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.