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 support for cut CYGates and CHGates #290

Merged
merged 6 commits into from
Jun 27, 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
25 changes: 18 additions & 7 deletions circuit_knitting/cutting/qpd/qpd.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@
RYGate,
RZGate,
CXGate,
CYGate,
CZGate,
CHGate,
RXXGate,
RYYGate,
RZZGate,
Expand Down Expand Up @@ -191,15 +193,17 @@ def qpdbasis_from_gate(gate: Gate) -> QPDBasis:
"""
Generate a QPDBasis object, given a supported operation.

This method currently supports 8 operations:
This method currently supports 10 operations:
- :class:`~qiskit.circuit.library.RXXGate`
- :class:`~qiskit.circuit.library.RYYGate`
- :class:`~qiskit.circuit.library.RZZGate`
- :class:`~qiskit.circuit.library.CRXGate`
- :class:`~qiskit.circuit.library.CRYGate`
- :class:`~qiskit.circuit.library.CRZGate`
- :class:`~qiskit.circuit.library.CXGate`
- :class:`~qiskit.circuit.library.CYGate`
- :class:`~qiskit.circuit.library.CZGate`
- :class:`~qiskit.circuit.library.CHGate`

Returns:
The newly-instantiated :class:`QPDBasis` object
Expand Down Expand Up @@ -304,8 +308,8 @@ def _(gate: RXXGate | RYYGate | RZZGate | CRXGate | CRYGate | CRZGate):
return QPDBasis(maps, coeffs)


@_register_qpdbasis_from_gate("cz", "cx")
def _(gate: CZGate | CXGate):
@_register_qpdbasis_from_gate("cx", "cy", "cz", "ch")
def _(gate: CXGate | CYGate | CZGate | CHGate):
# Constructing a virtual two-qubit gate by sampling single-qubit operations - Mitarai et al
# https://iopscience.iop.org/article/10.1088/1367-2630/abd7bc/pdf
measurement_0 = [SdgGate(), QPDMeasure()]
Expand All @@ -323,12 +327,19 @@ def _(gate: CZGate | CXGate):
([ZGate()], measurement_1),
]

if gate.name == "cx":
# Modify `maps` to sandwich the target operations inside of Hadamards
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():
if operations:
operations.insert(0, HGate())
operations.append(HGate())
if gate.name in ("cx", "cy"):
operations.insert(0, HGate())
operations.append(HGate())
if gate.name == "cy":
operations.insert(0, SdgGate())
operations.append(SGate())
elif gate.name == "ch":
operations.insert(0, RYGate(-np.pi / 4))
operations.append(RYGate(np.pi / 4))

coeffs = [0.5, 0.5, 0.5, -0.5, 0.5, -0.5]

Expand Down
6 changes: 6 additions & 0 deletions releasenotes/notes/additional-gates-f4ed6c0e8dc3a9be.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
features:
- |
This release adds support for additional cut gates:
- :class:`~qiskit.circuit.library.CHGate`
- :class:`~qiskit.circuit.library.CYGate`
4 changes: 3 additions & 1 deletion test/cutting/qpd/test_qpd.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,4 +282,6 @@ def test_qpdbasis_from_gate_unique_maps(

def test_supported_gates(self):
gates = supported_gates()
self.assertEqual({"rxx", "ryy", "rzz", "crx", "cry", "crz", "cx", "cz"}, gates)
self.assertEqual(
{"rxx", "ryy", "rzz", "crx", "cry", "crz", "cx", "cy", "cz", "ch"}, gates
)
4 changes: 4 additions & 0 deletions test/cutting/test_cutting_roundtrip.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
RXXGate,
RYYGate,
RZZGate,
CHGate,
CXGate,
CYGate,
CZGate,
CRXGate,
CRYGate,
Expand Down Expand Up @@ -49,7 +51,9 @@ def append_random_unitary(circuit: QuantumCircuit, qubits):
@pytest.fixture(
params=[
[CXGate()],
[CYGate()],
[CZGate()],
[CHGate()],
[RYYGate(0.0)],
[RZZGate(np.pi)],
[RXXGate(np.pi / 3)],
Expand Down