Skip to content

Commit f37bd68

Browse files
authored
Promote CONTROL_FLOW_OP_NAMES to public API (#13057)
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.
1 parent cc2edc9 commit f37bd68

3 files changed

Lines changed: 14 additions & 0 deletions

File tree

qiskit/circuit/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -686,6 +686,13 @@
686686
687687
ControlFlowOp
688688
689+
For convenience, there is a :class:`frozenset` instance containing the :attr:`.Instruction.name`
690+
attributes of each of the control-flow operations.
691+
692+
.. data:: CONTROL_FLOW_OP_NAMES
693+
694+
Set of the instruction names of Qiskit's known control-flow operations.
695+
689696
These control-flow operations (:class:`IfElseOp`, :class:`WhileLoopOp`,
690697
:class:`SwitchCaseOp` and :class:`ForLoopOp`) all have specific state that defines the branching
691698
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):
12571264
CASE_DEFAULT,
12581265
BreakLoopOp,
12591266
ContinueLoopOp,
1267+
CONTROL_FLOW_OP_NAMES,
12601268
)
12611269

12621270
from .annotated_operation import AnnotatedOperation, InverseModifier, ControlModifier, PowerModifier

qiskit/circuit/controlflow/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,4 @@
2525

2626

2727
CONTROL_FLOW_OP_NAMES = frozenset(("for_loop", "while_loop", "if_else", "switch_case"))
28+
"""Set of the instruction names of Qiskit's known control-flow operations."""
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
features_circuits:
3+
- |
4+
A new data attribute, :data:`qiskit.circuit.CONTROL_FLOW_OP_NAMES`, is available to easily find
5+
and check whether a given :class:`~.circuit.Instruction` is a control-flow operation by name.

0 commit comments

Comments
 (0)