Classical Simulation
Since version 0.6.0, all simulation classes (previously under the pulser.simulation
module)
are in the pulser-simulation
extension and should be imported from pulser_simulation
.
QutipEmulator
QutipEmulator
is the class to simulate SequenceSamples
, that are samples of a Sequence
.
It is possible to simulate directly a Sequence
object by using the class method
QutipEmulator.from_sequence
. Since version 0.14.0, the Simulation
class is deprecated
in favour of QutipEmulator
.
- class pulser_simulation.simulation.QutipEmulator(sampled_seq, register, device, sampling_rate=1.0, config=None, evaluation_times='Full')
Emulator of a pulse sequence using QuTiP.
- Parameters:
sampled_seq (
SequenceSamples
) – A pulse sequence samples used in the emulation.register (
BaseRegister
) – The register associating coordinates to the qubits targeted by the pulses within the samples.device (
BaseDevice
) – The device specifications used in the emulation. Register and samples have to satisfy its constraints.sampling_rate (
float
, default:1.0
) – The fraction of samples that we wish to extract from the samples to simulate. Has to be a value between 0.05 and 1.0.config (
Optional
[SimConfig
], default:None
) – Configuration to be used for this simulation.evaluation_times (
Union
[float
,str
,_SupportsArray
[dtype
[Any
]],_NestedSequence
[_SupportsArray
[dtype
[Any
]]],bool
,int
,complex
,bytes
,_NestedSequence
[Union
[bool
,int
,float
,complex
,str
,bytes
]]], default:'Full'
) –Choose between:
”Full”: The times are set to be the ones used to define the Hamiltonian to the solver.
”Minimal”: The times are set to only include initial and final times.
An ArrayLike object of times in µs if you wish to only include those specific times.
A float to act as a sampling rate for the resulting state.
- property sampling_times
The times at which hamiltonian is sampled.
- property dim
The dimension of the basis.
- property basis_name
The name of the basis.
- property basis
The basis in which result is expressed.
- property config
The current configuration, as a SimConfig instance.
- set_config(cfg)
Sets current config to cfg and updates simulation parameters.
- Parameters:
cfg (
SimConfig
) – New configuration.- Return type:
None
- add_config(config)
Updates the current configuration with parameters of another one.
Mostly useful when dealing with multiple noise types in different configurations and wanting to merge these configurations together. Adds simulation parameters to noises that weren’t available in the former SimConfig. Noises specified in both SimConfigs will keep former noise parameters.
- Parameters:
config (
SimConfig
) – SimConfig to retrieve parameters from.- Return type:
None
- show_config(solver_options=False)
Shows current configuration.
- Return type:
None
- reset_config()
Resets configuration to default.
- Return type:
None
- property initial_state
The initial state of the simulation.
- set_initial_state(state)
Sets the initial state of the simulation.
- Parameters:
state (
Union
[str
,ndarray
,Qobj
]) –The initial state. Choose between:
”all-ground” for all atoms in ground state
An ArrayLike with a shape compatible with the system
A Qobj object
- Return type:
None
- property evaluation_times
The times at which the results of this simulation are returned.
- set_evaluation_times(value)
Sets times at which the results of this simulation are returned.
- Parameters:
value (
Union
[str
,_SupportsArray
[dtype
[Any
]],_NestedSequence
[_SupportsArray
[dtype
[Any
]]],bool
,int
,float
,complex
,bytes
,_NestedSequence
[Union
[bool
,int
,float
,complex
,str
,bytes
]]]) –Choose between:
”Full”: The times are set to be the ones used to define the Hamiltonian to the solver.
”Minimal”: The times are set to only include initial and final times.
An ArrayLike object of times in µs if you wish to only include those specific times.
A float to act as a sampling rate for the resulting state.
- Return type:
None
- build_operator(operations)
Creates an operator with non-trivial actions on some qubits.
Takes as argument a list of tuples
[(operator_1, qubits_1), (operator_2, qubits_2)...]
. Returns the operator given by the tensor product of {operator_i
applied onqubits_i
} and Id on the rest.(operator, 'global')
returns the sum for allj
of operator applied atqubit_j
and identity elsewhere.Example for 4 qubits:
[(Z, [1, 2]), (Y, [3])]
returns ZZYI and[(X, 'global')]
returns XIII + IXII + IIXI + IIIX- Parameters:
operations (
Union
[list
,tuple
]) – List of tuples (operator, qubits). operator can be aqutip.Quobj
or a string key forself.op_matrix
. qubits is the list on which operator will be applied. The qubits can be passed as their index or their label in the register.- Return type:
Qobj
- Returns:
The final operator.
- get_hamiltonian(time)
Get the Hamiltonian created from the sequence at a fixed time.
- Return type:
Qobj
Note
The whole Hamiltonian is divided by \(\hbar\), so its units are rad/µs.
- Parameters:
time (
float
) – The specific time at which we want to extract the Hamiltonian (in ns).- Returns:
A new Qobj for the Hamiltonian with coefficients extracted from the effective sequence (determined by self.sampling_rate) at the specified time.
- run(progress_bar=False, **options)
Simulates the sequence using QuTiP’s solvers.
Will return NoisyResults if the noise in the SimConfig requires it. Otherwise will return CoherentResults.
- Parameters:
progress_bar (
bool
, default:False
) – If True, the progress bar of QuTiP’s solver will be shown. If None or False, no text appears.options (
Any
) –Used as arguments for qutip.Options(). If specified, will override SimConfig solver_options. If no max_step value is provided, an automatic one is calculated from the Sequence’s schedule (half of the shortest duration among pulses and delays). Refer to the QuTiP docs for an overview of the parameters.
- Return type:
SimulationResults
- draw(draw_phase_area=False, draw_phase_shifts=False, draw_phase_curve=False, fig_name=None, kwargs_savefig={})
Draws the samples of a sequence of operations used for simulation.
- Parameters:
draw_phase_area (bool, default:
False
) – Whether phase and area values need to be shown as text on the plot, defaults to False.draw_phase_shifts (bool, default:
False
) – Whether phase shift and reference information should be added to the plot, defaults to False.draw_phase_curve (bool, default:
False
) – Draws the changes in phase in its own curve (ignored if the phase doesn’t change throughout the channel).fig_name (str | None, default:
None
) – The name on which to save the figure. If None the figure will not be saved.kwargs_savefig (dict, default:
{}
) – Keywords arguments formatplotlib.pyplot.savefig
. Not applicable if fig_name isNone
.
- Return type:
None
See also
Sequence.draw(): Draws the sequence in its current state.
- classmethod from_sequence(sequence, sampling_rate=1.0, config=None, evaluation_times='Full', with_modulation=False)
Simulation of a pulse sequence using QuTiP.
- Parameters:
sequence (
Sequence
) – An instance of a Pulser Sequence that we want to simulate.sampling_rate (
float
, default:1.0
) – The fraction of samples that we wish to extract from the pulse sequence to simulate. Has to be a value between 0.05 and 1.0.config (
Optional
[SimConfig
], default:None
) – Configuration to be used for this simulation.evaluation_times (
Union
[float
,str
,_SupportsArray
[dtype
[Any
]],_NestedSequence
[_SupportsArray
[dtype
[Any
]]],bool
,int
,complex
,bytes
,_NestedSequence
[Union
[bool
,int
,float
,complex
,str
,bytes
]]], default:'Full'
) –Choose between:
”Full”: The times are set to be the ones used to define the Hamiltonian to the solver.
”Minimal”: The times are set to only include initial and final times.
An ArrayLike object of times in µs if you wish to only include those specific times.
A float to act as a sampling rate for the resulting state.
with_modulation (
bool
, default:False
) – Whether to simulate the sequence with the programmed input or the expected output.
- Return type:
- class pulser_simulation.simulation.Simulation(sequence, sampling_rate=1.0, config=None, evaluation_times='Full', with_modulation=False)
Simulation of a pulse sequence using QuTiP.
Warning
This class is deprecated in favour of
QutipEmulator.from_sequence
.- Parameters:
sequence (
Sequence
) – An instance of a Pulser Sequence that we want to simulate.sampling_rate (
float
, default:1.0
) – The fraction of samples that we wish to extract from the pulse sequence to simulate. Has to be a value between 0.05 and 1.0.config (
Optional
[SimConfig
], default:None
) – Configuration to be used for this simulation.evaluation_times (
Union
[float
,str
,_SupportsArray
[dtype
[Any
]],_NestedSequence
[_SupportsArray
[dtype
[Any
]]],bool
,int
,complex
,bytes
,_NestedSequence
[Union
[bool
,int
,float
,complex
,str
,bytes
]]], default:'Full'
) –Choose between:
”Full”: The times are set to be the ones used to define the Hamiltonian to the solver.
”Minimal”: The times are set to only include initial and final times.
An ArrayLike object of times in µs if you wish to only include those specific times.
A float to act as a sampling rate for the resulting state.
with_modulation (
bool
, default:False
) – Whether to simulated the sequence with the programmed input or the expected output.
SimConfig
Contains the SimConfig class that sets the configuration of a simulation.
- pulser_simulation.simconfig.doppler_sigma(temperature)
Standard deviation for Doppler shifting due to thermal motion.
- Arg:
temperature: The temperature in K.
- Return type:
float
- class pulser_simulation.simconfig.SimConfig(noise=(), runs=15, samples_per_run=5, temperature=50.0, laser_waist=175.0, amp_sigma=0.05, eta=0.005, epsilon=0.01, epsilon_prime=0.05, dephasing_rate=0.05, depolarizing_rate=0.05, eff_noise_rates=<factory>, eff_noise_opers=<factory>, solver_options=None, dephasing_prob=None, depolarizing_prob=None, eff_noise_probs=<factory>)
Specifies a simulation’s configuration.
Note
Being a frozen dataclass, the configuration chosen upon instantiation cannot be changed later on.
- Parameters:
noise (Union[NOISE_TYPES, tuple[NOISE_TYPES, …]], default:
()
) –Types of noises to be used in the simulation. You may specify just one, or a tuple of the allowed noise types:
”dephasing”: Random phase (Z) flip.
”depolarizing”: Quantum noise where the state (rho) is turned into a mixed state I/2 at a rate gamma (in rad/µs).
”eff_noise”: General effective noise channel defined by the set of collapse operators eff_noise_opers and the corresponding rates eff_noise_rates (in rad/µs).
”doppler”: Local atom detuning due to finite speed of the atoms and Doppler effect with respect to laser frequency.
”amplitude”: Gaussian damping due to finite laser waist
”SPAM”: SPAM errors. Defined by eta, epsilon and epsilon_prime.
eta (float, default:
0.005
) – Probability of each atom to be badly prepared.epsilon (float, default:
0.01
) – Probability of false positives.epsilon_prime (float, default:
0.05
) – Probability of false negatives.runs (int, default:
15
) – Number of runs needed : each run draws a new random noise.samples_per_run (int, default:
5
) – Number of samples per noisy run. Useful for cutting down on computing time, but unrealistic.temperature (float, default:
50.0
) – Temperature, set in µK, of the Rydberg array. Also sets the standard deviation of the speed of the atoms.laser_waist (float, default:
175.0
) – Waist of the gaussian laser, set in µm, in global pulses.amp_sigma (float, default:
0.05
) – Dictates the fluctuations in amplitude as a standard deviation of a normal distribution centered in 1.solver_options (Optional[qutip.Options], default:
None
) – Options for the qutip solver.
- classmethod from_noise_model(noise_model)
Creates a SimConfig from a NoiseModel.
- Return type:
TypeVar
(T
, bound= SimConfig)
- to_noise_model()
Creates a NoiseModel from the SimConfig.
- Return type:
NoiseModel
- property spam_dict
A dictionary combining the SPAM error parameters.
- property doppler_sigma
Standard deviation for Doppler shifting due to thermal motion.
- property supported_noises
Return the noises implemented on pulser.
Simulation Results
Depending on the types of noise involved in a simulation, the results are returned
as an instance of SimulationResults
, namely CoherentResults
(when each result can still be represented as a QutipResult
i.e. a state vector
or a density matrix, before being measured) or NoisyResults
(when each of them can only
be represented as SampledResult
i.e. a probability distribution over the basis states).
Both classes feature methods for processing and displaying the results stored within them.
QutipResult
- class pulser_simulation.qutip_result.QutipResult(atom_order, meas_basis, state, matching_meas_basis)
Represents the result of a run as a Qutip QObj.
- Parameters:
atom_order (
tuple
[Union
[int
,str
],...
]) – The order of the atoms in the bitstrings that represent the measured states.meas_basis (
str
) – The measurement basis.state (
Qobj
) – The Qobj representing the state. Can be a statevector or a density matrix.matching_meas_basis (
bool
) – Whether the measurement basis is the same as the state’s basis.
- property sampling_errors
The sampling error associated to each bitstring’s sampling rate.
Uses the standard error of the mean as a quantifier for sampling error.
- get_state(reduce_to_basis=None, ignore_global_phase=True, tol=1e-06, normalize=True)
Gets the state with some optional post-processing.
- Parameters:
reduce_to_basis (str | None, default:
None
) – Reduces the full state vector to the given basis (“ground-rydberg” or “digital”), if the population of the states to be ignored is negligible. Doesn’t apply to XY mode.ignore_global_phase (bool, default:
True
) – If True and if the final state is a vector, changes the final state’s global phase such that the largest term (in absolute value) is real.tol (float, default:
1e-06
) – Maximum allowed population of each eliminated state.normalize (bool, default:
True
) – Whether to normalize the reduced state.
- Return type:
qutip.Qobj
- Returns:
The resulting state.
- Raises:
TypeError – If trying to reduce to a basis that would eliminate states with significant occupation probabilites.
- get_samples(n_samples)
Takes multiple samples from the sampling distribution.
- Parameters:
n_samples (
int
) – Number of samples to return.- Return type:
Counter
[str
]- Returns:
Samples of bitstrings corresponding to measured quantum states.
- plot_histogram(min_rate=0.001, max_n_bitstrings=None, show=True)
Plots the result in an histogram.
- Parameters:
min_rate (float, default:
0.001
) – The minimum sampling rate a bitstring must have to be displayed.max_n_bitstrings (int | None, default:
None
) – An optional limit on the number of bitrstrings displayed.show (bool, default:
True
) – Whether or not to call plt.show() before returning.
- Return type:
None
- property sampling_dist
Sampling distribution of the measured bitstring.
- Parameters:
atom_order – The order of the atoms in the bitstrings that represent the measured states.
meas_basis – The measurement basis.
CoherentResults
- class pulser_simulation.simresults.CoherentResults(run_output, size, basis_name, sim_times, meas_basis, meas_errors=None)
Results of a coherent simulation run of a pulse sequence.
Contains methods for studying the states and extracting useful information from them.
- property states
List of
qutip.Qobj
for each state in the simulation.
- get_state(t, reduce_to_basis=None, ignore_global_phase=True, tol=1e-06, normalize=True, t_tol=0.001)
Get the state at time t of the simulation.
- Parameters:
t (
float
) – Time (µs) at which to return the state.reduce_to_basis (
Optional
[str
], default:None
) – Reduces the full state vector to the given basis (“ground-rydberg” or “digital”), if the population of the states to be ignored is negligible. Doesn’t apply to XY mode.ignore_global_phase (
bool
, default:True
) – If True and if the final state is a vector, changes the final state’s global phase such that the largest term (in absolute value) is real.tol (
float
, default:1e-06
) – Maximum allowed population of each eliminated state.normalize (
bool
, default:True
) – Whether to normalize the reduced state.t_tol (
float
, default:0.001
) – Tolerance for the difference between t and closest time.
- Return type:
Qobj
- Returns:
The resulting state at time t.
- Raises:
TypeError – If trying to reduce to a basis that would eliminate states with significant occupation probabilites.
- get_final_state(reduce_to_basis=None, ignore_global_phase=True, tol=1e-06, normalize=True)
Returns the final state of the Simulation.
- Parameters:
reduce_to_basis (
Optional
[str
], default:None
) – Reduces the full state vector to the given basis (“ground-rydberg” or “digital”), if the population of the states to be ignored is negligible. Doesn’t apply to XY mode.ignore_global_phase (
bool
, default:True
) – If True, changes the final state’s global phase such that the largest term (in absolute value) is real.tol (
float
, default:1e-06
) – Maximum allowed population of each eliminated state.normalize (
bool
, default:True
) – Whether to normalize the reduced state.
- Return type:
Qobj
- Returns:
The resulting final state.
- Raises:
If trying to reduce to a basis that would eliminate states with –
significant occupation probabilites. –
- sample_state(t, n_samples=1000, t_tol=0.001)
Returns the result of multiple measurements at time t.
- Parameters:
t (
float
) – Time at which the state is sampled.n_samples (
int
, default:1000
) – Number of samples to return.t_tol (
float
, default:0.001
) – Tolerance for the difference between t and closest time.
- Return type:
Counter
- Returns:
Sample distribution of bitstrings corresponding to measured quantum states at time t.
- count(value) integer -- return number of occurrences of value
- expect(obs_list)
Returns the expectation values of operators in obs_list.
- Parameters:
obs_list (
Sequence
[Union
[Qobj
,_SupportsArray
[dtype
[Any
]],_NestedSequence
[_SupportsArray
[dtype
[Any
]]],bool
,int
,float
,complex
,str
,bytes
,_NestedSequence
[Union
[bool
,int
,float
,complex
,str
,bytes
]]]]) – Input observable list. ArrayLike objects will be converted to qutip.Qobj.- Return type:
list
[Union
[float
,complex
,_SupportsArray
[dtype
[Any
]],_NestedSequence
[_SupportsArray
[dtype
[Any
]]],bool
,int
,str
,bytes
,_NestedSequence
[Union
[bool
,int
,float
,complex
,str
,bytes
]]]]- Returns:
Expectation values of obs_list.
- index(value[, start[, stop]]) integer -- return first index of value.
Raises ValueError if the value is not present.
Supporting start and stop arguments is optional, but recommended.
- plot(op, fmt='', label='')
Plots the expectation value of a given operator op.
- Parameters:
op (
Qobj
) – Operator whose expectation value is wanted.fmt (
str
, default:''
) – Curve plot format.label (
str
, default:''
) – Curve label.
- Return type:
None
- sample_final_state(N_samples=1000)
Returns the result of multiple measurements of the final state.
- Parameters:
N_samples (
int
, default:1000
) – Number of samples to return.- Return type:
Counter
- Returns:
Sample distribution of bitstrings corresponding to measured quantum states at the end of the simulation.
NoisyResults
- class pulser_simulation.simresults.NoisyResults(run_output, size, basis_name, sim_times, n_measures)
Results of a noisy simulation run of a pulse sequence.
Contrary to a CoherentResults object, this object contains a list of Counters describing the state distribution at the time it was created by using Simulation.run() with a noisy simulation. Contains methods for studying the populations and extracting useful information from them.
- property states
Measured states as a list of diagonal qutip.Qobj.
- property results
Probability distribution of the bitstrings.
- get_state(t, t_tol=0.001)
Gets the state at time t as a diagonal density matrix.
- Return type:
Qobj
Note
This is not the density matrix of the system, but is a convenient way of computing expectation values of observables.
- Parameters:
t (
float
) – Time (µs) at which to return the state.t_tol (
float
, default:0.001
) – Tolerance for the difference between t and closest time.
- Returns:
States probability distribution as a diagonal density matrix.
- get_final_state()
Get the final state of the simulation as a diagonal density matrix.
- Return type:
Qobj
Note
This is not the density matrix of the system, but is a convenient way of computing expectation values of observables.
- Returns:
States probability distribution as a density matrix.
- plot(op, fmt='.', label='', error_bars=True)
Plots the expectation value of a given operator op.
- Return type:
None
Note
The observable must be diagonal.
- Parameters:
op (
Qobj
) – Operator whose expectation value is wanted.fmt (
str
, default:'.'
) – Curve plot format.label (
str
, default:''
) – y-Axis label.error_bars (
bool
, default:True
) – Choose to display error bars.
- count(value) integer -- return number of occurrences of value
- expect(obs_list)
Returns the expectation values of operators in obs_list.
- Parameters:
obs_list (
Sequence
[Union
[Qobj
,_SupportsArray
[dtype
[Any
]],_NestedSequence
[_SupportsArray
[dtype
[Any
]]],bool
,int
,float
,complex
,str
,bytes
,_NestedSequence
[Union
[bool
,int
,float
,complex
,str
,bytes
]]]]) – Input observable list. ArrayLike objects will be converted to qutip.Qobj.- Return type:
list
[Union
[float
,complex
,_SupportsArray
[dtype
[Any
]],_NestedSequence
[_SupportsArray
[dtype
[Any
]]],bool
,int
,str
,bytes
,_NestedSequence
[Union
[bool
,int
,float
,complex
,str
,bytes
]]]]- Returns:
Expectation values of obs_list.
- index(value[, start[, stop]]) integer -- return first index of value.
Raises ValueError if the value is not present.
Supporting start and stop arguments is optional, but recommended.
- sample_final_state(N_samples=1000)
Returns the result of multiple measurements of the final state.
- Parameters:
N_samples (
int
, default:1000
) – Number of samples to return.- Return type:
Counter
- Returns:
Sample distribution of bitstrings corresponding to measured quantum states at the end of the simulation.
- sample_state(t, n_samples=1000, t_tol=0.001)
Returns the result of multiple measurements at time t.
- Parameters:
t (
float
) – Time at which the state is sampled.n_samples (
int
, default:1000
) – Number of samples to return.t_tol (
float
, default:0.001
) – Tolerance for the difference between t and closest time.
- Return type:
Counter
- Returns:
Sample distribution of bitstrings corresponding to measured quantum states at time t.