Quantum Operations¶
This page documents all quantum operations available in Squint, organized by category.
Fock Space Operations¶
Operations for continuous variable (CV) quantum systems using the Fock (photon number) basis. These are commonly used for simulating linear optical networks and photonic quantum computing.
Key classes:
FockState- Fock basis states and superpositionsBeamSplitter- Two-mode beam splitterPhase- Single-mode phase shiftLinearOpticalUnitaryGate- General passive linear optical transformation
FockState
¶
Bases: AbstractPureState
Fock (photon number) state for continuous variable systems.
Represents a pure quantum state in the Fock basis, where each mode contains a definite number of photons. Can represent single Fock states or arbitrary superpositions of Fock states.
The state is specified as a sum of basis states with amplitudes: \(\(|\psi\rangle = \sum_i a_i |n_1^{(i)}, n_2^{(i)}, \ldots\rangle\)\)
where \(n_k^{(i)}\) is the photon number in mode \(k\) for term \(i\).
Attributes:
| Name | Type | Description |
|---|---|---|
n |
Sequence[tuple[complex, Sequence[int]]]
|
List of (amplitude, basis_indices) tuples defining the state. |
Example
wire0 = Wire(dim=5, idx=0)
wire1 = Wire(dim=5, idx=1)
# Single Fock state |1,0>
state = FockState(wires=(wire0, wire1), n=(1, 0))
# Vacuum state |0,0> (default)
vacuum = FockState(wires=(wire0, wire1))
# Superposition (|1,0> + |0,1>)/sqrt(2)
noon = FockState(wires=(wire0, wire1), n=[
(1.0, (1, 0)),
(1.0, (0, 1))
])
Source code in src/squint/ops/fock.py
FixedEnergyFockState
¶
Bases: AbstractPureState
Fock state superposition with fixed total photon number.
Creates a parameterized superposition over all Fock basis states with a fixed total number of photons \(n\) distributed across all modes. The state is parameterized by trainable weights and phases for each basis state.
The state has the form: \(\(|\psi\rangle = \sum_{\{n_i\}: \sum_i n_i = n} w_i e^{i\phi_i} |n_1, n_2, \ldots\rangle\)\)
where the sum is over all distributions of \(n\) photons across the modes, and \(w_i\) are softmax-normalized weights.
Attributes:
| Name | Type | Description |
|---|---|---|
weights |
ArrayLike
|
Trainable weights for each basis state (before softmax). |
phases |
ArrayLike
|
Trainable phases for each basis state. |
n |
int
|
Total photon number (energy). |
bases |
Sequence[tuple[complex | float, Sequence[int]]]
|
List of all valid photon number distributions. |
Example
Source code in src/squint/ops/fock.py
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 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 | |
TwoModeWeakThermalState
¶
Bases: AbstractMixedState
Two-mode weak coherent source.
Source code in src/squint/ops/fock.py
TwoModeSqueezingGate
¶
Bases: AbstractGate
TwoModeSqueezingGate
Source code in src/squint/ops/fock.py
BeamSplitter
¶
Bases: AbstractGate
Beam splitter gate for two optical modes.
Implements a lossless beam splitter that mixes two optical modes. The transformation is generated by the photon exchange Hamiltonian: \(\(H = i(a^\dagger b - a b^\dagger)\)\)
resulting in the unitary: \(\(U(r) = \exp(i r (a^\dagger b + a b^\dagger))\)\)
where \(a\), \(b\) are annihilation operators for the two modes. The parameter \(r\) controls the splitting ratio: \(r = \pi/4\) gives a 50:50 beam splitter.
Attributes:
| Name | Type | Description |
|---|---|---|
r |
ArrayLike
|
Beam splitter angle in radians. Default is \(\pi/4\) (50:50 splitter). |
Example
Source code in src/squint/ops/fock.py
LinearOpticalUnitaryGate
¶
Bases: AbstractGate
General linear optical unitary gate acting on multiple modes.
Implements an arbitrary passive linear optical transformation defined by a unitary matrix \(U\) acting on the mode creation operators: \(\(a_j^\dagger \to \sum_k U_{jk} a_k^\dagger\)\)
The unitary on the Fock space is computed using the permanent formula for bosonic transformations. This allows implementing arbitrary linear optical networks (combinations of beam splitters and phase shifters).
Attributes:
| Name | Type | Description |
|---|---|---|
unitary_modes |
ArrayLike
|
An \(m \times m\) unitary matrix defining the mode transformation, where \(m\) is the number of modes (wires). |
Example
wire0 = Wire(dim=5, idx=0)
wire1 = Wire(dim=5, idx=1)
# Hadamard-like transformation
U = jnp.array([[1, 1], [1, -1]]) / jnp.sqrt(2)
gate = LinearOpticalUnitaryGate(wires=(wire0, wire1), unitary_modes=U)
# 3-mode Fourier transform
wires = tuple(Wire(dim=4, idx=i) for i in range(3))
U = jnp.fft.fft(jnp.eye(3)) / jnp.sqrt(3)
gate = LinearOpticalUnitaryGate(wires=wires, unitary_modes=U)
Note
The unitary_modes matrix must be unitary (U @ U.conj().T = I). Computation uses the permanent which can be expensive for large photon numbers or many modes.
Source code in src/squint/ops/fock.py
337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 | |
Phase
¶
Bases: AbstractGate
Phase shift gate for optical modes.
Applies a phase shift \(\phi\) to an optical mode, which is equivalent to a rotation in the optical phase space. The transformation acts on the Fock states as: \(\(|n\rangle \to e^{in\phi} |n\rangle\)\)
This is generated by the number operator: \(U(\phi) = e^{i\phi \hat{n}}\).
Attributes:
| Name | Type | Description |
|---|---|---|
phi |
ArrayLike
|
Phase shift angle in radians. |
Example
Note
This gate is commonly used in Mach-Zehnder interferometers and for implementing phase estimation protocols in linear optics.
Source code in src/squint/ops/fock.py
Discrete Variable Operations¶
Operations for finite-dimensional quantum systems including qubits (dim=2) and qudits (dim>2). Includes standard gates like Pauli rotations, Hadamard, and controlled gates.
Key classes:
DiscreteVariableState- Computational basis states and superpositionsXGate,ZGate,HGate- Standard single-qubit gates (generalized for qudits)RXGate,RYGate,RZGate- Parameterized rotation gatesCXGate,CZGate- Controlled gates
DiscreteVariableState
¶
Bases: AbstractPureState
A pure quantum state for a discrete variable system.
\(|\psi\rangle = \sum_{i} a_i |i\rangle\) where \(a_i\) are amplitudes and \(|i\rangle\) are basis states.
Source code in src/squint/ops/dv.py
MaximallyMixedState
¶
Bases: AbstractMixedState
The maximally mixed state for discrete variable systems.
Represents the completely mixed density matrix \(\rho = I/d\) where \(d\) is the total Hilbert space dimension. This state has maximum von Neumann entropy and represents complete ignorance about the quantum state.
The density matrix is constructed as: \(\(\rho = \frac{1}{d} \sum_{i=0}^{d-1} |i\rangle\langle i|\)\)
where \(d = \prod_i d_i\) is the product of all wire dimensions.
Example
Note
This state requires the "mixed" backend in the circuit.
Source code in src/squint/ops/dv.py
XGate
¶
Bases: AbstractGate
The generalized shift operator, which when dim = 2 corresponds to the standard \(X\) gate.
\(U = \sum_{k=0}^{d-1} |k\rangle \langle (k+1) \mod d|\)
Source code in src/squint/ops/dv.py
ZGate
¶
Bases: AbstractGate
The generalized phase operator, which when dim = 2 corresponds to the standard \(Z\) gate.
\(U = \sum_{k=0}^{d-1} e^{2\pi i k / d} |k\rangle\langle k|\)
Source code in src/squint/ops/dv.py
HGate
¶
Bases: AbstractGate
The generalized discrete Fourier operator, which when dim = 2 corresponds to the standard \(H\) gate.
\(U = \frac{1}{\sqrt{d}} \sum_{j,k=0}^{d-1} e^{2\pi i jk / d} |j\rangle\langle k|\)
Source code in src/squint/ops/dv.py
Conditional
¶
Bases: AbstractGate
The generalized conditional operator. Applies gate \(U\) raised to a power conditional on the control state: \(U = \sum_{k=0}^{d-1} |k\rangle\langle k| \otimes U^k\)
Source code in src/squint/ops/dv.py
CXGate
¶
Bases: Conditional
Controlled-X (CNOT) gate for qubits and qudits.
Applies an X gate to the target qubit/qudit conditional on the control. For qubits (dim=2), this is the standard CNOT gate: \(\(CX = |0\rangle\langle 0| \otimes I + |1\rangle\langle 1| \otimes X\)\)
For qudits (dim>2), this generalizes to: \(\(CX = \sum_{k=0}^{d-1} |k\rangle\langle k| \otimes X^k\)\)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wires
|
tuple[Wire, Wire]
|
Tuple of (control_wire, target_wire). |
(0, 1)
|
Example
Source code in src/squint/ops/dv.py
CZGate
¶
Bases: Conditional
Controlled-Z gate for qubits and qudits.
Applies a Z gate to the target qubit/qudit conditional on the control. For qubits (dim=2), this is the standard CZ gate: \(\(CZ = |0\rangle\langle 0| \otimes I + |1\rangle\langle 1| \otimes Z\)\)
For qudits (dim>2), this generalizes to: \(\(CZ = \sum_{k=0}^{d-1} |k\rangle\langle k| \otimes Z^k\)\)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wires
|
tuple[Wire, Wire]
|
Tuple of (control_wire, target_wire). |
(0, 1)
|
Example
Source code in src/squint/ops/dv.py
RZGate
¶
Bases: AbstractGate
Rotation gate around the Z-axis for qubits and qudits.
For qubits (dim=2), this implements the standard RZ rotation: \(\(R_Z(\phi) = \begin{pmatrix} 1 & 0 \\ 0 & e^{i\phi} \end{pmatrix}\)\)
For qudits (dim>2), this generalizes to: \(\(R_Z(\phi) = \sum_{k=0}^{d-1} e^{ik\phi} |k\rangle\langle k|\)\)
Attributes:
| Name | Type | Description |
|---|---|---|
phi |
ArrayLike
|
The rotation angle in radians. |
Source code in src/squint/ops/dv.py
RXGate
¶
Bases: AbstractGate
Rotation gate around the X-axis for qubits.
Implements the standard RX rotation: \(\(R_X(\phi) = \cos(\phi/2) I - i \sin(\phi/2) X = \begin{pmatrix} \cos(\phi/2) & -i\sin(\phi/2) \\ -i\sin(\phi/2) & \cos(\phi/2) \end{pmatrix}\)\)
Attributes:
| Name | Type | Description |
|---|---|---|
phi |
ArrayLike
|
The rotation angle in radians. |
Note
This gate is only defined for qubits (dim=2).
Source code in src/squint/ops/dv.py
RYGate
¶
Bases: AbstractGate
Rotation gate around the Y-axis for qubits.
Implements the standard RY rotation: \(\(R_Y(\phi) = \cos(\phi/2) I - i \sin(\phi/2) Y = \begin{pmatrix} \cos(\phi/2) & -\sin(\phi/2) \\ \sin(\phi/2) & \cos(\phi/2) \end{pmatrix}\)\)
Attributes:
| Name | Type | Description |
|---|---|---|
phi |
ArrayLike
|
The rotation angle in radians. |
Note
This gate is only defined for qubits (dim=2).
Source code in src/squint/ops/dv.py
TwoLocalHermitianBasisGate
¶
Bases: AbstractGate
Two-qubit/qudit gate generated by a tensor product of Gell-Mann basis operators.
Implements gates of the form: \(\(U(\theta) = \exp(-i \theta \cdot G_i \otimes G_j)\)\)
where \(G_i\) and \(G_j\) are Gell-Mann basis operators (generalized Pauli matrices) acting on the first and second wire respectively. For qubits (dim=2), the Gell-Mann operators reduce to the Pauli matrices.
This is the base class for specific two-qubit interaction gates like RXXGate and RZZGate.
Attributes:
| Name | Type | Description |
|---|---|---|
angles |
ArrayLike
|
The rotation angle(s) in radians. |
_basis_op_indices |
tuple[int, int]
|
Indices of the Gell-Mann basis operators to use on each wire. For dim=2: 0=Z, 1=Y, 2=X, 3=I. |
Example
Source code in src/squint/ops/dv.py
Noise Channels¶
Quantum noise channels for modeling decoherence and errors. These require the "mixed" backend as they produce density matrices.
Key classes:
BitFlipChannel- Random X errors with probability pPhaseFlipChannel- Random Z errors (dephasing) with probability pDepolarizingChannel- Symmetric Pauli noiseErasureChannel- Traces out (erases) specified wires
ErasureChannel
¶
Bases: AbstractErasureChannel
Erasure channel that traces out specified wires.
This channel performs a partial trace over the specified wires, effectively "erasing" those subsystems from the quantum state. It models complete photon loss or the discarding of quantum information in those modes.
Mathematically, for a density matrix \(\rho\) on wires A and B, tracing out B gives: \(\(\text{Tr}_B[\rho] = \sum_i \langle i_B | \rho | i_B \rangle\)\)
Note
This channel requires the "mixed" backend in the circuit, as it produces a reduced density matrix.
Example
Source code in src/squint/ops/noise.py
BitFlipChannel
¶
Bases: AbstractKrausChannel
Qubit bit flip channel.
Models random bit flip errors with probability \(p\). The channel flips the qubit state \(|0\rangle \leftrightarrow |1\rangle\) with probability \(p\) and leaves it unchanged with probability \(1-p\).
Kraus operators: \(\(K_0 = \sqrt{1-p} \cdot I, \quad K_1 = \sqrt{p} \cdot X\)\)
The channel acts on a density matrix as: \(\(\mathcal{E}(\rho) = (1-p)\rho + p X\rho X\)\)
Attributes:
| Name | Type | Description |
|---|---|---|
p |
ArrayLike
|
Bit flip probability, must be in [0, 1]. |
Note
This channel is only defined for qubits (dim=2) and requires the "mixed" backend.
Example
Source code in src/squint/ops/noise.py
PhaseFlipChannel
¶
Bases: AbstractKrausChannel
Qubit phase flip (dephasing) channel.
Models random phase flip errors with probability \(p\). The channel applies a Z gate (phase flip) with probability \(p\) and leaves the state unchanged with probability \(1-p\).
Kraus operators: \(\(K_0 = \sqrt{1-p} \cdot I, \quad K_1 = \sqrt{p} \cdot Z\)\)
The channel acts on a density matrix as: \(\(\mathcal{E}(\rho) = (1-p)\rho + p Z\rho Z\)\)
This channel preserves populations but decoheres superpositions in the computational basis.
Attributes:
| Name | Type | Description |
|---|---|---|
p |
ArrayLike
|
Phase flip probability, must be in [0, 1]. |
Note
This channel is only defined for qubits (dim=2) and requires the "mixed" backend.
Example
Source code in src/squint/ops/noise.py
DepolarizingChannel
¶
Bases: AbstractKrausChannel
Qubit depolarizing channel.
Models symmetric noise that randomly applies one of the three Pauli errors (X, Y, or Z) each with probability \(p/4\), or leaves the state unchanged with probability \(1 - 3p/4\). At \(p=1\), the state is fully depolarized to the maximally mixed state.
Kraus operators: \(\(K_0 = \sqrt{1-3p/4} \cdot I, \quad K_1 = \sqrt{p/4} \cdot X\)\) \(\(K_2 = \sqrt{p/4} \cdot Y, \quad K_3 = \sqrt{p/4} \cdot Z\)\)
The channel acts on a density matrix as: \(\(\mathcal{E}(\rho) = (1-p)\rho + \frac{p}{3}(X\rho X + Y\rho Y + Z\rho Z)\)\)
which can also be written as: \(\(\mathcal{E}(\rho) = (1-p)\rho + p \cdot \frac{I}{2}\)\)
Attributes:
| Name | Type | Description |
|---|---|---|
p |
ArrayLike
|
Depolarizing probability, must be in [0, 1]. At p=0, no noise. At p=1, output is maximally mixed. |
Note
This channel is only defined for qubits (dim=2) and requires the "mixed" backend.
Example
Source code in src/squint/ops/noise.py
Blocks¶
Blocks allow grouping multiple operations for organizational purposes.
brickwork(wires: Sequence[Wire], depth: int, LocalGates: Union[Type[AbstractGate], Sequence[Type[AbstractGate]]], CouplingGate: Type[AbstractGate], periodic: bool = False) -> Block
¶
Create a brickwork block with the specified local and coupling gates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wires
|
Sequence[Wire]
|
The wires to apply the gates to. |
required |
depth
|
int
|
The depth of the brickwork block. |
required |
LocalGates
|
Union[Type[AbstractGate], Sequence[Type[AbstractGate]]]
|
The local gates to apply to each wire. |
required |
CouplingGate
|
Type[AbstractGate]
|
The coupling gate to apply to pairs of wires. |
required |
periodic
|
bool
|
Whether to use periodic boundary conditions. |
False
|
Returns: Block: A block containing the specified brickwork structure.
Source code in src/squint/blocks.py
brickwork_type(wires: Sequence[Wire], depth: int, ansatz: Literal[hea, rxx, rzz], periodic: bool = False)
¶
Create a brickwork block with the specified ansatz type. Ansatz can be one of 'hea', 'rxx', or 'rzz'. - 'hea' uses RX and RY gates for one-qubit gates and CZ for two-qubit gates. - 'rxx' uses RX and RY gates for one-qubit gates and RXX for two-qubit gates. - 'rzz' uses RZ gates for one-qubit gates and RZZ for two-qubit gates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wires
|
Sequence[Wire]
|
The wires to apply the gates to. |
required |
depth
|
int
|
The depth of the brickwork block. |
required |
ansatz
|
Literal[hea, rxx, rzz]
|
The type of ansatz to use. |
required |
periodic
|
bool
|
Whether to use periodic boundary conditions. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
Block |
A block containing the specified brickwork ansatz. |