- QuantumCircuit.while_loop(condition: Tuple[Union[ClassicalRegister, Clbit], int], body: None, qubits: None, clbits: None, *, label: Optional[str]) qiskit.circuit.controlflow.while_loop.WhileLoopContext ¶
- QuantumCircuit.while_loop(condition: Tuple[Union[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: Optional[str]) InstructionSet
whileloop 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 a
WhileLoopOpwith the given
clbits) are not passed, then this acts as a context manager, which will automatically build a
WhileLoopOpwhen 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.
from qiskit.circuit import QuantumCircuit, Clbit, Qubit bits = [Qubit(), Qubit(), Clbit()] qc = QuantumCircuit(bits) with qc.while_loop((bits, 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 a
Clbit, 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
withresource, 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.