Skip to content

Commit

Permalink
Promote CONTROL_FLOW_OP_NAMES to public API (#13057)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jakelishman authored Aug 29, 2024
1 parent cc2edc9 commit f37bd68
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
8 changes: 8 additions & 0 deletions qiskit/circuit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
1 change: 1 addition & 0 deletions qiskit/circuit/controlflow/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Original file line number Diff line number Diff line change
@@ -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.

0 comments on commit f37bd68

Please sign in to comment.