API specification¶
The emu-sv API is based on the specification here. Concretely, the classes are as follows:
SVBackend¶
Bases: EmulatorBackend
A backend for emulating Pulser sequences using state vectors and sparse matrices. Noisy simulation is supported by solving the Lindblad equation and using effective noise channel or jump operators
| PARAMETER | DESCRIPTION |
|---|---|
sequence
|
The sequence to be executed.
TYPE:
|
config
|
Configuration for the SV backend.
TYPE:
|
mimic_qpu
|
Whether to enforce Register constrains imposed by the device in the Sequence.
TYPE:
|
Source code in pulser/backend/abc.py
run()
¶
Emulates the given sequence.
| RETURNS | DESCRIPTION |
|---|---|
Results | list[Results]
|
the simulation results |
Source code in emu_sv/sv_backend.py
SVConfig¶
Bases: EmulationConfig
The configuration of the emu-sv SVBackend. The kwargs passed to this class are passed on to the base class. See the API for that class for a list of available options.
| PARAMETER | DESCRIPTION |
|---|---|
dt
|
the timestep size that the solver uses. Note that observables are only calculated if the evaluation_times are divisible by dt.
TYPE:
|
max_krylov_dim
|
the size of the krylov subspace that the Lanczos algorithm maximally builds
TYPE:
|
krylov_tolerance
|
the Lanczos algorithm uses this as the convergence tolerance
TYPE:
|
gpu
|
whether to run the simulation on GPU
- if
TYPE:
|
interaction_cutoff
|
Set interaction coefficients below this value to
TYPE:
|
log_level
|
How much to log. Set to
TYPE:
|
log_file
|
If specified, log to this file rather than stout.
TYPE:
|
solver
|
The solver to use in the presence of Lindblad noise. By default it will use Monte Carlo quantum jumps if shot noise is present, and the Lindblad equation with density matrices otherwise.
TYPE:
|
kwargs
|
arguments that are passed to the base class
TYPE:
|
Examples:
gpu = True
dt = 1.0 #this will impact the runtime
krylov_tolerance = 1e-8 #the simulation will be faster, but less accurate
SVConfig(gpu=gpu, dt=dt, krylov_tolerance=krylov_tolerance,
with_modulation=True) #the last arg is taken from the base class
Source code in emu_sv/sv_config.py
StateVector¶
Bases: State[complex, Tensor]
Represents a quantum state vector in a computational basis.
This class extends the State class to handle state vectors,
providing various utilities for initialization, normalization,
manipulation, and measurement. The state vector must have a length
that is a power of 2, representing 2ⁿ basis states for n qubits.
| PARAMETER | DESCRIPTION |
|---|---|
vector
|
1D tensor representation of a state vector.
TYPE:
|
gpu
|
store the vector on GPU if True and a GPU is present, otherwise on CPU
TYPE:
|
eigenstates
|
sequence of eigenstates used as basis only qubit basis are supported (default: ('r','g'))
TYPE:
|
Source code in emu_sv/state_vector.py
n_qudits
property
¶
The number of qudits in the state.
__add__(other)
¶
Sum of two state vectors
| PARAMETER | DESCRIPTION |
|---|---|
other
|
the vector to add to this vector
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
StateVector
|
The summed state |
Source code in emu_sv/state_vector.py
__rmul__(scalar)
¶
Scalar multiplication
| PARAMETER | DESCRIPTION |
|---|---|
scalar
|
the scalar to multiply with
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
StateVector
|
The scaled state |
Source code in emu_sv/state_vector.py
inner(other)
¶
Compute
| PARAMETER | DESCRIPTION |
|---|---|
other
|
the other state
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
the inner product |
Source code in emu_sv/state_vector.py
make(num_sites, gpu=True)
classmethod
¶
Returns a State vector in the ground state |00..0>.
| PARAMETER | DESCRIPTION |
|---|---|
num_sites
|
the number of qubits
TYPE:
|
gpu
|
whether gpu or cpu
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
StateVector
|
The described state |
Examples:
Output:
Source code in emu_sv/state_vector.py
norm()
¶
Returns the norm of the state
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
the norm of the state |
sample(*, num_shots=1000, one_state=None, p_false_pos=0.0, p_false_neg=0.0)
¶
Samples bitstrings, taking into account the specified error rates.
| PARAMETER | DESCRIPTION |
|---|---|
num_shots
|
how many bitstrings to sample
TYPE:
|
p_false_pos
|
the rate at which a 0 is read as a 1
TYPE:
|
p_false_neg
|
teh rate at which a 1 is read as a 0
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Counter[str]
|
the measured bitstrings, by count |
Source code in emu_sv/state_vector.py
zero(num_sites, gpu=True, eigenstates=('r', 'g'))
classmethod
¶
Returns a zero uninitialized "state" vector. Warning, this has no physical meaning as-is!
| PARAMETER | DESCRIPTION |
|---|---|
num_sites
|
the number of qubits
TYPE:
|
gpu
|
whether gpu or cpu
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
StateVector
|
The zero state |
Examples:
Output:
Source code in emu_sv/state_vector.py
inner¶
Wrapper around StateVector.inner.
| PARAMETER | DESCRIPTION |
|---|---|
left
|
StateVector argument
TYPE:
|
right
|
StateVector argument
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
the inner product |
Examples:
factor = math.sqrt(2.0)
basis = ("r","g")
nqubits=2
string_state1 = {"gg":1.0,"rr":1.0}
state1 = StateVector.from_state_string(basis=basis,
nqubits=nqubits,strings=string_state1)
string_state2 = {"gr":1.0/factor,"rr":1.0/factor}
state2 = StateVector.from_state_string(basis=basis,
nqubits=nqubits,strings=string_state2)
state1 = StateVector.from_state_amplitudes(eigenstates=basis,
amplitudes=string_state1)
string_state2 = {"gr":1.0/factor,"rr":1.0/factor}
state2 = StateVector.from_state_amplitudes(eigenstates=basis,
amplitudes=string_state2)
inner(state1,state2).item()
Output:
Source code in emu_sv/state_vector.py
DenseOperator¶
Bases: Operator[complex, Tensor, StateVector]
DenseOperator in emu-sv uses dense matrices. This class represents a quantum operator backed by a dense PyTorch tensor for state-vector simulation.
| PARAMETER | DESCRIPTION |
|---|---|
matrix
|
Square complex tensor of shape (2ⁿ, 2ⁿ) representing the operator in the computational basis.
TYPE:
|
gpu
|
If True, place the operator on a CUDA device when available. Default: True (and only 1 GPU).
TYPE:
|
Source code in emu_sv/dense_operator.py
__add__(other)
¶
Element-wise addition of two DenseOperators.
| PARAMETER | DESCRIPTION |
|---|---|
other
|
a DenseOperator instance.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
DenseOperator
|
A new DenseOperator representing the sum. |
Source code in emu_sv/dense_operator.py
__matmul__(other)
¶
Compose two DenseOperators via matrix multiplication.
| PARAMETER | DESCRIPTION |
|---|---|
other
|
a DenseOperator instance.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
DenseOperator
|
A new DenseOperator representing the product |
Source code in emu_sv/dense_operator.py
__rmul__(scalar)
¶
Scalar multiplication of the DenseOperator.
| PARAMETER | DESCRIPTION |
|---|---|
scalar
|
a number to scale the operator.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
DenseOperator
|
A new DenseOperator scaled by the given scalar. |
Source code in emu_sv/dense_operator.py
apply_to(other)
¶
Apply the DenseOperator to a given StateVector.
| PARAMETER | DESCRIPTION |
|---|---|
other
|
a StateVector instance.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
StateVector
|
A new StateVector after applying the operator. |
Source code in emu_sv/dense_operator.py
expect(state)
¶
Compute the expectation value of the operator with respect to a state.
| PARAMETER | DESCRIPTION |
|---|---|
state
|
a StateVector instance.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
The expectation value as a float or complex number. |
Source code in emu_sv/dense_operator.py
SparseOperator¶
Bases: Operator[complex, Tensor, StateVector]
This operator is used to represent a sparse matrix in CSR (Compressed Sparse Row) format for efficient computation on the emu-sv emulator
| PARAMETER | DESCRIPTION |
|---|---|
matrix
|
The CSR matrix representation of the operator.
TYPE:
|
gpu
|
If True (by default), run on GPU when available; otherwise fall back to CPU. If False, always run on CPU.
TYPE:
|
Source code in emu_sv/sparse_operator.py
__add__(other)
¶
Element-wise addition of two SparseOperators.
| PARAMETER | DESCRIPTION |
|---|---|
other
|
a SparseOperator instance.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
SparseOperator
|
A new SparseOperator representing the sum. |
Source code in emu_sv/sparse_operator.py
__deepcopy__(memo)
¶
torch CSR tensor does not deepcopy automatically
__matmul__(other)
¶
Compose two SparseOperators via matrix multiplication.
| PARAMETER | DESCRIPTION |
|---|---|
other
|
a SparseOperator instance.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
SparseOperator
|
A new SparseOperator representing the product |
Source code in emu_sv/sparse_operator.py
__rmul__(scalar)
¶
Scalar multiplication of the SparseOperator.
| PARAMETER | DESCRIPTION |
|---|---|
scalar
|
a number to scale the operator.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
SparseOperator
|
A new SparseOperator scaled by the given scalar. |
Source code in emu_sv/sparse_operator.py
apply_to(other)
¶
Apply the SparseOperator to a given StateVector.
| PARAMETER | DESCRIPTION |
|---|---|
other
|
a StateVector instance.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
StateVector
|
A new StateVector after applying the operator. |
Source code in emu_sv/sparse_operator.py
expect(state)
¶
Compute the expectation value of the operator with respect to a state.
| PARAMETER | DESCRIPTION |
|---|---|
state
|
a StateVector instance.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
The expectation value as a float or complex number. |
Source code in emu_sv/sparse_operator.py
DensityMatrix¶
Bases: State[complex, Tensor]
Represents an n-qubit density matrix ρ in the computational (|g⟩, |r⟩) basis. The input should be a square complex tensor with shape (2ⁿ, 2ⁿ), where n is the number of atoms. ρ must be Hermitian, positive semidefinite, and has trace 1. These checks are too expensive to actually perform, so it's up to the user to ensure these constraints are met.
| PARAMETER | DESCRIPTION |
|---|---|
matrix
|
Square complex tensor of shape (2ⁿ, 2ⁿ), Hermitian with trace 1, that represents the state in the computational basis.
TYPE:
|
gpu
|
If True, place the operator on a CUDA device when available. Default: True.
TYPE:
|
Source code in emu_sv/density_matrix_state.py
n_qudits
property
¶
The number of qudits in the state.
from_state_vector(state)
classmethod
¶
Convert a state vector to a density matrix. This function takes a state vector |ψ❭ and returns the corresponding density matrix ρ = |ψ❭❬ψ| representing the pure state |ψ❭.
Examples:
bell_state_vec = 0.7071 * torch.tensor([1.0, 0.0, 0.0, 1.0j],
dtype=torch.complex128)
bell_state = StateVector(bell_state_vec, gpu=False)
density = DensityMatrix.from_state_vector(bell_state)
print(density.data)
Output:
tensor([[0.5000+0.0000j, 0.0000+0.0000j, 0.0000+0.0000j, 0.0000-0.5000j],
[0.0000+0.0000j, 0.0000+0.0000j, 0.0000+0.0000j, 0.0000+0.0000j],
[0.0000+0.0000j, 0.0000+0.0000j, 0.0000+0.0000j, 0.0000+0.0000j],
[0.0000+0.5000j, 0.0000+0.0000j, 0.0000+0.0000j, 0.5000+0.0000j]],
dtype=torch.complex128)
Source code in emu_sv/density_matrix_state.py
make(n_atoms, gpu=True)
classmethod
¶
Creates the density matrix of the ground state |000...0>
Source code in emu_sv/density_matrix_state.py
norm()
¶
Returns the norm of the state
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
the norm of the state |
overlap(other)
¶
Compute Tr(self^† @ other). The type of other must be DensityMatrix.
| PARAMETER | DESCRIPTION |
|---|---|
other
|
the other state
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
the inner product |
Examples:
density_bell_state = 0.5 * torch.tensor([[1, 0, 0, 1], [0, 0, 0, 0],
[0, 0, 0, 0], [1, 0, 0, 1]],dtype=torch.complex128)
density_c = DensityMatrix(density_bell_state, gpu=False)
density_c.overlap(density_c)
Output:
Source code in emu_sv/density_matrix_state.py
sample(num_shots=1000, one_state=None, p_false_pos=0.0, p_false_neg=0.0)
¶
Samples bitstrings, taking into account the specified error rates.
| PARAMETER | DESCRIPTION |
|---|---|
num_shots
|
how many bitstrings to sample
TYPE:
|
p_false_pos
|
the rate at which a 0 is read as a 1
TYPE:
|
p_false_neg
|
teh rate at which a 1 is read as a 0
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Counter[str]
|
the measured bitstrings, by count |
Examples:
torch.manual_seed(1234)
from emu_sv import StateVector
bell_vec = 0.7071 * torch.tensor([1.0, 0.0, 0.0, 1.0j],
dtype=torch.complex128)
bell_state_vec = StateVector(bell_vec)
bell_density = DensityMatrix.from_state_vector(bell_state_vec)
bell_density.sample(1000)
Output: