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 a supported_gates function #277

Merged
merged 8 commits into from
Jun 21, 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
1 change: 1 addition & 0 deletions circuit_knitting/cutting/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@

qpd.generate_qpd_samples
qpd.decompose_qpd_instructions
qpd.supported_gates

CutQC
=====
Expand Down
2 changes: 2 additions & 0 deletions circuit_knitting/cutting/qpd/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
decompose_qpd_instructions,
WeightType,
qpdbasis_from_gate,
supported_gates,
)
from .instructions import (
BaseQPDGate,
Expand All @@ -29,6 +30,7 @@
"qpdbasis_from_gate",
"generate_qpd_samples",
"decompose_qpd_instructions",
"supported_gates",
"QPDBasis",
"BaseQPDGate",
"TwoQubitQPDGate",
Expand Down
10 changes: 10 additions & 0 deletions circuit_knitting/cutting/qpd/qpd.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,16 @@ def qpdbasis_from_gate(gate: Gate) -> QPDBasis:
return f(gate)


def supported_gates() -> set[str]:
caleb-johnson marked this conversation as resolved.
Show resolved Hide resolved
"""
Return a set of gate names supported for automatic decomposition.

Returns:
Set of gate names supported for automatic decomposition.
"""
return set(_qpdbasis_from_gate_funcs)


@_register_qpdbasis_from_gate("rxx", "ryy", "rzz", "crx", "cry", "crz")
def _(gate: RXXGate | RYYGate | RZZGate | CRXGate | CRYGate | CRZGate):
# Constructing a virtual two-qubit gate by sampling single-qubit operations - Mitarai et al
Expand Down
4 changes: 4 additions & 0 deletions releasenotes/notes/supported-gates-d2156f58bc07fc7a.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
upgrade:
- |
Addition of :func:`~circuit_knitting.cutting.qpd.supported_gates` function, which returns the names of all gates which may be automatically decomposed using :func:`~circuit_knitting.cutting.qpd.qpdbasis_from_gate`.
4 changes: 4 additions & 0 deletions test/cutting/qpd/test_qpd.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,3 +279,7 @@ def test_qpdbasis_from_gate_unique_maps(
]
assert len(unique_by_eq(a for (a, b) in relevant_maps)) == q0_num_unique
assert len(unique_by_eq(b for (a, b) in relevant_maps)) == q1_num_unique

def test_supported_gates(self):
gates = supported_gates()
self.assertEqual({"rxx", "ryy", "rzz", "crx", "cry", "crz", "cx", "cz"}, gates)