Skip to content

Python API

The dynamiqs Python API features two main types of functions: solvers of differential equations describing quantum systems, and various utility functions to ease the creation and manipulation of quantum states and operators.

Quantum solvers

sesolve

Solve the Schrödinger equation.

mesolve

Solve the Lindblad master equation.

smesolve

Solve the diffusive stochastic master equation (SME).

Core

Time-dependent arrays

TimeArray

Base class for time-dependent arrays.

constant

Instantiate a constant time-array.

pwc

Instantiate a piecewise constant (PWC) time-array.

modulated

Instantiate a modulated time-array.

timecallable

Instantiate a callable time-array.

Solvers (dq.solver)

Tsit5

Tsitouras method of order 5 (adaptive step size ODE solver).

Dopri5

Dormand-Prince method of order 5 (adaptive step size ODE solver).

Dopri8

Dormand-Prince method of order 8 (adaptive step size ODE solver).

Euler

Euler method (fixed step size ODE solver).

Rouchon1

First-order Rouchon method (fixed step size ODE solver).

Rouchon2

Second-order Rouchon method (fixed step size ODE solver).

Propagator

Quantum propagator method.

Gradients (dq.gradient)

Autograd

Standard automatic differentiation of JAX.

CheckpointAutograd

Checkpointed automatic differentiation.

Options

Options

Generic options for the quantum solvers.

Results

SEResult

Result of the Schrödinger equation integration.

MEResult

Result of the Lindblad master equation integration.

Utilities

Operators

eye

Returns the identity operator.

zero

Returns the null operator.

destroy

Returns a bosonic annihilation operator, or a tuple of annihilation operators in a multi-mode system.

create

Returns a bosonic creation operator, or a tuple of creation operators in a multi-mode system.

number

Returns the number operator of a bosonic mode.

parity

Returns the parity operator of a bosonic mode.

displace

Returns the displacement operator of complex amplitude \(\alpha\).

squeeze

Returns the squeezing operator of complex squeezing amplitude \(z\).

quadrature

Returns the quadrature operator of phase angle \(\phi\).

position

Returns the position operator \(x = (a^\dag + a) / 2\).

momentum

Returns the momentum operator \(p = i (a^\dag - a) / 2\).

sigmax

Returns the Pauli \(\sigma_x\) operator.

sigmay

Returns the Pauli \(\sigma_y\) operator.

sigmaz

Returns the Pauli \(\sigma_z\) operator.

sigmap

Returns the Pauli raising operator \(\sigma_+\).

sigmam

Returns the Pauli lowering operator \(\sigma_-\).

hadamard

Returns the Hadamard transform on \(n\) qubits.

States

fock

Returns the ket of a Fock state or the ket of a tensor product of Fock states.

fock_dm

Returns the density matrix of a Fock state or the density matrix of a tensor product of Fock states.

basis

Alias of dq.fock().

basis_dm

Alias of dq.fock_dm().

coherent

Returns the ket of a coherent state, or the ket of a tensor product of coherent states.

coherent_dm

Returns the density matrix of a coherent state, or the density matrix of a tensor product of coherent states.

Quantum utilities

dag

Returns the adjoint (complex conjugate transpose) of a matrix.

powm

Returns the \(n\)-th matrix power of an array.

expm

Returns the matrix exponential of an array.

cosm

Returns the cosine of an array.

sinm

Returns the sine of an array.

trace

Returns the trace of an array along its last two dimensions.

tracemm

Return the trace of a matrix multiplication using a fast implementation.

ptrace

Returns the partial trace of a ket, bra or density matrix.

tensor

Returns the tensor product of multiple kets, bras, density matrices or operators.

expect

Returns the expectation value of an operator or list of operators on a ket, bra or density matrix.

norm

Returns the norm of a ket, bra or density matrix.

unit

Normalize a ket, bra or density matrix to unit norm.

dissipator

Applies the Lindblad dissipation superoperator to a density matrix.

lindbladian

Applies the Lindbladian superoperator to a density matrix.

isket

Returns True if the array is in the format of a ket.

isbra

Returns True if the array is in the format of a bra.

isdm

Returns True if the array is in the format of a density matrix.

isop

Returns True if the array is in the format of an operator.

isherm

Returns True if the array is Hermitian.

toket

Returns the ket representation of a pure quantum state.

tobra

Returns the bra representation of a pure quantum state.

todm

Returns the density matrix representation of a quantum state.

proj

Returns the projection operator onto a pure quantum state.

braket

Returns the inner product \(\braket{\psi|\varphi}\) between two kets.

overlap

Returns the overlap between two quantum states.

fidelity

Returns the fidelity of two states, kets or density matrices.

entropy_vn

Returns the Von Neumann entropy of a ket or density matrix.

wigner

Compute the Wigner distribution of a ket or density matrix.

to_qutip

Convert an array-like object into a QuTiP quantum object (or a list of QuTiP quantum objects if it has more than two dimensions).

set_device

Configure the default device.

set_precision

Configure the default floating point precision.

set_matmul_precision

Configure the default precision for matrix multiplications on GPUs and TPUs.

Vectorization

operator_to_vector

Returns the vectorized version of an operator.

vector_to_operator

Returns the operator version of a vectorized operator.

spre

Returns the superoperator formed from pre-multiplication by an operator.

spost

Returns the superoperator formed from post-multiplication by an operator.

sprepost

Returns the superoperator formed from pre- and post-multiplication by operators.

sdissipator

Returns the Lindblad dissipation superoperator (in matrix form).

slindbladian

Returns the Lindbladian superoperator (in matrix form).

Quantum optimal control

snap_gate

Returns a SNAP gate.

cd_gate

Returns a conditional displacement gate.

Random arrays

rand_real

Returns an array of uniformly distributed random real numbers.

rand_complex

Returns an array of uniformly distributed random complex numbers.

rand_herm

Returns a random complex Hermitian matrix.

rand_psd

Returns a random complex positive semi-definite matrix.

rand_dm

Returns a random density matrix (hermitian, positive semi-definite, and unit trace).

rand_ket

Returns a random ket with unit norm.

Plotting

plot_wigner

Plot the Wigner function of a state.

plot_wigner_mosaic

Plot the Wigner function of multiple states in a mosaic arrangement.

plot_wigner_gif

Plot a GIF of the Wigner function of multiple states.

plot_pwc_pulse

Plot a piecewise constant pulse.

plot_fock

Plot the photon number population of a state.

plot_fock_evolution

Plot the photon number population of state as a function of time.

plot_hinton

Plot a Hinton diagram.

gridplot

Returns a figure and an iterator of subplots organised in a grid.

mplstyle

Set custom Matplotlib style.