Skip to content

Commit

Permalink
Add standard 1q Pauli equivalences to standard library (#10300)
Browse files Browse the repository at this point in the history
* Add standard 1q Pauli equivalences to standard library

This makes `transpile` a little more reliable in cases where people are
trying to use it to convert to a constrained basis.  We can't
necessarily recognise _all_ possible transformations into an incomplete
basis, but simple Pauli relations are things people may well expect.

* Fix test setup
  • Loading branch information
jakelishman authored Jun 16, 2023
1 parent 5f271bd commit 45a1d98
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
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

0 comments on commit 45a1d98

Please sign in to comment.