From 6ff471a42c3b6baf1a7d32cfa986d189aace257f Mon Sep 17 00:00:00 2001 From: Caleb Johnson Date: Wed, 21 Jun 2023 15:21:21 -0500 Subject: [PATCH] Add a supported_gates function (#277) * 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 * Add new function to package and sphinx docs --------- Co-authored-by: Jim Garrison --- circuit_knitting/cutting/__init__.py | 1 + circuit_knitting/cutting/qpd/__init__.py | 2 ++ circuit_knitting/cutting/qpd/qpd.py | 10 ++++++++++ .../notes/supported-gates-d2156f58bc07fc7a.yaml | 4 ++++ test/cutting/qpd/test_qpd.py | 4 ++++ 5 files changed, 21 insertions(+) create mode 100644 releasenotes/notes/supported-gates-d2156f58bc07fc7a.yaml diff --git a/circuit_knitting/cutting/__init__.py b/circuit_knitting/cutting/__init__.py index 1e75ce5f2..14ebc6d7a 100644 --- a/circuit_knitting/cutting/__init__.py +++ b/circuit_knitting/cutting/__init__.py @@ -57,6 +57,7 @@ qpd.generate_qpd_samples qpd.decompose_qpd_instructions + qpd.supported_gates CutQC ===== diff --git a/circuit_knitting/cutting/qpd/__init__.py b/circuit_knitting/cutting/qpd/__init__.py index 8e0f36960..646abc03a 100644 --- a/circuit_knitting/cutting/qpd/__init__.py +++ b/circuit_knitting/cutting/qpd/__init__.py @@ -17,6 +17,7 @@ decompose_qpd_instructions, WeightType, qpdbasis_from_gate, + supported_gates, ) from .instructions import ( BaseQPDGate, @@ -29,6 +30,7 @@ "qpdbasis_from_gate", "generate_qpd_samples", "decompose_qpd_instructions", + "supported_gates", "QPDBasis", "BaseQPDGate", "TwoQubitQPDGate", diff --git a/circuit_knitting/cutting/qpd/qpd.py b/circuit_knitting/cutting/qpd/qpd.py index d66040937..995f5d781 100644 --- a/circuit_knitting/cutting/qpd/qpd.py +++ b/circuit_knitting/cutting/qpd/qpd.py @@ -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 diff --git a/releasenotes/notes/supported-gates-d2156f58bc07fc7a.yaml b/releasenotes/notes/supported-gates-d2156f58bc07fc7a.yaml new file mode 100644 index 000000000..dcb6ba4d5 --- /dev/null +++ b/releasenotes/notes/supported-gates-d2156f58bc07fc7a.yaml @@ -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`. diff --git a/test/cutting/qpd/test_qpd.py b/test/cutting/qpd/test_qpd.py index 12b77d98b..56f4fc555 100644 --- a/test/cutting/qpd/test_qpd.py +++ b/test/cutting/qpd/test_qpd.py @@ -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)