qiskit.circuit.QuantumCircuit.while_loop¶
- QuantumCircuit.while_loop(condition: tuple[ClassicalRegister | Clbit, int], body: None, qubits: None, clbits: None, *, label: str | None) qiskit.circuit.controlflow.while_loop.WhileLoopContext [ソース]¶
- QuantumCircuit.while_loop(condition: tuple[ClassicalRegister | Clbit, int], body: QuantumCircuit, qubits: Sequence[Union[Qubit, QuantumRegister, int, slice, Sequence[Union[Qubit, int]]]], clbits: Sequence[Union[Clbit, ClassicalRegister, int, slice, Sequence[Union[Clbit, int]]]], *, label: str | None) InstructionSet
Create a
while
loop on this circuit.There are two forms for calling this function. If called with all its arguments (with the possible exception of
label
), it will create aWhileLoopOp
with the givenbody
. Ifbody
(andqubits
andclbits
) are not passed, then this acts as a context manager, which will automatically build aWhileLoopOp
when the scope finishes. In this form, you do not need to keep track of the qubits or clbits you are using, because the scope will handle it for you.Example usage:
from qiskit.circuit import QuantumCircuit, Clbit, Qubit bits = [Qubit(), Qubit(), Clbit()] qc = QuantumCircuit(bits) with qc.while_loop((bits[2], 0)): qc.h(0) qc.cx(0, 1) qc.measure(0, 0)
- パラメータ
condition (Tuple[Union[ClassicalRegister, Clbit], int]) – An equality condition to be checked prior to executing
body
. The left-hand side of the condition must be aClassicalRegister
or aClbit
, and the right-hand side must be an integer or boolean.body (Optional[QuantumCircuit]) – The loop body to be repeatedly executed. Omit this to use the context-manager mode.
qubits (Optional[Sequence[Qubit]]) – The circuit qubits over which the loop body should be run. Omit this to use the context-manager mode.
clbits (Optional[Sequence[Clbit]]) – The circuit clbits over which the loop body should be run. Omit this to use the context-manager mode.
label (Optional[str]) – The string label of the instruction in the circuit.
- 戻り値
If used in context-manager mode, then this should be used as a
with
resource, which will infer the block content and operands on exit. If the full form is used, then this returns a handle to the instructions created.- 戻り値の型
InstructionSet or WhileLoopContext
- 例外
CircuitError – if an incorrect calling convention is used.