The proper way to implement this would be writing your own transpiler pass, a TransformationPass to be more precise, which replaces the RYY and RZZ gates with your decomposition. If you want to decompose it into RXX gates the following should do the trick:
from qiskit.circuit import QuantumCircuit
from qiskit.converters import circuit_to_dag
from qiskit.transpiler import TransformationPass
class RXXTranslator(TransformationPass):
"""A transpiler pass to replace RYY and RZZ gates with RXX gates."""
def run(self, dag):
"""Run the pass."""
# iterate over all operations
for node in dag.op_nodes():
# if we hit a RYY or RZZ gate replace it
if node.op.name in ["ryy", "rzz"]:
# get the rotation angle
angle = node.op.params[0]
# calculate the replacement
replacement = QuantumCircuit(2)
if node.op.name == "ryy":
replacement.sdg([0, 1])
else:
replacement.h([0, 1])
replacement.rxx(angle, 0, 1)
if node.op.name == "ryy":
replacement.s([0, 1])
else:
replacement.h([0, 1])
# replace the node with our new decomposition
dag.substitute_node_with_dag(node, circuit_to_dag(replacement))
return dag
circuit = QuantumCircuit(2)
circuit.rxx(0.1, 0, 1)
circuit.ryy(0.2, 0, 1)
circuit.rzz(0.3, 0, 1)
as_rxx = RXXTranslator()(circuit)
print(as_rxx.draw())
which outputs
┌───────────┐┌─────┐┌───────────┐┌───┐┌───┐┌───────────┐┌───┐
q_0: ┤0 ├┤ Sdg ├┤0 ├┤ S ├┤ H ├┤0 ├┤ H ├
│ Rxx(0.1) │├─────┤│ Rxx(0.2) │├───┤├───┤│ Rxx(0.3) │├───┤
q_1: ┤1 ├┤ Sdg ├┤1 ├┤ S ├┤ H ├┤1 ├┤ H ├
└───────────┘└─────┘└───────────┘└───┘└───┘└───────────┘└───┘