API specification¶
The emu-mps API is based on the specification here. Additionally, some observables are implemented specifically for emu-mps.
The implementation of the base classes is as follows:
MPSBackend¶
Bases: EmulatorBackend
A backend for emulating Pulser sequences using Matrix Product States (MPS), aka tensor trains.
| PARAMETER | DESCRIPTION |
|---|---|
config
|
Configuration for the MPS backend.
TYPE:
|
Source code in pulser/backend/abc.py
resume(autosave_file)
staticmethod
¶
Resume simulation from autosave file. Only resume simulations from data you trust! Unpickling of untrusted data is not safe.
Source code in emu_mps/mps_backend.py
run()
¶
Emulates the given sequence.
| RETURNS | DESCRIPTION |
|---|---|
Results
|
the simulation results |
Source code in emu_mps/mps_backend.py
MPSConfig¶
Bases: EmulationConfig
The configuration of the emu-mps MPSBackend. 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:
|
precision
|
Up to what precision the state is truncated.
Defaults to
TYPE:
|
max_bond_dim
|
The maximum bond dimension that the state is allowed
to have.
Defaults to
TYPE:
|
max_krylov_dim
|
The size of the krylov subspace that the Lanczos algorithm maximally builds
TYPE:
|
extra_krylov_tolerance
|
The Lanczos algorithm uses this*precision as the convergence tolerance
TYPE:
|
num_gpus_to_use
|
number of GPUs to be used in a given simulation.
- if it is set to a number
TYPE:
|
optimize_qubit_ordering
|
Optimize the register ordering. Improves performance and accuracy, but disables certain features.
TYPE:
|
interaction_cutoff
|
Set interaction coefficients Uᵢⱼ 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:
|
autosave_prefix
|
filename prefix for autosaving simulation state to file
TYPE:
|
autosave_dt
|
Minimum time interval in seconds between two autosaves. Saving the simulation state is only possible at specific times, therefore this interval is only a lower bound.
TYPE:
|
solver
|
Chooses the solver algorithm to run a sequence.
Two options are currently available:
TYPE:
|
kwargs
|
Arguments that are passed to the base class
TYPE:
|
Examples:
num_gpus_to_use = 2 #use 2 gpus if available, otherwise 1 or cpu
dt = 1.0 #this will impact the runtime
precision = 1e-6 #smaller dt requires better precision, generally
MPSConfig(num_gpus_to_use=num_gpus_to_use, dt=dt, precision=precision,
with_modulation=True) #the last arg is taken from the base class
Source code in emu_mps/mps_config.py
Solvers¶
Bases: str, Enum
Available MPS solvers used by emu-mps. Use these values to
select the algorithm for time evolution.
By defatult TDVP is used. In order to use DMRG, set the
solver argument of MPSConfig to "dmrg" or Solver.DMRG.
Args:
- Solver.TDVP: Time-Dependent Variational Principle solver.
- Solver.DMRG: Density Matrix Renormalization Group solver.
MPS¶
Bases: State[complex, Tensor]
Matrix Product State, a.k.a tensor train. Each tensor has 3 dimensions ordered as such: (left bond, site, right bond). Only qubits and qutrits (using the leakage state: 'x') are supported. This constructor creates a MPS directly from a list of tensors.
| PARAMETER | DESCRIPTION |
|---|---|
factors
|
the tensors for each site. WARNING: for efficiency, this list of tensors IS NOT DEEP-COPIED. Therefore, the new MPS object is not necessarily the exclusive owner of the list and its tensors. As a consequence, beware of potential external modifications affecting the list or the tensors. You are responsible for deciding whether to pass its own exclusive copy of the data to this constructor, or some shared objects.
TYPE:
|
orthogonality_center
|
the orthogonality center of the MPS, or None (in which case it will be orthogonalized when needed)
TYPE:
|
precision
|
the threshold for truncating singular values during SVD operations. Any singular value below this threshold will be discarded, effectively reducing the bond dimension and improving computational efficiency. Check precision in config
TYPE:
|
max_bond_dim
|
the maximum bond dimension to allow for this MPS
TYPE:
|
num_gpus_to_use
|
number of GPUs to use for placing MPS factors. - If set to 0, all factors are placed on CPU. - If set to None, factors retain their current device assignment. - Otherwise, factors are distributed across the specified number of GPUs.
TYPE:
|
eigenstates
|
the basis states for each qudit (['0','1'] or ['r','g']) or qutrit ['g','r','x'], where 'x' is the leakage state (default: ['0','1'])
TYPE:
|
Source code in emu_mps/mps.py
n_qudits
property
¶
The number of qudits in the state.
__add__(other)
¶
Returns the sum of two MPSs, computed with a direct algorithm.
The resulting MPS is orthogonalized on the first site and truncated
up to self.config.precision.
| PARAMETER | DESCRIPTION |
|---|---|
other
|
the other state
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
MPS
|
the summed state |
Source code in emu_mps/mps.py
__rmul__(scalar)
¶
Multiply an MPS by a scalar.
| PARAMETER | DESCRIPTION |
|---|---|
scalar
|
the scale factor
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
MPS
|
the scaled MPS |
Source code in emu_mps/mps.py
apply(qubit_index, single_qubit_operator)
¶
Apply given single qubit operator to qubit qubit_index, leaving the MPS orthogonalized on that qubit.
Source code in emu_mps/mps.py
entanglement_entropy(mps_site)
¶
Returns
the Von Neumann entanglement entropy of the state mps at the bond
between sites b and b+1
S = -Σᵢsᵢ² log(sᵢ²)),
where sᵢ are the singular values at the chosen bond.
Source code in emu_mps/mps.py
expect_batch(single_qubit_operators)
¶
Computes expectation values for each qubit and each single qubit operator in the batched input tensor.
Returns a tensor T such that T[q, i] is the expectation value for qubit #q and operator single_qubit_operators[i].
Source code in emu_mps/mps.py
get_correlation_matrix(operator=None)
¶
Efficiently compute the symmetric correlation matrix \(C_{ij} = \langle \text{self}|\text{operator}_i \text{operator}_j|\text{self}\rangle\) in basis ("r", "g"), ("0","1"), and ("r","g","x").
| PARAMETER | DESCRIPTION |
|---|---|
operator
|
a 2x2 (or 3x3) Torch tensor to use
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
the corresponding correlation matrix |
Source code in emu_mps/mps.py
get_max_bond_dim()
¶
Return the max bond dimension of this MPS.
| RETURNS | DESCRIPTION |
|---|---|
int
|
the largest bond dimension in the state |
get_memory_footprint()
¶
Returns the number of MBs of memory occupied to store the state
| RETURNS | DESCRIPTION |
|---|---|
float
|
the memory in MBs |
Source code in emu_mps/mps.py
inner(other)
¶
Compute the inner product between this state and other. Note that self is the left state in the inner product, so this function is linear in other, and anti-linear in self
| PARAMETER | DESCRIPTION |
|---|---|
other
|
the other state
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
inner product |
Source code in emu_mps/mps.py
make(num_sites, precision=DEFAULT_PRECISION, max_bond_dim=DEFAULT_MAX_BOND_DIM, num_gpus_to_use=DEVICE_COUNT, eigenstates=['0', '1'])
classmethod
¶
Returns a MPS in ground state |000..0>.
| PARAMETER | DESCRIPTION |
|---|---|
num_sites
|
the number of qubits
TYPE:
|
precision
|
the precision with which to keep this MPS
TYPE:
|
max_bond_dim
|
the maximum bond dimension to allow for this MPS
TYPE:
|
num_gpus_to_use
|
distribute the factors over this many GPUs 0=all factors to cpu
TYPE:
|
Source code in emu_mps/mps.py
norm()
¶
Computes the norm of the MPS.
Source code in emu_mps/mps.py
orthogonalize(desired_orthogonality_center=0)
¶
Orthogonalize the state on the given orthogonality center.
Returns the new orthogonality center index as an integer, this is convenient for type-checking purposes.
Source code in emu_mps/mps.py
overlap(other)
¶
Compute the overlap of this state and other. This is defined as \(|\langle self | other \rangle |^2\)
sample(*, num_shots, 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
|
the rate at which a 1 is read as a 0
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Counter[str]
|
the measured bitstrings, by count |
Source code in emu_mps/mps.py
truncate()
¶
SVD based truncation of the state. Puts the orthogonality center at the first qubit. Calls orthogonalize on the last qubit, and then sweeps a series of SVDs right-left. Uses self.config for determining accuracy. An in-place operation.
Source code in emu_mps/mps.py
inner¶
Computes the inner product ⟨left|right⟩ between two MPS states (convenience wrapper for MPS.inner). Both MPS must have the same number of sites and the same local (physical) dimension at each site.
| PARAMETER | DESCRIPTION |
|---|---|
left
|
Left state (conjugated in the inner product).
TYPE:
|
right
|
Right state (not conjugated).
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
A scalar torch.Tensor equal to ⟨left|right⟩ (typically complex-valued). Use result.item() to convert to a Python number. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the MPS are incompatible (e.g., different lengths or dimensions). |
RuntimeError
|
If tensors are on incompatible devices/dtypes (as raised by PyTorch). |
Source code in emu_mps/mps.py
MPO¶
Bases: Operator[complex, Tensor, MPS]
Matrix Product Operator.
Each tensor is 4 dimensions with axes ordered as (left_bond, phys_out, phys_in, right_bond). When contracting an MPO with an MPS as H|ψ⟩, phys_in contracts with the MPS physical index, while phys_out becomes the physical index of the resulting MPS.
| PARAMETER | DESCRIPTION |
|---|---|
factors
|
List of 4D tensors with shape (Dl, d_out, d_in, Dr). Neighboring tensors must satisfy Dr[i] == Dl[i+1].
TYPE:
|
num_gpus_to_use
|
Number of GPUs to use for placing MPO factors (implementation-dependent placement). If None, uses all available GPUs.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
MPO
|
A matrix product operator constructed from the provided factors. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If any factor is not 4D or if neighboring bond dimensions do not match. |
RuntimeError
|
If requested GPUs are not available. |
Source code in emu_mps/mpo.py
__add__(other)
¶
Returns the sum of two MPOs, computed with a direct algorithm. The result is currently not truncated
| PARAMETER | DESCRIPTION |
|---|---|
other
|
the other operator
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
MPO
|
the summed operator |
Source code in emu_mps/mpo.py
__matmul__(other)
¶
Compose two operators. The ordering is that self is applied after other.
| PARAMETER | DESCRIPTION |
|---|---|
other
|
the operator to compose with self
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
MPO
|
the composed operator |
Source code in emu_mps/mpo.py
__rmul__(scalar)
¶
Multiply an MPO by scalar. Assumes the orthogonal centre is on the first factor.
| PARAMETER | DESCRIPTION |
|---|---|
scalar
|
the scale factor to multiply with
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
MPO
|
the scaled MPO |
Source code in emu_mps/mpo.py
apply_to(other)
¶
Applies this MPO to the given MPS. The returned MPS is:
- othogonal on the first site
- truncated up to `other.precision`
- distributed on the same devices of `other`
| PARAMETER | DESCRIPTION |
|---|---|
other
|
the state to apply this operator to
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
MPS
|
the resulting state |
Source code in emu_mps/mpo.py
expect(state)
¶
Compute the expectation value of self on the given state.
| PARAMETER | DESCRIPTION |
|---|---|
state
|
the state with which to compute
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
the expectation |
Source code in emu_mps/mpo.py
The following observables are defined specifically in emu-mps:
Entanglement Entropy¶
Bases: Observable
Entanglement Entropy of the state partition at qubit mps_site.
| PARAMETER | DESCRIPTION |
|---|---|
mps_site
|
the qubit index at which the bipartition is made.
All qubits with index \(\leq\)
TYPE:
|
evaluation_times
|
The relative times at which to store the state.
If left as
TYPE:
|
tag_suffix
|
An optional suffix to append to the tag. Needed if multiple instances of the same observable are given to the same EmulationConfig.
TYPE:
|