Base classes¶
AbstractDoF
¶
Bases: Module
Abstract base class for degrees of freedom (DoF) in quantum systems.
Degrees of freedom classify the physical encoding of quantum information. Each DoF subclass represents a different physical implementation for encoding quantum states, which can be useful for enforcing circuit validity and distinguishing between different physical platforms.
Subclasses
DV: Discrete variable systems (qubits, qudits) Fock: Fock second-quantized systems (optical modes)
Source code in src/squint/interface/base.py
DV
¶
Bases: AbstractDoF
Discrete variable degree of freedom.
Represents finite-dimensional quantum systems such as qubits (dim=2) or qudits (dim>2). These systems have a finite number of basis states and are commonly implemented in platforms like superconducting circuits, trapped ions, and spin systems.
Source code in src/squint/interface/base.py
Fock
¶
Bases: AbstractDoF
Fock space degree of freedom.
Represents infinite-dimensional Fock space systems, typically optical modes with photon number states. In practice, the Hilbert space is truncated at a finite photon number cutoff specified by the wire dimension.
Source code in src/squint/interface/base.py
Wire
¶
Bases: Module
Represents a quantum subsystem (wire) in a circuit.
A Wire defines a single quantum subsystem with a specific Hilbert space dimension and degree of freedom type. Wires are the fundamental building blocks that connect quantum operations in a circuit, determining how operators act on different parts of the composite quantum system.
Attributes:
| Name | Type | Description |
|---|---|---|
dim |
int
|
The dimension of the local Hilbert space. For qubits, dim=2; for qudits, dim>2; for Fock spaces, dim is the photon number cutoff. |
dof |
type[AbstractDoF]
|
The type of degree of freedom this wire represents (e.g., DV for discrete variable, CV for continuous variable). |
idx |
str | int
|
Unique identifier for the wire, used to track which operations act on which subsystems. |
Example
from squint.ops.base import Wire, DV, CV
# Create a qubit wire
qubit = Wire(dim=2, dof=DV, idx=0)
# Create an optical mode wire with photon cutoff of 5
mode = Wire(dim=5, dof=CV, idx="signal")
# Use wires in operations
from squint.ops.dv import DiscreteVariableState, HGate
state = DiscreteVariableState(wires=(qubit,), n=(0,))
gate = HGate(wires=(qubit,))
Source code in src/squint/interface/base.py
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 | |
__init__(dim: int, dof: Optional[type[AbstractDoF]] = AbstractDoF, idx: Optional[int | str] = None)
¶
Initialize a Wire.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dim
|
int
|
The dimension of the local Hilbert space. Must be >= 2. For qubits use dim=2, for qudits use dim>2, for Fock spaces this is the photon number cutoff. |
required |
dof
|
type[AbstractDoF]
|
Type of degree of freedom that this wire represents. Can be used to enforce circuit validity and distinguish between different physical encodings. Defaults to AbstractDoF. |
AbstractDoF
|
idx
|
str | int
|
Unique identifier for the wire. If not provided, a random id is generated. |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If dim < 2. |
Source code in src/squint/interface/base.py
AbstractContainer
¶
AbstractProcess
¶
Bases: Module
An abstract base class for all quantum objects, including states, gates, channels, and measurements. It provides a common interface for various quantum objects, ensuring consistency and reusability across different types of quantum operations.
Attributes:
| Name | Type | Description |
|---|---|---|
wires |
tuple[int, ...]
|
A tuple of nonnegative integers representing the quantum wires on which the operation acts. Each wire corresponds to a specific subsystem in the composite quantum system. |
Source code in src/squint/interface/base.py
__init__(wires: Sequence[Wire])
¶
Initializes the AbstractProcess instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wires
|
tuple[int, ...]
|
A tuple of nonnegative integers representing the quantum wires on which the operation acts. Defaults to (0, 1). |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
If any wire in the provided tuple is not a nonnegative integer. |
Source code in src/squint/interface/base.py
AbstractState
¶
Bases: AbstractProcess
An abstract base class for all quantum states.
Source code in src/squint/interface/base.py
AbstractPureState
¶
Bases: AbstractState
An abstract base class for all pure quantum states, equivalent to the state vector formalism.
Pure states are associated with a Hilbert space of size
\(|\psi\rangle \in \mathcal{H}^{d_1 \times \dots \times d_w}\)
where \(w\) = len(wires) and \(d\) is assigned at compile time.
Source code in src/squint/interface/base.py
AbstractMixedState
¶
Bases: AbstractState
An abstract base class for all mixed quantum states, equivalent to the density matrix formalism.
Mixed states are associated with a Hilbert space of size
\(\rho \in \mathcal{H}^{d_1 \times \dots \times d_w \times d_1 \times \dots \times d_w}\)
where \(w\) = len(wires) and \(d\) is assigned at compile time.
Source code in src/squint/interface/base.py
AbstractGate
¶
Bases: AbstractProcess
An abstract base class for all unitary quantum gates, which transform an input state in a reversible way.
\(U \in \mathcal{H}^{d_1 \times \dots \times d_w \times d_1 \times \dots \times d_w}\)
where \(w\) = len(wires) and \(d\) is assigned at compile time.
Source code in src/squint/interface/base.py
AbstractChannel
¶
Bases: AbstractProcess
An abstract base class for quantum channels, including channels expressed as Kraus operators, erasure (partial trace), and others.
Source code in src/squint/interface/base.py
AbstractMeasurement
¶
Bases: AbstractProcess
An abstract base class for quantum measurements. Currently, this is not supported, and measurements are projective measurements in the computational basis.
Source code in src/squint/interface/base.py
AbstractInstrument
¶
Bases: AbstractProcess
An abstract base class for all quantum instruments.
Source code in src/squint/interface/base.py
SharedGate
¶
Bases: AbstractContainer
A class representing a shared quantum gate, which allows for the sharing of parameters or attributes across multiple copies of a quantum operation. This is useful for scenarios where multiple gates share the same underlying structure or parameters, such as in variational quantum circuits. This is most commonly used when applying the same parameterized gate across different wires, e.g., phase gates, for studying phase estimation protocols.
Attributes:
| Name | Type | Description |
|---|---|---|
op |
AbstractProcess
|
The base quantum operation that is shared across multiple copies. |
copies |
Sequence[AbstractProcess]
|
A sequence of copies of the base operation, each acting on different wires. |
where |
Callable
|
A function that determines which attributes of the operation are shared across copies. |
get |
Callable
|
A function that retrieves the shared attributes from the base operation. |
Source code in src/squint/interface/base.py
AbstractKrausChannel
¶
Bases: AbstractChannel
An abstract base class for quantum channels expressed as Kraus operators.
The channel \(K\) is of shape \((d_1 \times \dots \times d_w \times d_1 \times \dots \times d_w)\)
where \(w\) = len(wires) and \(d\) is assigned at compile time.
Source code in src/squint/interface/base.py
AbstractErasureChannel
¶
Bases: AbstractChannel
This channel traces out the local Hilbert space associated with the wires
Source code in src/squint/interface/base.py
Block
¶
Bases: AbstractContainer
A block operation that groups a sequence of quantum operations.
Blocks allow organizing multiple operations into a single logical unit.
They can be nested within circuits or other blocks, and support the same
add and unwrap interface as Circuit. Unlike Circuit, Block does not
specify a backend and is purely for organizational purposes.
Attributes:
| Name | Type | Description |
|---|---|---|
ops |
OrderedDict
|
Ordered dictionary mapping keys to operations or nested blocks. |
Example
Source code in src/squint/interface/base.py
__init__(ops: dict | OrderedDict = {})
¶
Initialize an empty Block.
Creates a new Block with no operations. Operations can be added
using the add method.
Source code in src/squint/interface/base.py
add(op: Union[AbstractProcess, AbstractContainer], key: str = None) -> None
¶
Add an operator to the block.
Operators are added sequentially. When this block is used in a circuit, the operations will be applied in the order they were added.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
op
|
AbstractProcess | Block
|
The operator or nested block to add. |
required |
key
|
str
|
A string key for indexing into the block's ops dictionary. If None, an integer counter is used as the key. |
None
|
Source code in src/squint/interface/base.py
create(dim)
cached
¶
Returns the create operator for a Hilbert space of dimension dim.
The create operator is a matrix that adds one excitation to a quantum system,
effectively increasing the energy level by one.
Args:
dim (int): The dimension of the Hilbert space.
Returns:
jnp.ndarray: A 2D array of shape (dim, dim) representing the create operator.
Source code in src/squint/interface/base.py
destroy(dim)
cached
¶
Returns the destroy operator for a Hilbert space of dimension dim.
The destroy operator is a matrix that annihilates one excitation of a quantum system,
effectively reducing the energy level by one.
Args:
dim (int): The dimension of the Hilbert space.
Returns:
jnp.ndarray: A 2D array of shape (dim, dim) representing the destroy operator.
Source code in src/squint/interface/base.py
eye(dim)
cached
¶
Returns the identity operator for a Hilbert space of dimension dim.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dim
|
int
|
The dimension of the Hilbert space. |
required |
Returns: jnp.ndarray: A 2D array of shape (dim, dim) representing the identity operator.
Source code in src/squint/interface/base.py
bases(dim)
cached
¶
Returns the computational basis indices for a Hilbert space of dimension dim.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dim
|
int
|
The dimension of the Hilbert space. |
required |
Returns:
| Type | Description |
|---|---|
|
jnp.ndarray: A 1D array of shape (dim,) containing the indices of the computational bases. |
Source code in src/squint/interface/base.py
dft(dim)
cached
¶
Returns the discrete Fourier transform matrix of dimension dim.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dim
|
int
|
The dimension of the DFT matrix. |
required |
Returns:
| Type | Description |
|---|---|
|
jnp.ndarray: A 2D array of shape (dim, dim) representing the DFT matrix. |
Source code in src/squint/interface/base.py
basis_operators(dim)
cached
¶
Return a basis of orthogonal Hermitian operators on a Hilbert space of dimension \(d\), with the identity element in the last place. i.e., the Gell-Mann operators (for dim=2, these are the four Pauli operators).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dim
|
int
|
The dimension of the Hilbert space. |
required |
Returns:
| Type | Description |
|---|---|
|
jnp.ndarray: A 3D array of shape (n_operators, dim, dim) containing the basis operators. |