# When I try to transpile circuit with Qiskit, how can I use $Ry(\pi/2)$ as a basis gate?

When I try to transpile circuit with Qiskit, I can use 'ry' as a basis gate. But I want to set one of the basis gate as $$R_y(\pi/2)$$. How can I do that?

Edited:

my_z2 = QuantumCircuit(1,name='z2')
my_z2.rz(np.pi,0)
z2_def = QuantumCircuit(1)
z2_def.append(my_z2.to_gate(),[0])

qc = QuantumCircuit(1)
qc.rz(np.pi,0)
qc_trans = transpile(qc, basis_gates=['id','z2'],translation_method='translator')
qc_trans.draw('mpl')


This is my code and it throws CircuitError: CircuitError: 'Cannot bind parameters (rz[0]) not present in the circuit.'

How can I fix this?

• You can define $R_y(\pi/2)$ as a custom gate, then follow the method described here: quantumcomputing.stackexchange.com/a/17861/9474 Dec 22 '21 at 8:37
• Thanks. But I cannot find the code corresponds to StandardEquivalenceLibrary.add_equivalence(CXGate(), mycx_def). StandardEquivalenceLibrary seems not exist.
– Inm
Dec 22 '21 at 8:49
• from qiskit.circuit.library.standard_gates.equivalence_library import StandardEquivalenceLibrary Dec 22 '21 at 9:14
• I follow the steps but it raise a circuit error.
– Inm
Dec 22 '21 at 10:25
• @Inm do you need to just transpile to a circuit with that basis, or then actually compile it to be executed on a machine? Jan 4 at 4:10