- QuantumCircuit.if_else(condition, true_body, false_body, qubits, clbits, label=None)[código fonte]¶
This method does not have an associated context-manager form, because it is already handled by the
if_test()method. You can use the
elsepart 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, 0)) as else_: qc.h(0) with else_: qc.x(0)
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 a
ClassicalRegisterto be tested for equality with a given
int, or as a tuple of a
Clbitto be compared to either a
true_body (QuantumCircuit) – The circuit body to be run if
false_body (QuantumCircuit) – The circuit to be run if
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.
CircuitError – If the provided condition references Clbits outside the enclosing circuit.
A handle to the instruction created.
- Tipo de retorno