qiskit.circuit.QuantumCircuit.if_else¶
- QuantumCircuit.if_else(condition, true_body, false_body, qubits, clbits, label=None)[Quellcode]¶
Apply
IfElseOp
.Bemerkung
This method does not have an associated context-manager form, because it is already handled by the
if_test()
method. You can use theelse
part of that with something such as:from qiskit.circuit import QuantumCircuit, Qubit, Clbit bits = [Qubit(), Qubit(), Clbit()] qc = QuantumCircuit(bits) qc.h(0) qc.cx(0, 1) qc.measure(0, 0) with qc.if_test((bits[2], 0)) as else_: qc.h(0) with else_: qc.x(0)
- Parameter
condition (tuple[ClassicalRegister, int] | tuple[Clbit, int] | tuple[Clbit, bool]) – A condition to be evaluated at circuit runtime which, if true, will trigger the evaluation of
true_body
. Can be specified as either a tuple of aClassicalRegister
to be tested for equality with a givenint
, or as a tuple of aClbit
to be compared to either abool
or anint
.true_body (QuantumCircuit) – The circuit body to be run if
condition
is true.false_body (QuantumCircuit) – The circuit to be run if
condition
is false.qubits (Sequence[QubitSpecifier]) – The circuit qubits over which the if/else should be run.
clbits (Sequence[ClbitSpecifier]) – The circuit clbits over which the if/else should be run.
label (str | None) – The string label of the instruction in the circuit.
- Verursacht
CircuitError – If the provided condition references Clbits outside the enclosing circuit.
- Rückgabe
A handle to the instruction created.
- Rückgabetyp