mqt.core.ir¶
MQT Core IR - The MQT Core Intermediate Representation (IR) module.
Submodules¶
Package Contents¶
- class Permutation¶
- class Permutation(permutation: dict[int, int])
Bases:
collections.abc.MutableMapping[int,int]A class to represent a permutation of the qubits in a quantum circuit.
- Parameters:
permutation – The permutation to initialize the object with.
- apply(controls: Set[Control]) set[Control]¶
- apply(targets: Sequence[int]) list[int]
Apply the permutation to a list of targets.
- Parameters:
targets – The list of targets to apply the permutation to.
- Returns:
The list of targets with the permutation applied.
- __getitem__(index: int) int¶
Get the value of the permutation at the given index.
- Parameters:
index – The index to get the value of the permutation at.
- Returns:
The value of the permutation at the given index.
- __setitem__(index: int, value: int) None¶
Set the value of the permutation at the given index.
- Parameters:
index – The index to set the value of the permutation at.
value – The value to set the permutation at the given index to.
- class QuantumComputation(nq: int = 0, nc: int = 0, seed: int = 0)¶
Bases:
collections.abc.MutableSequence[operations.Operation]The main class for representing quantum computations within the MQT.
Acts as mutable sequence of
Operationobjects, which represent the individual operations in the quantum computation.- Parameters:
nq – The number of qubits in the quantum computation.
nc – The number of classical bits in the quantum computation.
seed – The seed to use for the internal random number generator.
- static from_qasm_str(qasm: str) QuantumComputation¶
Create a QuantumComputation object from an OpenQASM string.
- Parameters:
qasm – The OpenQASM string to create the QuantumComputation object from.
- Returns:
The QuantumComputation object created from the OpenQASM string.
- static from_qasm(filename: str) QuantumComputation¶
Create a QuantumComputation object from an OpenQASM file.
- Parameters:
filename – The filename of the OpenQASM file to create the QuantumComputation object from.
- Returns:
The QuantumComputation object created from the OpenQASM file.
- property num_ancilla_qubits: int¶
The number of ancilla qubits in the quantum computation.
Note
Ancilla qubits are qubits that always start in a fixed state (usually \(|0\\rangle\)).
- property num_garbage_qubits: int¶
The number of garbage qubits in the quantum computation.
Note
Garbage qubits are qubits whose final state is not relevant for the computation.
- property num_measured_qubits: int¶
The number of qubits that are measured in the quantum computation.
Computed as \(| \text{qubits} | - | \text{garbage} |\).
- property num_data_qubits: int¶
The number of data qubits in the quantum computation.
Computed as \(| \text{qubits} | - | \text{ancilla} |\).
- num_single_qubit_ops() int¶
Return the number of single-qubit operations in the quantum computation.
- num_total_ops() int¶
Return the total number of operations in the quantum computation.
Recursively counts sub-operations (e.g., from
CompoundOperationobjects).
- invert() None¶
Invert the quantum computation in-place by inverting each operation and reversing the order of operations.
- to_operation() Operation¶
Convert the quantum computation to a single operation.
This gives ownership of the operations to the resulting operation, so the quantum computation will be empty after this operation.
When the quantum computation contains more than one operation, the resulting operation is a
CompoundOperation.- Returns:
The operation representing the quantum computation.
- __getitem__(index: int) Operation¶
- __getitem__(index: slice) list[Operation]
Get a slice of operations from the quantum computation.
Note
This gives write access to the operations in the given slice.
- Parameters:
index – The slice of 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.
- insert(index: int, value: Operation) None¶
Insert an operation at the given index.
- Parameters:
index – The index to insert the operation at.
value – The operation to insert.
- append(value: Operation) None¶
Append an operation to the end of the quantum computation.
- Parameters:
value – The operation to append.
- add_qubit_register(n: int, name: str = 'q') QuantumRegister¶
Add a qubit register to the quantum computation.
- Parameters:
n – The number of qubits in the qubit register.
name – The name of the qubit register.
- Returns:
The qubit register added to the quantum computation.
- add_classical_register(n: int, name: str = 'c') ClassicalRegister¶
Add a classical register to the quantum computation.
- Parameters:
n – The number of bits in the classical register.
name – The name of the classical register.
- Returns:
The classical register added to the quantum computation.
- add_ancillary_register(n: int, name: str = 'anc') QuantumRegister¶
Add an ancillary register to the quantum computation.
- Parameters:
n – The number of qubits in the ancillary register.
name – The name of the ancillary register.
- Returns:
The ancillary register added to the quantum computation.
- unify_quantum_registers(name: str = 'q') QuantumRegister¶
Unify all quantum registers in the quantum computation.
- Parameters:
name – The name of the unified quantum register.
- Returns:
The unified quantum register.
- property qregs: dict[str, QuantumRegister]¶
The quantum registers in the quantum computation.
- property cregs: dict[str, ClassicalRegister]¶
The classical registers in the quantum computation.
- property ancregs: dict[str, QuantumRegister]¶
The ancillary registers in the quantum computation.
- property initial_layout: Permutation¶
The initial layout of the qubits in the quantum computation.
This is a permutation of the qubits in the quantum computation. It is mainly used to track the mapping of circuit qubits to device qubits during quantum circuit compilation. The keys are the device qubits (in which a compiled circuit is expressed in), and the values are the circuit qubits (in which the original quantum circuit is expressed in).
Any operations in the quantum circuit are expected to be expressed in terms of the keys of the initial layout.
Examples
If no initial layout is explicitly specified (which is the default), the initial layout is assumed to be the identity permutation.
Assume a three-qubit circuit has been compiled to a four qubit device and circuit qubit 0 is mapped to device qubit 1, circuit qubit 1 is mapped to device qubit 2, and circuit qubit 2 is mapped to device qubit 3. Then the initial layout is {1: 0, 2: 1, 3: 2}.
- property output_permutation: Permutation¶
The output permutation of the qubits in the quantum computation.
This is a permutation of the qubits in the quantum computation. It is mainly used to track where individual qubits end up at the end of the quantum computation, for example after a circuit has been compiled to a specific device and SWAP gates have been inserted, which permute the qubits. Similar to the initial layout, the keys are the qubits in the circuit and the values are the qubits in the “original” circuit.
Examples
If no output permutation is explicitly specified and the circuit does not contain measurements at the end, the output permutation is assumed to be the identity permutation.
If the circuit contains measurements at the end, these measurements are used to infer the output permutation. Assume a three-qubit circuit has been compiled to a four qubit device and, at the end of the circuit, circuit qubit 0 is measured into classical bit 2, circuit qubit 1 is measured into classical bit 1, and circuit qubit 3 is measured into classical bit 0. Then the output permutation is {0: 2, 1: 1, 3: 0}.
- initialize_io_mapping() None¶
Initialize the I/O mapping of the quantum computation.
If no initial layout is explicitly specified, the initial layout is assumed to be the identity permutation. If the circuit contains measurements at the end, these measurements are used to infer the output permutation.
- set_circuit_qubit_ancillary(q: int) None¶
Set a circuit (i.e., logical) qubit to be ancillary.
- Parameters:
q – The index of the circuit qubit to set as ancillary.
- set_circuit_qubits_ancillary(q_min: int, q_max: int) None¶
Set a range of circuit (i.e., logical) qubits to be ancillary.
- Parameters:
q_min – The minimum index of the circuit qubits to set as ancillary.
q_max – The maximum index of the circuit qubits to set as ancillary.
- is_circuit_qubit_ancillary(q: int) bool¶
Check if a circuit (i.e., logical) qubit is ancillary.
- Parameters:
q – The index of the circuit qubit to check.
- Returns:
True if the circuit qubit is ancillary, False otherwise.
- set_circuit_qubit_garbage(q: int) None¶
Set a circuit (i.e., logical) qubit to be garbage.
- Parameters:
q – The index of the circuit qubit to set as garbage.
- set_circuit_qubits_garbage(q_min: int, q_max: int) None¶
Set a range of circuit (i.e., logical) qubits to be garbage.
- Parameters:
q_min – The minimum index of the circuit qubits to set as garbage.
q_max – The maximum index of the circuit qubits to set as garbage.
- is_circuit_qubit_garbage(q: int) bool¶
Check if a circuit (i.e., logical) qubit is garbage.
- Parameters:
q – The index of the circuit qubit to check.
- Returns:
True if the circuit qubit is garbage, False otherwise.
- add_variable(var: Expression | float) None¶
Add a variable to the quantum computation.
- Parameters:
var – The variable to add.
- add_variables(vars_: Sequence[Expression | float]) None¶
Add multiple variables to the quantum computation.
- Parameters:
vars – The variables to add.
- is_variable_free() bool¶
Check if the quantum computation is free of variables.
- Returns:
True if the quantum computation is free of variables, False otherwise.
- instantiate(assignment: Mapping[Variable, float]) QuantumComputation¶
Instantiate the quantum computation with the given variable assignment.
- Parameters:
assignment – The variable assignment to instantiate the quantum computation with.
- Returns:
The instantiated quantum computation.
- instantiate_inplace(assignment: Mapping[Variable, float]) None¶
Instantiate the quantum computation with the given variable assignment in-place.
- Parameters:
assignment – The variable assignment to instantiate the quantum computation with.
- qasm2_str() str¶
Return the OpenQASM2 representation of the quantum computation as a string.
Note
This uses some custom extensions to OpenQASM 2.0 that allow for easier definition of multi-controlled gates. These extensions might not be supported by all OpenQASM 2.0 parsers. Consider using the
qasm3_str()method instead, which uses OpenQASM 3.0 that natively supports multi-controlled gates. The export also assumes the bigger, non-standard qelib1.inc from Qiskit is available.- Returns:
The OpenQASM2 representation of the quantum computation as a string.
- qasm2(filename: PathLike[str] | str) None¶
Write the OpenQASM2 representation of the quantum computation to a file.
See also
- Parameters:
filename – The filename of the file to write the OpenQASM2 representation to.
- qasm3_str() str¶
Return the OpenQASM3 representation of the quantum computation as a string.
- Returns:
The OpenQASM3 representation of the quantum computation as a string.
- qasm3(filename: PathLike[str] | str) None¶
Write the OpenQASM3 representation of the quantum computation to a file.
See also
- Parameters:
filename – The filename of the file to write the OpenQASM3 representation to.
- i(q: int) None¶
Apply an identity operation.
\[\begin{split}I = \begin{pmatrix} 1 & 0 \\ 0 & 1 \end{pmatrix}\end{split}\]- Parameters:
q – The target qubit
- ci(control: Control | int, target: int) None¶
Apply a controlled identity operation.
See also
- Parameters:
control – The control qubit
target – The target qubit
- mci(controls: Set[Control | int], target: int) None¶
Apply a multi-controlled identity operation.
See also
- Parameters:
controls – The control qubits
target – The target qubit
- x(q: int) None¶
Apply a Pauli-X gate.
\[\begin{split}X = \begin{pmatrix} 0 & 1 \\ 1 & 0 \end{pmatrix}\end{split}\]- Parameters:
q – The target qubit
- cx(control: Control | int, target: int) None¶
Apply a controlled Pauli-X (i.e., CNOT or CX) gate.
See also
- Parameters:
control – The control qubit
target – The target qubit
- mcx(controls: Set[Control | int], target: int) None¶
Apply a multi-controlled Pauli-X (i.e., Toffoli or MCX) gate.
See also
- Parameters:
controls – The control qubits
target – The target qubit
- y(q: int) None¶
Apply a Pauli-Y gate.
\[\begin{split}Y = \begin{pmatrix} 0 & -i \\ i & 0 \end{pmatrix}\end{split}\]- Parameters:
q – The target qubit
- cy(control: Control | int, target: int) None¶
Apply a controlled Pauli-Y gate.
See also
- Parameters:
control – The control qubit
target – The target qubit
- mcy(controls: Set[Control | int], target: int) None¶
Apply a multi-controlled Pauli-Y gate.
See also
- Parameters:
controls – The control qubits
target – The target qubit
- z(q: int) None¶
Apply a Pauli-Z gate.
\[\begin{split}Z = \begin{pmatrix} 1 & 0 \\ 0 & -1 \end{pmatrix}\end{split}\]- Parameters:
q – The target qubit
- cz(control: Control | int, target: int) None¶
Apply a controlled Pauli-Z gate.
See also
- Parameters:
control – The control qubit
target – The target qubit
- mcz(controls: Set[Control | int], target: int) None¶
Apply a multi-controlled Pauli-Z gate.
See also
- Parameters:
controls – The control qubits
target – The target qubit
- h(q: int) None¶
Apply a Hadamard gate.
\[\begin{split}H = \frac{1}{\sqrt{2}} \begin{pmatrix} 1 & 1 \\ 1 & -1 \end{pmatrix}\end{split}\]- Parameters:
q – The target qubit
- ch(control: Control | int, target: int) None¶
Apply a controlled Hadamard gate.
See also
- Parameters:
control – The control qubit
target – The target qubit
- mch(controls: Set[Control | int], target: int) None¶
Apply a multi-controlled Hadamard gate.
See also
- Parameters:
controls – The control qubits
target – The target qubit
- s(q: int) None¶
Apply an S (i.e., phase) gate.
\[\begin{split}S = \begin{pmatrix} 1 & 0 \\ 0 & i \end{pmatrix}\end{split}\]- Parameters:
q – The target qubit
- cs(control: Control | int, target: int) None¶
Apply a controlled S gate.
See also
- Parameters:
control – The control qubit
target – The target qubit
- mcs(controls: Set[Control | int], target: int) None¶
Apply a multi-controlled S gate.
See also
- Parameters:
controls – The control qubits
target – The target qubit
- sdg(q: int) None¶
Apply an \(S^\dagger\) gate.
\[\begin{split}S^\dagger = \begin{pmatrix} 1 & 0 \\ 0 & -i \end{pmatrix}\end{split}\]- Parameters:
q – The target qubit
- csdg(control: Control | int, target: int) None¶
Apply a controlled \(S^\dagger\) gate.
See also
- Parameters:
control – The control qubit
target – The target qubit
- mcsdg(controls: Set[Control | int], target: int) None¶
Apply a multi-controlled \(S^\dagger\) gate.
See also
- Parameters:
controls – The control qubits
target – The target qubit
- t(q: int) None¶
Apply a T gate.
\[\begin{split}T = \begin{pmatrix} 1 & 0 \\ 0 & e^{i \pi / 4} \end{pmatrix}\end{split}\]- Parameters:
q – The target qubit
- ct(control: Control | int, target: int) None¶
Apply a controlled T gate.
See also
- Parameters:
control – The control qubit
target – The target qubit
- mct(controls: Set[Control | int], target: int) None¶
Apply a multi-controlled T gate.
See also
- Parameters:
controls – The control qubits
target – The target qubit
- tdg(q: int) None¶
Apply a \(T^\dagger\) gate.
\[\begin{split}T^\dagger = \begin{pmatrix} 1 & 0 \\ 0 & e^{-i \pi / 4} \end{pmatrix}\end{split}\]- Parameters:
q – The target qubit
- ctdg(control: Control | int, target: int) None¶
Apply a controlled \(T^\dagger\) gate.
See also
- Parameters:
control – The control qubit
target – The target qubit
- mctdg(controls: Set[Control | int], target: int) None¶
Apply a multi-controlled \(T^\dagger\) gate.
See also
- Parameters:
controls – The control qubits
target – The target qubit
- v(q: int) None¶
Apply a V gate.
\[\begin{split}V = \frac{1}{\sqrt{2}} \begin{pmatrix} 1 & -i \\ -i & 1 \end{pmatrix}\end{split}\]- Parameters:
q – The target qubit
- cv(control: Control | int, target: int) None¶
Apply a controlled V gate.
See also
- Parameters:
control – The control qubit
target – The target qubit
- mcv(controls: Set[Control | int], target: int) None¶
Apply a multi-controlled V gate.
See also
- Parameters:
controls – The control qubits
target – The target qubit
- vdg(q: int) None¶
Apply a \(V^\dagger\) gate.
\[\begin{split}V^\dagger = \frac{1}{\sqrt{2}} \begin{pmatrix} 1 & i \\ i & 1 \end{pmatrix}\end{split}\]- Parameters:
q – The target qubit
- cvdg(control: Control | int, target: int) None¶
Apply a controlled \(V^\dagger\) gate.
See also
- Parameters:
control – The control qubit
target – The target qubit
- mcvdg(controls: Set[Control | int], target: int) None¶
Apply a multi-controlled \(V^\dagger\) gate.
See also
- Parameters:
controls – The control qubits
target – The target qubit
- sx(q: int) None¶
Apply a \(\sqrt{X}\) gate.
\[\begin{split}\sqrt{X} = \frac{1}{2} \begin{pmatrix} 1 + i & 1 - i \\ 1 - i & 1 + i \end{pmatrix}\end{split}\]- Parameters:
q – The target qubit
- csx(control: Control | int, target: int) None¶
Apply a controlled \(\sqrt{X}\) gate.
See also
- Parameters:
control – The control qubit
target – The target qubit
- mcsx(controls: Set[Control | int], target: int) None¶
Apply a multi-controlled \(\sqrt{X}\) gate.
See also
- Parameters:
controls – The control qubits
target – The target qubit
- sxdg(q: int) None¶
Apply a \(\sqrt{X}^\dagger\) gate.
\[\begin{split}\sqrt{X}^{\dagger} = \frac{1}{2} \begin{pmatrix} 1 - i & 1 + i \\ 1 + i & 1 - i \end{pmatrix}\end{split}\]- Parameters:
q – The target qubit
- csxdg(control: Control | int, target: int) None¶
Apply a controlled \(\sqrt{X}^\dagger\) gate.
See also
- Parameters:
control – The control qubit
target – The target qubit
- mcsxdg(controls: Set[Control | int], target: int) None¶
Apply a multi-controlled \(\sqrt{X}^\dagger\) gate.
See also
- Parameters:
controls – The control qubits
target – The target qubit
- rx(theta: Expression | float, q: int) None¶
Apply an \(R_x(\theta)\) gate.
\[\begin{split}R_x(\theta) = e^{-i \theta X / 2} = \cos(\theta / 2) I - i \sin(\theta / 2) X = \begin{pmatrix} \cos(\theta / 2) & -i \sin(\theta / 2) \\ -i \sin(\theta / 2) & \cos(\theta / 2) \end{pmatrix}\end{split}\]- Parameters:
theta – The rotation angle
q – The target qubit
- crx(theta: Expression | float, control: Control | int, target: int) None¶
Apply a controlled \(R_x(\theta)\) gate.
See also
- Parameters:
theta – The rotation angle
control – The control qubit
target – The target qubit
- mcrx(theta: Expression | float, controls: Set[Control | int], target: int) None¶
Apply a multi-controlled \(R_x(\theta)\) gate.
See also
- Parameters:
theta – The rotation angle
controls – The control qubits
target – The target qubit
- ry(theta: Expression | float, q: int) None¶
Apply an \(R_y(\theta)\) gate.
\[\begin{split}R_y(\theta) = e^{-i \theta Y / 2} = \cos(\theta / 2) I - i \sin(\theta / 2) Y = \begin{pmatrix} \cos(\theta / 2) & -\sin(\theta / 2) \\ \sin(\theta / 2) & \cos(\theta / 2) \end{pmatrix}\end{split}\]- Parameters:
theta – The rotation angle
q – The target qubit
- cry(theta: Expression | float, control: Control | int, target: int) None¶
Apply a controlled \(R_y(\theta)\) gate.
See also
- Parameters:
theta – The rotation angle
control – The control qubit
target – The target qubit
- mcry(theta: Expression | float, controls: Set[Control | int], target: int) None¶
Apply a multi-controlled \(R_y(\theta)\) gate.
See also
- Parameters:
theta – The rotation angle
controls – The control qubits
target – The target qubit
- rz(theta: Expression | float, q: int) None¶
Apply an \(R_z(\theta)\) gate.
\[\begin{split}R_z(\theta) = e^{-i \theta Z / 2} = \begin{pmatrix} e^{-i \theta / 2} & 0 \\ 0 & e^{i \theta / 2} \end{pmatrix}\end{split}\]- Parameters:
theta – The rotation angle
q – The target qubit
- crz(theta: Expression | float, control: Control | int, target: int) None¶
Apply a controlled \(R_z(\theta)\) gate.
See also
- Parameters:
theta – The rotation angle
control – The control qubit
target – The target qubit
- mcrz(theta: Expression | float, controls: Set[Control | int], target: int) None¶
Apply a multi-controlled \(R_z(\theta)\) gate.
See also
- Parameters:
theta – The rotation angle
controls – The control qubits
target – The target qubit
- p(theta: Expression | float, q: int) None¶
Apply a phase gate.
\[\begin{split}P(\theta) = \begin{pmatrix} 1 & 0 \\ 0 & e^{i \theta} \end{pmatrix}\end{split}\]- Parameters:
theta – The rotation angle
q – The target qubit
- cp(theta: Expression | float, control: Control | int, target: int) None¶
Apply a controlled phase gate.
See also
- Parameters:
theta – The rotation angle
control – The control qubit
target – The target qubit
- mcp(theta: Expression | float, controls: Set[Control | int], target: int) None¶
Apply a multi-controlled phase gate.
See also
- Parameters:
theta – The rotation angle
controls – The control qubits
target – The target qubit
- u2(phi: Expression | float, lambda_: Expression | float, q: int) None¶
Apply a \(U_2(\phi, \lambda)\) gate.
\[\begin{split}U_2(\phi, \lambda) = \frac{1}{\sqrt{2}} \begin{pmatrix} 1 & -e^{i \lambda} \\ e^{i \phi} & e^{i (\phi + \lambda)} \end{pmatrix}\end{split}\]- Parameters:
phi – The rotation angle
lambda – The rotation angle
q – The target qubit
- cu2(phi: Expression | float, lambda_: Expression | float, control: Control | int, target: int) None¶
Apply a controlled \(U_2(\phi, \lambda)\) gate.
See also
- Parameters:
phi – The rotation angle
lambda – The rotation angle
control – The control qubit
target – The target qubit
- mcu2(phi: Expression | float, lambda_: Expression | float, controls: Set[Control | int], target: int) None¶
Apply a multi-controlled \(U_2(\phi, \lambda)\) gate.
See also
- Parameters:
phi – The rotation angle
lambda – The rotation angle
controls – The control qubits
target – The target qubit
- r(theta: Expression | float, phi: Expression | float, q: int) None¶
Apply an \(R(\theta, \phi)\) gate.
\[\begin{split}R(\theta, \phi) = e^{-i \frac{\theta}{2} (\cos(\phi) X + \sin(\phi) Y)} = \begin{pmatrix} \cos(\theta / 2) & -i e^{-i \phi} \sin(\theta / 2) \\ -i e^{i \phi} \sin(\theta / 2) & \cos(\theta / 2) \end{pmatrix}\end{split}\]- Parameters:
theta – The rotation angle
phi – The rotation angle
q – The target qubit
- cr(theta: Expression | float, phi: Expression | float, control: Control | int, target: int) None¶
Apply a controlled \(R(\theta, \phi)\) gate.
See also
- Parameters:
theta – The rotation angle
phi – The rotation angle
control – The control qubit
target – The target qubit
- mcr(theta: Expression | float, phi: Expression | float, controls: Set[Control | int], target: int) None¶
Apply a multi-controlled \(R(\theta, \phi)\) gate.
See also
- Parameters:
theta – The rotation angle
phi – The rotation angle
controls – The control qubits
target – The target qubit
- u(theta: Expression | float, phi: Expression | float, lambda_: Expression | float, q: int) None¶
Apply a \(U(\theta, \phi, \lambda)\) gate.
\[\begin{split}U(\theta, \phi, \lambda) = \begin{pmatrix} \cos(\theta / 2) & -e^{i \lambda} \sin(\theta / 2) \\ e^{i \phi} \sin(\theta / 2) & e^{i (\phi + \lambda)}\cos(\theta / 2) \end{pmatrix}\end{split}\]- Parameters:
theta – The rotation angle
phi – The rotation angle
lambda – The rotation angle
q – The target qubit
- cu(theta: Expression | float, phi: Expression | float, lambda_: Expression | float, control: Control | int, target: int) None¶
Apply a controlled \(U(\theta, \phi, \lambda)\) gate.
See also
- Parameters:
theta – The rotation angle
phi – The rotation angle
lambda – The rotation angle
control – The control qubit
target – The target qubit
- mcu(theta: Expression | float, phi: Expression | float, lambda_: Expression | float, controls: Set[Control | int], target: int) None¶
Apply a multi-controlled \(U(\theta, \phi, \lambda)\) gate.
See also
- Parameters:
theta – The rotation angle
phi – The rotation angle
lambda – The rotation angle
controls – The control qubits
target – The target qubit
- swap(target1: int, target2: int) None¶
Apply a SWAP gate.
\[\begin{split}\text{SWAP} = \begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 \end{pmatrix}\end{split}\]- Parameters:
target1 – The first target qubit
target2 – The second target qubit
- cswap(control: Control | int, target1: int, target2: int) None¶
Apply a controlled SWAP gate.
See also
- Parameters:
control – The control qubit
target1 – The first target qubit
target2 – The second target qubit
- mcswap(controls: Set[Control | int], target1: int, target2: int) None¶
Apply a multi-controlled SWAP gate.
See also
- Parameters:
controls – The control qubits
target1 – The first target qubit
target2 – The second target qubit
- dcx(target1: int, target2: int) None¶
Apply a DCX (i.e., double CNOT) gate.
\[\begin{split}DCX = \begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & 0 & 0 & 1 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & 0 \end{pmatrix}\end{split}\]- Parameters:
target1 – The first target qubit
target2 – The second target qubit
- cdcx(control: Control | int, target1: int, target2: int) None¶
Apply a controlled DCX gate.
See also
- Parameters:
control – The control qubit
target1 – The first target qubit
target2 – The second target qubit
- mcdcx(controls: Set[Control | int], target1: int, target2: int) None¶
Apply a multi-controlled DCX gate.
See also
- Parameters:
controls – The control qubits
target1 – The first target qubit
target2 – The second target qubit
- ecr(target1: int, target2: int) None¶
Apply a ECR (echoed cross-resonance) gate.
\[\begin{split}ECR = \frac{1}{\sqrt{2}} \begin{pmatrix} 0 & 0 & 1 & i \\ 0 & 0 & i & 1 \\ 1 & -i & 0 & 0 \\ -i & 1 & 0 & 0 \end{pmatrix}\end{split}\]- Parameters:
target1 – The first target qubit
target2 – The second target qubit
- cecr(control: Control | int, target1: int, target2: int) None¶
Apply a controlled ECR gate.
See also
- Parameters:
control – The control qubit
target1 – The first target qubit
target2 – The second target qubit
- mcecr(controls: Set[Control | int], target1: int, target2: int) None¶
Apply a multi-controlled ECR gate.
See also
- Parameters:
controls – The control qubits
target1 – The first target qubit
target2 – The second target qubit
- iswap(target1: int, target2: int) None¶
Apply a \(i\text{SWAP}\) gate.
\[\begin{split}i\text{SWAP} = \begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & 0 & i & 0 \\ 0 & i & 0 & 0 \\ 0 & 0 & 0 & 1 \end{pmatrix}\end{split}\]- Parameters:
target1 – The first target qubit
target2 – The second target qubit
- ciswap(control: Control | int, target1: int, target2: int) None¶
Apply a controlled \(i\text{SWAP}\) gate.
See also
- Parameters:
control – The control qubit
target1 – The first target qubit
target2 – The second target qubit
- mciswap(controls: Set[Control | int], target1: int, target2: int) None¶
Apply a multi-controlled \(i\text{SWAP}\) gate.
See also
- Parameters:
controls – The control qubits
target1 – The first target qubit
target2 – The second target qubit
- iswapdg(target1: int, target2: int) None¶
Apply a \(i\text{SWAP}^\dagger\) gate.
\[\begin{split}i\text{SWAP}^\dagger = \begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & 0 & -i & 0 \\ 0 & -i & 0 & 0 \\ 0 & 0 & 0 & 1 \end{pmatrix}\end{split}\]- Parameters:
target1 – The first target qubit
target2 – The second target qubit
- ciswapdg(control: Control | int, target1: int, target2: int) None¶
Apply a controlled \(i\text{SWAP}^\dagger\) gate.
See also
- Parameters:
control – The control qubit
target1 – The first target qubit
target2 – The second target qubit
- mciswapdg(controls: Set[Control | int], target1: int, target2: int) None¶
Apply a multi-controlled \(i\text{SWAP}^\dagger\) gate.
See also
- Parameters:
controls – The control qubits
target1 – The first target qubit
target2 – The second target qubit
- peres(target1: int, target2: int) None¶
Apply a Peres gate.
\[\begin{split}\text{Peres} = \begin{pmatrix} 0 & 0 & 0 & 1 \\ 0 & 0 & 1 & 0 \\ 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \end{pmatrix}\end{split}\]- Parameters:
target1 – The first target qubit
target2 – The second target qubit
- cperes(control: Control | int, target1: int, target2: int) None¶
Apply a controlled Peres gate.
See also
- Parameters:
control – The control qubit
target1 – The first target qubit
target2 – The second target qubit
- mcperes(controls: Set[Control | int], target1: int, target2: int) None¶
Apply a multi-controlled Peres gate.
See also
- Parameters:
controls – The control qubits
target1 – The first target qubit
target2 – The second target qubit
- peresdg(target1: int, target2: int) None¶
Apply a \(\text{Peres}^\dagger\) gate.
\[\begin{split}\text{Peres}^\dagger = \begin{pmatrix} 0 & 0 & 0 & 1 \\ 0 & 0 & 1 & 0 \\ 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \end{pmatrix}\end{split}\]- Parameters:
target1 – The first target qubit
target2 – The second target qubit
- cperesdg(control: Control | int, target1: int, target2: int) None¶
Apply a controlled \(\text{Peres}^\dagger\) gate.
See also
- Parameters:
control – The control qubit
target1 – The first target qubit
target2 – The second target qubit
- mcperesdg(controls: Set[Control | int], target1: int, target2: int) None¶
Apply a multi-controlled \(\text{Peres}^\dagger\) gate.
See also
- Parameters:
controls – The control qubits
target1 – The first target qubit
target2 – The second target qubit
- rxx(theta: Expression | float, target1: int, target2: int) None¶
Apply an \(R_{xx}(\theta)\) gate.
\[\begin{split}R_{xx}(\theta) = e^{-i \theta XX / 2} = \cos(\theta / 2) I \otimes I - i \sin(\theta / 2) X \otimes X = \begin{pmatrix} \cos(\theta / 2) & 0 & 0 & -i \sin(\theta / 2) \\ 0 & \cos(\theta / 2) & -i \sin(\theta / 2) & 0 \\ 0 & -i \sin(\theta / 2) & \cos(\theta / 2) & 0 \\ -i \sin(\theta / 2) & 0 & 0 & \cos(\theta / 2) \end{pmatrix}\end{split}\]- Parameters:
theta – The rotation angle
target1 – The first target qubit
target2 – The second target qubit
- crxx(theta: Expression | float, control: Control | int, target1: int, target2: int) None¶
Apply a controlled \(R_{xx}(\theta)\) gate.
See also
- Parameters:
theta – The rotation angle
control – The control qubit
target1 – The first target qubit
target2 – The second target qubit
- mcrxx(theta: Expression | float, controls: Set[Control | int], target1: int, target2: int) None¶
Apply a multi-controlled \(R_{xx}(\theta)\) gate.
See also
- Parameters:
theta – The rotation angle
controls – The control qubits
target1 – The first target qubit
target2 – The second target qubit
- ryy(theta: Expression | float, target1: int, target2: int) None¶
Apply an \(R_{yy}(\theta)\) gate.
\[\begin{split}R_{yy}(\theta) = e^{-i \theta YY / 2} = \cos(\theta / 2) I \otimes I - i \sin(\theta / 2) Y \otimes Y = \begin{pmatrix} \cos(\theta / 2) & 0 & 0 & i \sin(\theta / 2) \\ 0 & \cos(\theta / 2) & -i \sin(\theta / 2) & 0 \\ 0 & -i \sin(\theta / 2) & \cos(\theta / 2) & 0 \\ i \sin(\theta / 2) & 0 & 0 & \cos(\theta / 2) \end{pmatrix}\end{split}\]- Parameters:
theta – The rotation angle
target1 – The first target qubit
target2 – The second target qubit
- cryy(theta: Expression | float, control: Control | int, target1: int, target2: int) None¶
Apply a controlled \(R_{yy}(\theta)\) gate.
See also
- Parameters:
theta – The rotation angle
control – The control qubit
target1 – The first target qubit
target2 – The second target qubit
- mcryy(theta: Expression | float, controls: Set[Control | int], target1: int, target2: int) None¶
Apply a multi-controlled \(R_{yy}(\theta)\) gate.
See also
- Parameters:
theta – The rotation angle
controls – The control qubits
target1 – The first target qubit
target2 – The second target qubit
- rzx(theta: Expression | float, target1: int, target2: int) None¶
Apply an \(R_{zx}(\theta)\) gate.
\[\begin{split}R_{zx}(\theta) = e^{-i \theta ZX / 2} = \cos(\theta / 2) I \otimes I - i \sin(\theta / 2) Z \otimes X = \begin{pmatrix} \cos(\theta/2) & -i \sin(\theta/2) & 0 & 0 \\ -i \sin(\theta/2) & \cos(\theta/2) & 0 & 0 \\ 0 & 0 & \cos(\theta/2) & i \sin(\theta/2) \\ 0 & 0 & i \sin(\theta/2) & \cos(\theta/2) \end{pmatrix}\end{split}\]- Parameters:
theta – The rotation angle
target1 – The first target qubit
target2 – The second target qubit
- crzx(theta: Expression | float, control: Control | int, target1: int, target2: int) None¶
Apply a controlled \(R_{zx}(\theta)\) gate.
See also
- Parameters:
theta – The rotation angle
control – The control qubit
target1 – The first target qubit
target2 – The second target qubit
- mcrzx(theta: Expression | float, controls: Set[Control | int], target1: int, target2: int) None¶
Apply a multi-controlled \(R_{zx}(\theta)\) gate.
See also
- Parameters:
theta – The rotation angle
controls – The control qubits
target1 – The first target qubit
target2 – The second target qubit
- rzz(theta: Expression | float, target1: int, target2: int) None¶
Apply an \(R_{zz}(\theta)\) gate.
\[\begin{split}R_{zz}(\theta) = e^{-i \theta ZZ / 2} = \begin{pmatrix} e^{-i \theta / 2} & 0 & 0 & 0 \\ 0 & e^{i \theta / 2} & 0 & 0 \\ 0 & 0 & e^{i \theta / 2} & 0 \\ 0 & 0 & 0 & e^{-i \theta / 2} \end{pmatrix}\end{split}\]- Parameters:
theta – The rotation angle
target1 – The first target qubit
target2 – The second target qubit
- crzz(theta: Expression | float, control: Control | int, target1: int, target2: int) None¶
Apply a controlled \(R_{zz}(\theta)\) gate.
See also
- Parameters:
theta – The rotation angle
control – The control qubit
target1 – The first target qubit
target2 – The second target qubit
- mcrzz(theta: Expression | float, controls: Set[Control | int], target1: int, target2: int) None¶
Apply a multi-controlled \(R_{zz}(\theta)\) gate.
See also
- Parameters:
theta – The rotation angle
controls – The control qubits
target1 – The first target qubit
target2 – The second target qubit
- xx_minus_yy(theta: Expression | float, beta: Expression | float, target1: int, target2: int) None¶
Apply an \(R_{XX - YY}(\theta, \beta)\) gate.
\[\begin{split}R_{XX - YY}(\theta, \beta) = R_{z_2}(\beta) \cdot e^{-i \frac{\theta}{2} \frac{XX - YY}{2}} \cdot R_{z_2}(-\beta) = \begin{pmatrix} \cos(\theta / 2) & 0 & 0 & -i \sin(\theta / 2) e^{-i \beta} \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ -i \sin(\theta / 2) e^{i \beta} & 0 & 0 & \cos(\theta / 2) \end{pmatrix}\end{split}\]- Parameters:
theta – The rotation angle
beta – The rotation angle
target1 – The first target qubit
target2 – The second target qubit
- cxx_minus_yy(theta: Expression | float, beta: Expression | float, control: Control | int, target1: int, target2: int) None¶
Apply a controlled \(R_{XX - YY}(\theta, \beta)\) gate.
See also
- Parameters:
theta – The rotation angle
beta – The rotation angle
control – The control qubit
target1 – The first target qubit
target2 – The second target qubit
- mcxx_minus_yy(theta: Expression | float, beta: Expression | float, controls: Set[Control | int], target1: int, target2: int) None¶
Apply a multi-controlled \(R_{XX - YY}(\theta, \beta)\) gate.
See also
- Parameters:
theta – The rotation angle
beta – The rotation angle
controls – The control qubits
target1 – The first target qubit
target2 – The second target qubit
- xx_plus_yy(theta: Expression | float, beta: Expression | float, target1: int, target2: int) None¶
Apply an \(R_{XX + YY}(\theta, \beta)\) gate.
\[\begin{split}R_{XX + YY}(\theta, \beta) = R_{z_1}(\beta) \cdot e^{-i \frac{\theta}{2} \frac{XX + YY}{2}} \cdot R_{z_1}(-\beta) = \begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & \cos(\theta / 2) & -i \sin(\theta / 2) e^{-i \beta} & 0 \\ 0 & -i \sin(\theta / 2) e^{i \beta} & \cos(\theta / 2) & 0 \\ 0 & 0 & 0 & 1 \end{pmatrix}\end{split}\]- Parameters:
theta – The rotation angle
beta – The rotation angle
target1 – The first target qubit
target2 – The second target qubit
- cxx_plus_yy(theta: Expression | float, beta: Expression | float, control: Control | int, target1: int, target2: int) None¶
Apply a controlled \(R_{XX + YY}(\theta, \beta)\) gate.
See also
- Parameters:
theta – The rotation angle
beta – The rotation angle
control – The control qubit
target1 – The first target qubit
target2 – The second target qubit
- mcxx_plus_yy(theta: Expression | float, beta: Expression | float, controls: Set[Control | int], target1: int, target2: int) None¶
Apply a multi-controlled \(R_{XX + YY}(\theta, \beta)\) gate.
See also
- Parameters:
theta – The rotation angle
beta – The rotation angle
controls – The control qubits
target1 – The first target qubit
target2 – The second target qubit
- gphase(phase: float) None¶
Apply a global phase gate.
\[GPhase(\theta) = (e^{i \theta})\]- Parameters:
phase – The rotation angle
- measure(qubit: int, cbit: int) None¶
- measure(qubits: Sequence[int], cbits: Sequence[int]) None
Measure multiple qubits and store the results in classical bits.
This method is equivalent to calling
measure()multiple times.- Parameters:
qubits – The qubits to measure
cbits – The classical bits to store the results
- measure_all(*, add_bits: bool = True) None¶
Measure all qubits and store the results in classical bits.
- Details:
If add_bits is True, a new classical register (named “meas”) with the same size as the number of qubits will be added to the circuit and the results will be stored in it. If add_bits is False, the classical register must already exist and have a sufficient number of bits to store the results.
- Parameters:
add_bits – Whether to explicitly add a classical register
- reset(q: int) None¶
- reset(qubits: Sequence[int]) None
Add a reset operation to the circuit.
- Parameters:
qubits – The qubits to reset
- barrier() None¶
- barrier(q: int) None
- barrier(qubits: Sequence[int]) None
Add a barrier to the circuit.
- Parameters:
qubits – The qubits to add the barrier to
- if_else(then_operation: Operation, else_operation: Operation, control_register: ClassicalRegister, expected_value: int = 1, comparison_kind: ComparisonKind = ...) None¶
- if_else(then_operation: Operation, else_operation: Operation, control_bit: int, expected_value: int = 1, comparison_kind: ComparisonKind = ...) None
Add an if-else operation to the circuit.
- Parameters:
then_operation – The operation to apply if the condition is met
else_operation – The operation to apply if the condition is not met
control_bit – The index of the classical bit to check against
expected_value – The expected value of the control bit
comparison_kind – The kind of comparison to perform
- if_(op_type: OpType, target: int, control_register: ClassicalRegister, expected_value: int = 1, comparison_kind: ComparisonKind = ..., params: Sequence[float] = ...) None¶
- if_(op_type: OpType, target: int, control: Control | int, control_register: ClassicalRegister, expected_value: int = 1, comparison_kind: ComparisonKind = ..., params: Sequence[Expression | float] = ...) None
- if_(op_type: OpType, target: int, controls: Set[Control | int], control_register: ClassicalRegister, expected_value: int = 1, comparison_kind: ComparisonKind = ..., params: Sequence[Expression | float] = ...) None
- if_(op_type: OpType, target: int, control_bit: int, expected_value: bool = True, comparison_kind: ComparisonKind = ..., params: Sequence[float] = ...) None
- if_(op_type: OpType, target: int, control: Control | int, control_bit: int, expected_value: bool = True, comparison_kind: ComparisonKind = ..., params: Sequence[Expression | float] = ...) None
- if_(op_type: OpType, target: int, controls: Set[Control | int], control_bit: int, expected_value: bool = True, comparison_kind: ComparisonKind = ..., params: Sequence[Expression | float] = ...) None
Add an if operation to the circuit.
- Parameters:
op_type – The operation to apply
target – The target qubit
controls – The control qubits
control_bit – The index of the classical bit to check against
expected_value – The expected value of the control bit
comparison_kind – The kind of comparison to perform
params – The parameters of the operation.