French
Languages
English
Bengali
French
German
Japanese
Korean
Portuguese
Spanish
Tamil

qiskit.circuit.QuantumCircuit.if_else

QuantumCircuit.if_else(condition, true_body, false_body, qubits, clbits, label=None)[source]

Apply IfElseOp.

Note

This method does not have an associated context-manager form, because it is already handled by the if_test() method. You can use the else 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)
Paramètres
  • 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 ClassicalRegister to be tested for equality with a given int, or as a tuple of a Clbit to be compared to either a bool or an int.

  • 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.

Lève

CircuitError – If the provided condition references Clbits outside the enclosing circuit.

Renvoie

A handle to the instruction created.

Type renvoyé

InstructionSet