1

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?

glS
  • 24,708
  • 5
  • 34
  • 108
Inm
  • 505
  • 3
  • 8
  • 1
    You can define $R_y(\pi/2)$ as a custom gate, then follow the method described here: https://quantumcomputing.stackexchange.com/a/17861/9474 – Egretta.Thula Dec 22 '21 at 08: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 08:49
  • from qiskit.circuit.library.standard_gates.equivalence_library import StandardEquivalenceLibrary – Egretta.Thula Dec 22 '21 at 09: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? – 3yakuya Jan 04 '22 at 04:10

0 Answers0