Skip to content

Commit

Permalink
Add support for cut ECRGate (#292)
Browse files Browse the repository at this point in the history
* Add support for cut `ECRGate`

* Let's stop counting the supported operations.

* Add tests for optimal overhead

* Update test/cutting/qpd/test_qpd.py

black fix

* black

* Update release note

---------

Co-authored-by: Caleb Johnson <[email protected]>
  • Loading branch information
garrison and caleb-johnson committed Jul 5, 2023
1 parent cf0017a commit d907150
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 3 deletions.
22 changes: 20 additions & 2 deletions circuit_knitting/cutting/qpd/qpd.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
SGate,
TGate,
SdgGate,
SXGate,
RXGate,
RYGate,
RZGate,
Expand All @@ -47,6 +48,7 @@
CRXGate,
CRYGate,
CRZGate,
ECRGate,
CSXGate,
)

Expand Down Expand Up @@ -195,7 +197,7 @@ def qpdbasis_from_gate(gate: Gate) -> QPDBasis:
"""
Generate a QPDBasis object, given a supported operation.
This method currently supports 10 operations:
This method currently supports the following operations:
- :class:`~qiskit.circuit.library.RXXGate`
- :class:`~qiskit.circuit.library.RYYGate`
- :class:`~qiskit.circuit.library.RZZGate`
Expand All @@ -207,6 +209,9 @@ def qpdbasis_from_gate(gate: Gate) -> QPDBasis:
- :class:`~qiskit.circuit.library.CZGate`
- :class:`~qiskit.circuit.library.CHGate`
The above gate names can also be determined by calling
:func:`supported_gates`.
Returns:
The newly-instantiated :class:`QPDBasis` object
Expand Down Expand Up @@ -339,7 +344,7 @@ def _(gate: CXGate | CYGate | CZGate | CHGate):

if gate.name != "cz":
# Modify `maps` to sandwich the target operations inside of basis rotations
for operations in {id(m[1]): m[1] for m in maps}.values():
for operations in unique_by_id(m[1] for m in maps):
if operations:
if gate.name in ("cx", "cy"):
operations.insert(0, HGate())
Expand All @@ -356,6 +361,19 @@ def _(gate: CXGate | CYGate | CZGate | CHGate):
return QPDBasis(maps, coeffs)


@_register_qpdbasis_from_gate("ecr")
def _(gate: ECRGate):
retval = qpdbasis_from_gate(CXGate())
# Modify basis according to ECRGate definition in Qiskit circuit library
# https://github.com/Qiskit/qiskit-terra/blob/d9763523d45a747fd882a7e79cc44c02b5058916/qiskit/circuit/library/standard_gates/equivalence_library.py#L656-L663
for operations in unique_by_id(m[0] for m in retval.maps):
operations.insert(0, SGate())
operations.append(XGate())
for operations in unique_by_id(m[1] for m in retval.maps):
operations.insert(0, SXGate())
return retval


def _validate_qpd_instructions(
circuit: QuantumCircuit, instruction_ids: Sequence[Sequence[int]]
):
Expand Down
2 changes: 2 additions & 0 deletions releasenotes/notes/additional-gates-f4ed6c0e8dc3a9be.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ features:
This release adds support for additional cut gates:
- :class:`~qiskit.circuit.library.CHGate`
- :class:`~qiskit.circuit.library.CYGate`
- :class:`~qiskit.circuit.library.SXGate`
- :class:`~qiskit.circuit.library.ECRGate`
18 changes: 17 additions & 1 deletion test/cutting/qpd/test_qpd.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,10 @@ def test_decompose_qpd_instructions(self):
# Optimal values from https://arxiv.org/abs/2205.00016v2 Corollary 4.4 (page 10)
@data(
(CXGate(), 3),
(CYGate(), 3),
(CZGate(), 3),
(CHGate(), 3),
(ECRGate(), 3),
(CRXGate(np.pi / 7), 1 + 2 * np.abs(np.sin(np.pi / 14))),
(CRYGate(np.pi / 7), 1 + 2 * np.abs(np.sin(np.pi / 14))),
(CRZGate(np.pi / 7), 1 + 2 * np.abs(np.sin(np.pi / 14))),
Expand Down Expand Up @@ -283,6 +286,19 @@ def test_qpdbasis_from_gate_unique_maps(
def test_supported_gates(self):
gates = supported_gates()
self.assertEqual(
{"rxx", "ryy", "rzz", "crx", "cry", "crz", "cx", "cy", "cz", "ch", "csx"},
{
"rxx",
"ryy",
"rzz",
"crx",
"cry",
"crz",
"cx",
"cy",
"cz",
"ch",
"csx",
"ecr",
},
gates,
)
2 changes: 2 additions & 0 deletions test/cutting/test_cutting_roundtrip.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
CRXGate,
CRYGate,
CRZGate,
ECRGate,
CSXGate,
)
from qiskit.extensions import UnitaryGate
Expand Down Expand Up @@ -55,6 +56,7 @@ def append_random_unitary(circuit: QuantumCircuit, qubits):
[CYGate()],
[CZGate()],
[CHGate()],
[ECRGate()],
[CSXGate()],
[RYYGate(0.0)],
[RZZGate(np.pi)],
Expand Down

0 comments on commit d907150

Please sign in to comment.