Skip to content

Commit

Permalink
Add a supported_gates function (#277)
Browse files Browse the repository at this point in the history
* Add a supported_gates function

* use sets instead of tuples

* Fix docstring

* Add release note

* Fix test

* Update circuit_knitting/cutting/qpd/qpd.py

Co-authored-by: Jim Garrison <[email protected]>

* Add new function to package and sphinx docs

---------

Co-authored-by: Jim Garrison <[email protected]>
  • Loading branch information
caleb-johnson and garrison committed Jun 21, 2023
1 parent f6e3012 commit 6ff471a
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions circuit_knitting/cutting/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,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]:
"""
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)

0 comments on commit 6ff471a

Please sign in to comment.