From ef52a16536f10280411efcb1aaf58072cd1f34c6 Mon Sep 17 00:00:00 2001 From: Jake Lishman Date: Thu, 29 Aug 2024 23:33:05 +0100 Subject: [PATCH] Promote `CONTROL_FLOW_OP_NAMES` to public API This is generally useful for Qiskit's built-in transpiler passes, and we've had some interest in using it for the same reasons from outside the library. While the control-flow structure from within Rust might change in the future, in the immediate term and from Python space, it feels fair to expose this as public API, since all the information contained in it is certainly already public. --- qiskit/circuit/__init__.py | 8 ++++++++ qiskit/circuit/controlflow/__init__.py | 1 + .../notes/control-flow-op-names-c66f38f8a0e15ce7.yaml | 5 +++++ 3 files changed, 14 insertions(+) create mode 100644 releasenotes/notes/control-flow-op-names-c66f38f8a0e15ce7.yaml diff --git a/qiskit/circuit/__init__.py b/qiskit/circuit/__init__.py index 1ab084ef2072..ebaef39c2a43 100644 --- a/qiskit/circuit/__init__.py +++ b/qiskit/circuit/__init__.py @@ -686,6 +686,13 @@ ControlFlowOp +For convenience, there is a :class:`frozenset` instance containing the :attr:`.Instruction.name` +attributes of each of the control-flow operations. + +.. data:: CONTROL_FLOW_OP_NAMES + + Set of the instruction names of Qiskit's known control-flow operations. + These control-flow operations (:class:`IfElseOp`, :class:`WhileLoopOp`, :class:`SwitchCaseOp` and :class:`ForLoopOp`) all have specific state that defines the branching conditions and strategies, but contain all the different subcircuit blocks that might be entered in @@ -1257,6 +1264,7 @@ def __array__(self, dtype=None, copy=None): CASE_DEFAULT, BreakLoopOp, ContinueLoopOp, + CONTROL_FLOW_OP_NAMES, ) from .annotated_operation import AnnotatedOperation, InverseModifier, ControlModifier, PowerModifier diff --git a/qiskit/circuit/controlflow/__init__.py b/qiskit/circuit/controlflow/__init__.py index 12831ccaaaed..2679b45d7782 100644 --- a/qiskit/circuit/controlflow/__init__.py +++ b/qiskit/circuit/controlflow/__init__.py @@ -25,3 +25,4 @@ CONTROL_FLOW_OP_NAMES = frozenset(("for_loop", "while_loop", "if_else", "switch_case")) +"""Set of the instruction names of Qiskit's known control-flow operations.""" diff --git a/releasenotes/notes/control-flow-op-names-c66f38f8a0e15ce7.yaml b/releasenotes/notes/control-flow-op-names-c66f38f8a0e15ce7.yaml new file mode 100644 index 000000000000..94a3b11b935b --- /dev/null +++ b/releasenotes/notes/control-flow-op-names-c66f38f8a0e15ce7.yaml @@ -0,0 +1,5 @@ +--- +features_circuits: + - | + A new data attribute, :data:`qiskit.circuit.CONTROL_FLOW_OP_NAMES`, is available to easily find + and check whether a given :class:`~.circuit.Instruction` is a control-flow operation by name.