Skip to content
22 changes: 22 additions & 0 deletions qiskit/circuit/library/standard_gates/equivalence_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
ECRGate,
ZGate,
CZGate,
IGate,
CCZGate,
XXPlusYYGate,
XXMinusYYGate,
Expand Down Expand Up @@ -170,6 +171,27 @@
def_r.append(U3Gate(theta, phi - pi / 2, -phi + pi / 2), [q[0]])
_sel.add_equivalence(RGate(theta, phi), def_r)

# IGate
q = QuantumRegister(1, "q")
def_id = QuantumCircuit(q)
def_id.append(UGate(0, 0, 0), [q[0]])
_sel.add_equivalence(IGate(), def_id)

q = QuantumRegister(1, "q")
def_id_rx = QuantumCircuit(q)
def_id_rx.append(RXGate(0), [q[0]])
_sel.add_equivalence(IGate(), def_id_rx)

q = QuantumRegister(1, "q")
def_id_ry = QuantumCircuit(q)
def_id_ry.append(RYGate(0), [q[0]])
_sel.add_equivalence(IGate(), def_id_ry)

q = QuantumRegister(1, "q")
def_id_rz = QuantumCircuit(q)
def_id_rz.append(RZGate(0), [q[0]])
_sel.add_equivalence(IGate(), def_id_rz)
Comment thread
kdk marked this conversation as resolved.

# RCCXGate
#
# ┌───────┐
Expand Down
13 changes: 5 additions & 8 deletions test/python/transpiler/test_basis_translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -928,22 +928,19 @@ def test_cx_bell_to_ecr(self):
in_dag = circuit_to_dag(bell)
out_dag = BasisTranslator(std_eqlib, ["ecr", "u"]).run(in_dag)

# ┌────────────┐ ┌─────────────┐┌──────┐┌──────────┐
# q_0: ───┤ U(π/2,0,π) ├───┤ U(0,0,-π/2) ├┤0 ├┤ U(π,0,π) ├
# ┌──┴────────────┴──┐└─────────────┘│ Ecr │└──────────┘
# q_1: ┤ U(-π/2,-π/2,π/2) ├───────────────┤1 ├────────────
# └──────────────────┘ └──────┘

qr = QuantumRegister(2, "q")
expected = QuantumCircuit(2)
expected.u(pi / 2, 0, pi, qr[0])
expected.u(0, 0, -pi / 2, qr[0])
expected.u(-pi / 2, -pi / 2, pi / 2, qr[1])
expected.u(pi, 0, 0, qr[0])
expected.u(pi / 2, -pi / 2, pi / 2, qr[1])
expected.ecr(0, 1)
expected.u(pi, 0, pi, qr[0])
expected_dag = circuit_to_dag(expected)
Comment on lines 932 to 938
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My question from the prior review! It got lost before - I must have forgotten to save the comment.

Do we know why this changes? We haven't added any rules that go to IGate, so I'd not have expected the basis-translation path to change.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TBH, I'm not sure. I didn't really think to check. I just saw the output circuit was equivalent and updated the test. I'll do some debugging locally because the qpy tests are failing in a weird way now too so this is blocked on that anyway.


self.assertEqual(out_dag, expected_dag)
self.assertEqual(
Operator.from_circuit(bell), Operator.from_circuit(dag_to_circuit(out_dag))
)

def test_cx_bell_to_cp(self):
"""Verify we can translate a CX bell to CP,U."""
Expand Down