# IfElseOp¶

class IfElseOp(condition, true_body, false_body=None, label=None)[source]

Bases: qiskit.circuit.controlflow.control_flow.ControlFlowOp

A circuit operation which executes a program (true_body) if a provided condition (condition) evaluates to true, and optionally evaluates another program (false_body) otherwise.

Parameters
• condition (Tuple[Union[ClassicalRegister, Clbit], int]) – 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) – A program to be executed if condition evaluates to true.

• false_body (Optional[QuantumCircuit]) – A optional program to be executed if condition evaluates to false.

• label (Optional[str]) – An optional label for identifying the instruction.

If provided, false_body must be of the same num_qubits and num_clbits as true_body.

The classical bits used in condition must be a subset of those attached to the circuit on which this IfElseOp will be appended.

Circuit symbol:

     ┌───────────┐
q_0: ┤0          ├
│           │
q_1: ┤1          ├
│  if_else  │
q_2: ┤2          ├
│           │
c_0: ╡0          ╞
└───────────┘


Create a new instruction.

Parameters
• name (str) – instruction name

• num_qubits (int) – instruction’s qubit width

• num_clbits (int) – instruction’s clbit width

• params (list[int|float|complex|str|ndarray|list|ParameterExpression]) – list of parameters

• duration (int or float) – instruction’s duration. it must be integer if unit is ‘dt’

• unit (str) – time unit of duration

• label (str or None) – An optional label for identifying the instruction.

Raises

CircuitError – when the register is not in the correct format.

Methods

 add_decomposition Add a decomposition of the instruction to the SessionEquivalenceLibrary. assemble Assemble a QasmQobjInstruction broadcast_arguments Validation of the arguments. c_if Set a classical equality condition on this instruction between the register or cbit classical and value val. copy Copy of the instruction. inverse Invert this instruction. is_parameterized Return True .IFF. mirror DEPRECATED: use instruction.reverse_ops(). qasm Return a default OpenQASM string for the instruction. repeat Creates an instruction with gate repeated n amount of times. reverse_ops For a composite instruction, reverse the order of sub-instructions. soft_compare Soft comparison between gates. validate_parameter Instruction parameters has no validation or normalization.

Attributes

blocks
condition_bits

Get Clbits in condition.

Return type

List[Clbit]

decompositions

Get the decompositions of the instruction from the SessionEquivalenceLibrary.

definition

Return definition in terms of other basic gates.

duration

Get the duration.

label

Return instruction label

Return type

str

params
unit

Get the time unit of duration.