Base classes
Backend
Bases: ABC
Base class for different emulation backends. Forces backends to implement a run method.
run(sequence, config)
abstractmethod
Emulates the given sequence.
PARAMETER | DESCRIPTION |
---|---|
sequence
|
a Pulser sequence to simulate
TYPE:
|
config
|
the config. Should be of the appropriate type for the backend
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Results
|
the simulation results |
Source code in emu_base/base_classes/backend.py
BackendConfig
The base backend configuration.
PARAMETER | DESCRIPTION |
---|---|
observables
|
a list of callbacks to compute observables
TYPE:
|
with_modulation
|
if True, run the sequence with hardware modulation
TYPE:
|
noise_model
|
The pulser.NoiseModel to use in the simulation.
TYPE:
|
interaction_matrix
|
When specified, override the interaction terms in the Hamiltonian. This corresponds to the \(U_{ij}\) terms in the documentation. Must be symmetric.
TYPE:
|
interaction_cutoff
|
set interaction coefficients smaller than this to 0. This can improve the memory profile of the application for some backends.
TYPE:
|
log_level
|
The output verbosity. Should be one of the constants from logging.
TYPE:
|
log_file
|
a path to a file where to store the log, instead of printing to stdout
TYPE:
|
Examples:
>>> observables = [BitStrings(400, 100)] #compute 100 bitstrings at 400ns
>>> noise_model = pulser.noise_model.NoiseModel()
>>> interaction_matrix = [[1 for _ in range(nqubits)] for _ in range(nqubits)]
>>> interaction_cutoff = 2.0 #this will turn off all the above interactions again
>>> log_level = logging.warn
Source code in emu_base/base_classes/config.py
Results
This class contains emulation results. Since the results written by an emulator are defined through callbacks, the contents of this class are not known a-priori.
get_result(name, time)
get the given result at the given time
PARAMETER | DESCRIPTION |
---|---|
name
|
name of the result to get
TYPE:
|
time
|
time in ns at which to get the result
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Any
|
the result |
Source code in emu_base/base_classes/results.py
get_result_names()
get a list of results present in this object
Args:
RETURNS | DESCRIPTION |
---|---|
list[str]
|
list of results by name |
get_result_times(name)
get a list of times for which the given result has been stored
PARAMETER | DESCRIPTION |
---|---|
name
|
name of the result to get times of
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
list[int]
|
list of times in ns |
Source code in emu_base/base_classes/results.py
State
Bases: ABC
Base class enforcing an API for quantum states. Each backend will implement its own type of state, and the below methods.
__add__(other)
abstractmethod
Computes the sum of two states.
PARAMETER | DESCRIPTION |
---|---|
other
|
the other state
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
State
|
the summed state |
__rmul__(scalar)
abstractmethod
Scale the state by a scale factor.
PARAMETER | DESCRIPTION |
---|---|
scalar
|
the scale factor
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
State
|
the scaled state |
from_state_string(*, basis, nqubits, strings, **kwargs)
abstractmethod
staticmethod
Construct a state from the pulser abstract representation https://www.notion.so/pasqal/Abstract-State-and-Operator-Definition For a list of existing bases, see https://pulser.readthedocs.io/en/stable/conventions.html
PARAMETER | DESCRIPTION |
---|---|
basis
|
A tuple containing the basis states.
TYPE:
|
nqubits
|
the number of qubits.
TYPE:
|
strings
|
A dictionary mapping state strings to complex or floats amplitudes
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
State
|
the state in whatever format the backend provides. |
Examples:
>>> afm_string_state = {"rrr": 1.0 / math.sqrt(2), "ggg": 1.0 / math.sqrt(2)}
>>> afm_state = State.from_state_string(
>>> basis=("r", "g"), nqubits=3, strings=afm_string_state
>>> )
Source code in emu_base/base_classes/state.py
inner(other)
abstractmethod
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 |
---|---|
float | complex
|
inner product |
Source code in emu_base/base_classes/state.py
sample(num_shots, p_false_pos=0.0, p_false_neg=0.0)
abstractmethod
Sample bitstrings from the state, taking into account 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_base/base_classes/state.py
Operator
Bases: ABC
__add__(other)
abstractmethod
Computes the sum of two operators.
PARAMETER | DESCRIPTION |
---|---|
other
|
the other operator
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Operator
|
the summed operator |
__matmul__(other)
abstractmethod
Compose two operators. The ordering is that self is applied after other.
PARAMETER | DESCRIPTION |
---|---|
other
|
the operator to compose with self
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Operator
|
the composed operator |
Source code in emu_base/base_classes/operator.py
__mul__(other)
abstractmethod
Apply the operator to a state
PARAMETER | DESCRIPTION |
---|---|
other
|
the state to apply this operator to
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
State
|
the resulting state |
__rmul__(scalar)
abstractmethod
Scale the operator by a scale factor.
PARAMETER | DESCRIPTION |
---|---|
scalar
|
the scale factor
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Operator
|
the scaled operator |
expect(state)
abstractmethod
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 |
from_operator_string(basis, nqubits, operations, operators={}, /, **kwargs)
abstractmethod
staticmethod
Create an operator in the backend-specific format from the pulser abstract representation https://www.notion.so/pasqal/Abstract-State-and-Operator-Definition By default it supports strings 'ij', where i and j in basis, to denote |i><j|, but additional symbols can be defined in operators For a list of existing bases, see https://pulser.readthedocs.io/en/stable/conventions.html
PARAMETER | DESCRIPTION |
---|---|
basis
|
the eigenstates in the basis to use
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 |
---|---|
Operator
|
the operator in whatever format the backend provides. |
Examples:
>>> basis = {"r", "g"} #rydberg basis
>>> nqubits = 3 #or whatever
>>> x = {"rg": 1.0, "gr": 1.0}
>>> z = {"gg": 1.0, "rr": -1.0}
>>> operators = {"X": x, "Z": z} #define X and Z as conveniences
>>>
>>> operations = [ # 4 X1X + 3 1Z1
>>> (
>>> 1.0,
>>> [
>>> ({"X": 2.0}, [0, 2]),
>>> ({"Z": 3.0}, [1]),
>>> ],
>>> )
>>> ]
>>> op = Operator.from_operator_string(basis, nqubits, operations, operators)
Source code in emu_base/base_classes/operator.py
Callback
Bases: ABC
The callback base class that can be subclassed to add new kinds of results to the Results object returned by the Backend
PARAMETER | DESCRIPTION |
---|---|
evaluation_times
|
the times at which to add a result to Results
TYPE:
|
Source code in emu_base/base_classes/callback.py
default_aggregation_type
property
Defines how to combine by default multiple values from different simulation results. None means no default, therefore aggregator function is always user-provided.
name
abstractmethod
property
The name of the observable, can be used to index into the Results object. Some Callbacks might have multiple instances, such as a callback to compute a fidelity on some given state. In that case, this method could make sure each instance has a unique name.
RETURNS | DESCRIPTION |
---|---|
str
|
the name of the callback |
__call__(config, t, state, H, result)
This function is called after each time step performed by the emulator.
By default it calls apply to compute a result and put it in result
if t
in self.evaluation_times
.
It can be overloaded to define any custom behaviour for a Callback
.
PARAMETER | DESCRIPTION |
---|---|
config
|
the config object passed to the run method
TYPE:
|
t
|
the current time in ns
TYPE:
|
state
|
the current state
TYPE:
|
H
|
the Hamiltonian at this time
TYPE:
|
result
|
the results object
TYPE:
|
Source code in emu_base/base_classes/callback.py
apply(config, t, state, H)
abstractmethod
This method must be implemented by subclasses. The result of this method gets put in the Results object.
PARAMETER | DESCRIPTION |
---|---|
config
|
the config object passed to the run method
TYPE:
|
t
|
the current time in ns
TYPE:
|
state
|
the current state
TYPE:
|
H
|
the Hamiltonian at this time
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Any
|
the result to put in Results |