API specification
The emu-sv API is based on the specification here. Concretely, the classes are as follows:
SVBackend
Bases: Backend
A backend for emulating Pulser sequences using state vectors and sparse matrices.
run(sequence, sv_config)
Emulates the given sequence.
PARAMETER | DESCRIPTION |
---|---|
sequence
|
a Pulser sequence to simulate
TYPE:
|
sv_config
|
the backends config. Should be of type SVConfig
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Results
|
the simulation results |
Source code in emu_sv/sv_backend.py
SVConfig
Bases: BackendConfig
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 |
---|---|
initial_state
|
the initial state to use in the simulation
TYPE:
|
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
|
Use 1 gpu if True, and a GPU is available, otherwise, cpu. Will cause errors if True when a gpu is not available
TYPE:
|
kwargs
|
arguments that are passed to the base class
TYPE:
|
Examples:
>>> gpu = True
>>> dt = 1 #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
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.
ATTRIBUTE | DESCRIPTION |
---|---|
vector |
1D tensor representation of a state vector.
|
gpu |
store the vector on GPU if True, otherwise on CPU
|
Source code in emu_sv/state_vector.py
__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 |
from_state_string(*, basis, nqubits, strings, **kwargs)
staticmethod
Transforms a state given by a string into a state vector.
Construct a state from the pulser abstract representation https://pulser.readthedocs.io/en/stable/conventions.html
PARAMETER | DESCRIPTION |
---|---|
basis
|
A tuple containing the basis states (e.g., ('r', 'g')).
TYPE:
|
nqubits
|
the number of qubits.
TYPE:
|
strings
|
A dictionary mapping state strings to complex or floats amplitudes.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
StateVector
|
The resulting state. |
Examples:
>>> basis = ("r","g")
>>> n = 2
>>> st=StateVector.from_state_string(basis=basis,nqubits=n,strings={"rr":1.0,"gg":1.0})
>>> print(st)
tensor([0.7071+0.j, 0.0000+0.j, 0.0000+0.j, 0.7071+0.j], dtype=torch.complex128)
Source code in emu_sv/state_vector.py
inner(other)
Compute
PARAMETER | DESCRIPTION |
---|---|
other
|
the other state
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
float | complex
|
the inner product |
Source code in emu_sv/state_vector.py
make(num_sites, gpu=True)
classmethod
Returns a State vector in ground state |000..0>. The vector in the output of StateVector has the shape (2,)*number of qubits
PARAMETER | DESCRIPTION |
---|---|
num_sites
|
the number of qubits
TYPE:
|
gpu
|
whether gpu or cpu
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
StateVector
|
The described state |
Examples:
Source code in emu_sv/state_vector.py
norm()
Returns the norm of the state
RETURNS | DESCRIPTION |
---|---|
float | complex
|
the norm of the state |
sample(num_shots=1000, 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)
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:
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)
>>> inner(state1,state2).item()
(0.4999999999999999+0j)
Source code in emu_sv/state_vector.py
DenseOperator
Bases: Operator
Operators in EMU-SV are dense matrices
Source code in emu_sv/dense_operator.py
__add__(other)
Returns the sum of two matrices
PARAMETER | DESCRIPTION |
---|---|
other
|
the other operator
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
DenseOperator
|
the summed operator |
Source code in emu_sv/dense_operator.py
__matmul__(other)
Apply this operator to a other. The ordering is that self is applied after other.
PARAMETER | DESCRIPTION |
---|---|
other
|
the operator to compose with self
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
DenseOperator
|
the composed operator |
Source code in emu_sv/dense_operator.py
__mul__(other)
Applies this DenseOperator to the given StateVector.
PARAMETER | DESCRIPTION |
---|---|
other
|
the state to apply this operator to
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
StateVector
|
the resulting state |
Source code in emu_sv/dense_operator.py
__rmul__(scalar)
Multiply a DenseOperator by scalar.
PARAMETER | DESCRIPTION |
---|---|
scalar
|
the scale factor to multiply with
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
DenseOperator
|
the scaled MPO |
expect(state)
Compute the expectation value of self on the given state.
PARAMETER | DESCRIPTION |
---|---|
state
|
the state with which to compute
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
float | complex
|
the expectation |
Source code in emu_sv/dense_operator.py
from_operator_string(basis, nqubits, operations, operators={}, /, **kwargs)
staticmethod
See the base class
PARAMETER | DESCRIPTION |
---|---|
basis
|
the eigenstates in the basis to use e.g. ('r', 'g')
TYPE:
|
nqubits
|
how many qubits there are in the state
TYPE:
|
operations
|
which bitstrings make up the state with what weight
TYPE:
|
operators
|
additional symbols to be used in operations
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
DenseOperator
|
the operator in MPO form. |
Source code in emu_sv/dense_operator.py
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 |
|