mqt.core.ir.operations¶
Module Contents¶
- class OpType¶
Bases:
enum.EnumEnumeration of operation types.
- none = 0¶
A placeholder operation.
It is used to represent an operation that is not yet defined.
- gphase = 4¶
A global phase operation.
- i = 10¶
An identity operation.
See also
- h = 16¶
A Hadamard gate.
See also
- x = 20¶
An X gate.
See also
- y = 24¶
A Y gate.
See also
- z = 30¶
A Z gate.
See also
- s = 34¶
An S gate.
See also
- sdg = 35¶
An \(S^\dagger\) gate.
See also
- t = 38¶
A T gate.
See also
- tdg = 39¶
A \(T^\dagger\) gate.
See also
- v = 40¶
A V gate.
See also
- vdg = 41¶
A \(V^\dagger\) gate.
See also
- u = 44¶
A U gate.
See also
- u2 = 48¶
A U2 gate.
See also
- p = 54¶
A phase gate.
See also
- sx = 56¶
A \(\sqrt{X}\) gate.
See also
- sxdg = 57¶
A \(\sqrt{X}^\dagger\) gate.
- rx = 60¶
A \(R_x\) gate.
See also
- ry = 64¶
A \(R_y\) gate.
See also
- rz = 70¶
A \(R_z\) gate.
See also
- r = 164¶
An \(R\) gate.
See also
- swap = 72¶
A SWAP gate.
- iswap = 76¶
A iSWAP gate.
- iswapdg = 77¶
A \(i\text{SWAP}^\dagger\) gate.
- peres = 80¶
A Peres gate.
- peresdg = 81¶
A \(\text{Peres}^\dagger\) gate.
- dcx = 84¶
A DCX gate.
See also
- ecr = 88¶
An ECR gate.
See also
- rxx = 92¶
A \(R_{xx}\) gate.
See also
- ryy = 96¶
A \(R_{yy}\) gate.
See also
- rzz = 102¶
A \(R_{zz}\) gate.
See also
- rzx = 104¶
A \(R_{zx}\) gate.
See also
- xx_minus_yy = 108¶
A \(R_{XX - YY}\) gate.
- xx_plus_yy = 112¶
A \(R_{XX + YY}\) gate.
- compound = 116¶
A compound operation.
It is used to group multiple operations into a single operation.
See also
CompoundOperation
- measure = 120¶
A measurement operation.
- reset = 124¶
A reset operation.
- barrier = 14¶
A barrier operation.
It is used to separate operations in the circuit.
- if_else = 128¶
An if-else operation.
It is used to control the execution of an operation based on the value of a classical register.
- class Control(qubit: int, type_: Control = ...)¶
A control is a pair of a qubit and a type. The type can be either positive or negative.
- Parameters:
qubit – The qubit that is the control.
type – The type of the control.
- class Operation¶
-
- property targets: list[int]¶
The targets of the operation.
Note
The notion of a target might not make sense for all types of operations.
- property controls: set[Control]¶
The controls of the operation.
Note
The notion of a control might not make sense for all types of operations.
- add_control(control: Control) None¶
Add a control to the operation.
- Parameters:
control – The control to add.
- add_controls(controls: Set[Control]) None¶
Add multiple controls to the operation.
- Parameters:
controls – The controls to add.
- remove_control(control: Control) None¶
Remove a control from the operation.
- Parameters:
control – The control to remove.
- remove_controls(controls: Set[Control]) None¶
Remove multiple controls from the operation.
- Parameters:
controls – The controls to remove.
- get_used_qubits() set[int]¶
Get the qubits that are used by the operation.
- Returns:
The set of qubits that are used by the operation.
- acts_on(qubit: int) bool¶
Check if the operation acts on a specific qubit.
- Parameters:
qubit – The qubit to check.
- Returns:
True if the operation acts on the qubit, False otherwise.
- property parameter: list[float]¶
The parameters of the operation.
Note
The notion of a parameter might not make sense for all types of operations.
- is_unitary() bool¶
Check if the operation is unitary.
- Returns:
True if the operation is unitary, False otherwise.
- is_standard_operation() bool¶
Check if the operation is a
StandardOperation.- Returns:
True if the operation is a
StandardOperation, False otherwise.
- is_compound_operation() bool¶
Check if the operation is a
CompoundOperation.- Returns:
True if the operation is a
CompoundOperation, False otherwise.
- is_non_unitary_operation() bool¶
Check if the operation is a
NonUnitaryOperation.- Returns:
True if the operation is a
NonUnitaryOperation, False otherwise.
- is_if_else_operation() bool¶
Check if the operation is a
IfElseOperation.- Returns:
True if the operation is a
IfElseOperation, False otherwise.
- is_symbolic_operation() bool¶
Check if the operation is a
SymbolicOperation.- Returns:
True if the operation is a
SymbolicOperation, False otherwise.
- class StandardOperation¶
- class StandardOperation(target: int, op_type: OpType, params: Sequence[float] = ...)
- class StandardOperation(targets: Sequence[int], op_type: OpType, params: Sequence[float] = ...)
- class StandardOperation(control: Control, target: int, op_type: OpType, params: Sequence[float] = ...)
- class StandardOperation(control: Control, targets: Sequence[int], op_type: OpType, params: Sequence[float] = ...)
- class StandardOperation(controls: Set[Control], target: int, op_type: OpType, params: Sequence[float] = ...)
- class StandardOperation(controls: Set[Control], targets: Sequence[int], op_type: OpType, params: Sequence[float] = ...)
- class StandardOperation(controls: Set[Control], target0: int, target1: int, op_type: OpType, params: Sequence[float] = ...)
Bases:
OperationStandard quantum operation.
This class is used to represent all standard quantum operations, i.e., operations that are unitary. This includes all possible quantum gates. Such Operations are defined by their
OpType, the qubits (controls and targets) they act on, and their parameters.- Parameters:
control – The control qubit(s) of the operation (if any).
target – The target qubit(s) of the operation.
op_type – The type of the operation.
params – The parameters of the operation (if any).
- class CompoundOperation¶
- class CompoundOperation(ops: Sequence[Operation])
Bases:
Operation,collections.abc.MutableSequence[Operation]Compound quantum operation.
This class is used to aggregate and group multiple operations into a single object. This is useful for optimizations and for representing complex quantum functionality. A
CompoundOperationcan contain any number of operations, including otherCompoundOperation’s.- Parameters:
ops – The operations that are part of the compound operation.
- __getitem__(index: int) Operation¶
- __getitem__(index: slice) list[Operation]
Get the operations in the given slice.
Note
This gives direct access to the operations in the compound operation.
- Parameters:
index – The slice of the operations to get.
- Returns:
The operations in the given slice.
- __setitem__(index: int, value: Operation) None¶
- __setitem__(index: slice, value: Iterable[Operation]) None
Set the operations in the given slice.
- Parameters:
index – The slice of operations to set.
value – The operations to set in the given slice.
- __delitem__(index: int) None¶
- __delitem__(index: slice) None
Delete the operations in the given slice.
- Parameters:
index – The slice of operations to delete.
- class NonUnitaryOperation(targets: Sequence[int], classics: Sequence[int])¶
- class NonUnitaryOperation(target: int, classic: int)
- class NonUnitaryOperation(targets: Sequence[int], op_type: OpType = ...)
Bases:
OperationNon-unitary operation.
This class is used to represent all non-unitary operations, i.e., operations that are not reversible. This includes measurements and resets.
- Parameters:
targets – The target qubit(s) of the operation.
classics – The classical bit(s) that are associated with the operation (only relevant for measurements).
op_type – The type of the operation.
- class SymbolicOperation¶
- class SymbolicOperation(target: int, op_type: OpType, params: Sequence[Expression | float] = ...)
- class SymbolicOperation(targets: Sequence[int], op_type: OpType, params: Sequence[Expression | float] = ...)
- class SymbolicOperation(control: Control, target: int, op_type: OpType, params: Sequence[Expression | float] = ...)
- class SymbolicOperation(control: Control, targets: Sequence[int], op_type: OpType, params: Sequence[Expression | float] = ...)
- class SymbolicOperation(controls: Set[Control], target: int, op_type: OpType, params: Sequence[Expression | float] = ...)
- class SymbolicOperation(controls: Set[Control], targets: Sequence[int], op_type: OpType, params: Sequence[Expression | float] = ...)
- class SymbolicOperation(controls: Set[Control], target0: int, target1: int, op_type: OpType, params: Sequence[Expression | float] = ...)
Bases:
StandardOperationSymbolic quantum operation.
This class is used to represent quantum operations that are not yet fully defined. This can be useful for representing operations that depend on parameters that are not yet known. A
SymbolicOperationis defined by itsOpType, the qubits (controls and targets) it acts on, and its parameters. The parameters can be either fixed values or symbolic expressions.- Parameters:
controls – The control qubit(s) of the operation (if any).
targets – The target qubit(s) of the operation.
op_type – The type of the operation.
params – The parameters of the operation (if any).
- get_parameter(index: int) Expression | float¶
Get the parameter at the given index.
- Parameters:
index – The index of the parameter to get.
- Returns:
The parameter at the given index.
- get_parameters() list[Expression | float]¶
Get all parameters of the operation.
- Returns:
The parameters of the operation.
- get_instantiated_operation(assignment: Mapping[Variable, float]) StandardOperation¶
Get the instantiated operation.
- Parameters:
assignment – The assignment of the symbolic parameters.
- Returns:
The instantiated operation.
- class ComparisonKind¶
Bases:
enum.EnumEnumeration of comparison types for classic-controlled operations.
- eq = 0¶
Equality comparison.
- neq = 1¶
Inequality comparison.
- lt = 2¶
Less-than comparison.
- leq = 3¶
Less-than-or-equal comparison.
- gt = 4¶
Greater-than comparison.
- geq = 5¶
Greater-than-or-equal comparison.
- class IfElseOperation(then_operation: Operation, else_operation: Operation | None, control_register: ClassicalRegister, expected_value: int = 1, comparison_kind: ComparisonKind = ...)¶
- class IfElseOperation(then_operation: Operation, else_operation: Operation | None, control_bit: int, expected_value: bool = True, comparison_kind: ComparisonKind = ...)
Bases:
OperationIf-else quantum operation.
This class is used to represent an if-else operation. The then operation is executed if the value of the classical register matches the expected value. Otherwise, the else operation is executed.
- Parameters:
then_operation – The operation that is executed if the condition is met.
else_operation – The operation that is executed if the condition is not met.
control_register – The classical register that controls the operation.
expected_value – The expected value of the classical register.
comparison_kind – The kind of comparison (default is equality).
- property else_operation: Operation | None¶
The operation that is executed if the condition is not met.
- property control_register: ClassicalRegister | None¶
The classical register that controls the operation.
- property expected_value_register: int¶
The expected value of the classical register.
The then-operation is executed if the value of the classical register matches the expected value based on the kind of comparison. The expected value is an integer that is interpreted as a binary number, where the least significant bit is at the start index of the classical register.
- property expected_value_bit: bool¶
The expected value of the classical bit.
The then-operation is executed if the value of the classical bit matches the expected value based on the kind of comparison.
- property comparison_kind: ComparisonKind¶
The kind of comparison.
The then-operation is executed if the value of the control matches the expected value based on the kind of comparison.