1
$\begingroup$

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])
StandardEquivalenceLibrary.add_equivalence(RZGate(np.pi), z2_def)

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?

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.