Operations

QuantumFlow supports several different quantum operations that act upon either pure or mixed states (or both). The four main types are Gate, which represents the action of an operator (typically unitary) on a state; Channel, which represents the action of a superoperator on a mixed state (used for mixed quantum-classical dynamics); Kraus, which represents a Channel as a collection of operators; and Circuit, which is a list of other operations that act in sequence. Circuits can contain any instance of the abstract quantum operation superclass, Operation, including other circuits.

Quantum operations are immutable, and transformations of these operations return new copies.

The main types of Operation’s are Gate, UnitaryGate, StdGate, Channel, Circuit, DAGCircuit, and Pauli.

class quantumflow.Operation(qubits: Sequence[Qubit], params: Sequence[float | Expr] | None = None)

An operation on a quantum state. An element of a quantum circuit.

Abstract Base Class for Gate, Circuit, and other quantum operations.

Variables:
  • qubits – The qubits that this Operation acts upon.

  • params – Optional keyword parameters used to create this gate

property H: Operation

Return the Hermitian conjugate of this quantum operation.

For unitary Gates (and Circuits composed of the same) the Hermitian conjugate returns the inverse Gate (or Circuit)

Raises:

ValueError – If this operation does not support Hermitian conjugate

aschannel() Channel

Convert this quantum operation to a channel (if possible).

Raises:

ValueError – If this operation cannot be converted to a Channel

asgate() Gate

Convert this quantum operation to a gate (if possible).

Raises:

ValueError – If this operation cannot be converted to a Gate

cv_args: ClassVar[Tuple[str, ...] | Tuple] = ()

The names of the parameters for this operation (For operations with a fixed number of float parameters)

cv_interchangeable: ClassVar[bool] = False

Is this a multi-qubit operation that is known to be invariant under permutations of qubits?

cv_qubit_nb: ClassVar[int] = 0

The number of qubits, for operations with a fixed number of qubits

decompose() Iterator[Operation]

Decompose this operation into smaller or more standard subunits. If cannot be decomposed, returns self.

Returns: An iteration of operations.

evolve(rho: Density) Density

Apply the action of this operation upon a mixed state

float_param(name: str, subs: Mapping[str, float] | None = None) float

Return a a named parameters of this Operation as a float.

Parameters:
  • name – The name of the parameter (should be in cls.cv_args)

  • subs – Symbolic substitutions to resolve symbolic Variables

Raises:
  • KeyError – If unrecognized parameter name

  • ValueError – If Variable cannot be converted to float

property name: str

Return the name of this Operation

on(*qubits: Qubit) OperationTV

Return a copy of this Operation with new qubits

param(name: str) float | Expr

Return a a named parameters of this Operation.

Raises:

KeyError – If unrecognized parameter name

property params: Tuple[float | Expr, ...]

Return all of the parameters of this Operation

qubit_indices(qubits: Sequence[Qubit]) Tuple[int, ...]

Convert qubits to index positions.

Raises:

ValueError – If argument qubits are not found in operation’s qubits

property qubit_nb: int

Return the total number of qubits

property qubits: Sequence[Qubit]

Return the total number of qubits

resolve(subs: Mapping[str, float]) OperationTV

Resolve symbolic parameters

rewire(labels: Dict[Qubit, Qubit]) OperationTV

Relabel qubits and return copy of this Operation

run(ket: State) State

Apply the action of this operation upon a pure state

specialize() Operation

For parameterized operations, return appropriate special cases for particular parameters. Else return the original Operation.

e.g. Rx(0.0, 0).specialize() -> I(0)

property tensor: ndarray

Returns the tensor representation of this operation (if possible)

property tensor_diagonal: ndarray

Returns the diagonal of the tensor representation of this operation (if possible)