Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add standard 1q Pauli equivalences to standard library #10300

Merged
merged 2 commits into from
Jun 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion qiskit/circuit/library/standard_gates/equivalence_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -1188,6 +1188,15 @@
def_x.append(inst, qargs, cargs)
_sel.add_equivalence(XGate(), def_x)

# XGate
# global phase: π/2
# ┌───┐ ┌───┐┌───┐
# q: ┤ X ├ ≡ q: ┤ Y ├┤ Z ├
# └───┘ └───┘└───┘
def_x = QuantumCircuit(1, global_phase=pi / 2)
def_x.y(0)
def_x.z(0)
_sel.add_equivalence(XGate(), def_x)

# CXGate

Expand Down Expand Up @@ -1407,6 +1416,16 @@
def_y.append(inst, qargs, cargs)
_sel.add_equivalence(YGate(), def_y)

# YGate
# global phase: π/2
# ┌───┐ ┌───┐┌───┐
# q: ┤ Y ├ ≡ q: ┤ Z ├┤ X ├
# └───┘ └───┘└───┘
def_y = QuantumCircuit(1, global_phase=pi / 2)
def_y.z(0)
def_y.x(0)
_sel.add_equivalence(YGate(), def_y)

# CYGate
#
# q_0: ──■── q_0: ─────────■───────
Expand All @@ -1433,7 +1452,6 @@
def_z.append(U1Gate(pi), [q[0]], [])
_sel.add_equivalence(ZGate(), def_z)

# """
# ZGate
#
# ┌───┐ ┌───┐┌───┐
Expand All @@ -1448,6 +1466,16 @@
def_z.append(inst, qargs, cargs)
_sel.add_equivalence(ZGate(), def_z)

# ZGate
# global phase: π/2
# ┌───┐ ┌───┐┌───┐
# q: ┤ Z ├ ≡ q: ┤ X ├┤ Y ├
# └───┘ └───┘└───┘
def_z = QuantumCircuit(1, global_phase=pi / 2)
def_z.x(0)
def_z.y(0)
_sel.add_equivalence(ZGate(), def_z)

# CZGate
#
# q_0: ─■─ q_0: ───────■───────
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
features:
- |
The transpiler's built-in :class:`.EquivalenceLibrary` has been taught the circular Pauli
relations :math:`X = iYZ`, :math:`Y = iZX` and :math:`Z = iXY`. This should make transpiling
to constrained, and potentially incomplete, basis sets more reliable.
See `#10293 <https://github.com/Qiskit/qiskit-terra/issues/10293>`__ for more detail.
14 changes: 14 additions & 0 deletions test/python/compiler/test_transpiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -1643,6 +1643,20 @@ def test_initial_layout_with_overlapping_qubits(self, opt_level):
transpiled.layout.initial_layout, Layout({0: qc.qubits[1], 1: qc.qubits[0]})
)

@combine(opt_level=[0, 1, 2, 3], basis=[["rz", "x"], ["rx", "z"], ["rz", "y"], ["ry", "x"]])
def test_paulis_to_constrained_1q_basis(self, opt_level, basis):
"""Test that Pauli-gate circuits can be transpiled to constrained 1q bases that do not
contain any root-Pauli gates."""
qc = QuantumCircuit(1)
qc.x(0)
qc.barrier()
qc.y(0)
qc.barrier()
qc.z(0)
transpiled = transpile(qc, basis_gates=basis, optimization_level=opt_level)
self.assertGreaterEqual(set(basis) | {"barrier"}, transpiled.count_ops().keys())
self.assertEqual(Operator(qc), Operator(transpiled))


@ddt
class TestPostTranspileIntegration(QiskitTestCase):
Expand Down