pygsti.forwardsims.mapforwardsim
¶
Defines the MapForwardSimulator calculator class
Module Contents¶
Classes¶
A forward simulator that uses matrixvector products to compute circuit outcome probabilities. 

Computes circuit outcome probabilities using circuit layer maps that act on a state. 
Attributes¶
 pygsti.forwardsims.mapforwardsim._dummy_profiler¶
 pygsti.forwardsims.mapforwardsim._SUPEROP = 0¶
 pygsti.forwardsims.mapforwardsim._UNITARY = 1¶
 pygsti.forwardsims.mapforwardsim.CLIFFORD = 2¶
 class pygsti.forwardsims.mapforwardsim.SimpleMapForwardSimulator(model=None)¶
Bases:
pygsti.forwardsims.forwardsim.ForwardSimulator
A forward simulator that uses matrixvector products to compute circuit outcome probabilities.
This is “simple” in that it adds a minimal implementation to its
ForwardSimulator
base class. Because of this, it lacks some of the efficiency of aMapForwardSimulator
object, and is mainly useful as a reference implementation and check for other simulators. _compute_circuit_outcome_probabilities(self, array_to_fill, circuit, outcomes, resource_alloc, time=None)¶
 _set_evotype(self, evotype)¶
Called when the evotype being used (defined by the parent model) changes. evotype will be None when the current model is None
 __getstate__(self)¶
 class pygsti.forwardsims.mapforwardsim.MapForwardSimulator(model=None, max_cache_size=0, num_atoms=None, processor_grid=None, param_blk_sizes=None)¶
Bases:
pygsti.forwardsims.distforwardsim.DistributableForwardSimulator
,SimpleMapForwardSimulator
Computes circuit outcome probabilities using circuit layer maps that act on a state.
Interfaces with a model via its circuit_layer_operator method and applies the resulting operators in order to propagate states and finally compute outcome probabilities. Derivatives are computed using finitedifferences, and the prefix tables construbed by
MapCOPALayout
layout object are used to avoid duplicating (some) computation. Parameters
model (Model, optional) – The parent model of this simulator. It’s fine if this is None at first, but it will need to be set (by assigning self.model before using this simulator.
max_cache_size (int, optional) – The maximum number of “prefix” quantum states that may be cached for performance (within the layout). If None, there is no limit to how large the cache may be.
num_atoms (int, optional) – The number of atoms (subprefixtables) to use when creating the layout (i.e. when calling :method:`create_layout`). This determines how many units the element (circuit outcome probability) dimension is divided into, and doesn’t have to correclate with the number of processors. When multiple processors are used, if num_atoms is less than the number of processors then num_atoms should divide the number of processors evenly, so that num_atoms // num_procs groups of processors can be used to divide the computation over parameter dimensions.
processor_grid (tuple optional) – Specifies how the total number of processors should be divided into a number of atomprocessors, 1stparameterderivprocessors, and 2ndparameterderivprocessors. Each level of specification is optional, so this can be a 1, 2, or 3 tuple of integers (or None). Multiplying the elements of processor_grid together should give at most the total number of processors.
param_blk_sizes (tuple, optional) – The parameter block sizes along the first or first & second parameter dimensions  so this can be a 0, 1 or 2tuple of integers or None values. A block size of None means that there should be no division into blocks, and that each block processor computes all of its parameter indices at once.
 classmethod _array_types_for_method(cls, method_name)¶
 _to_nice_serialization(self)¶
 classmethod _from_nice_serialization(cls, state)¶
 copy(self)¶
Return a shallow copy of this MapForwardSimulator
 Returns
MapForwardSimulator
 create_layout(self, circuits, dataset=None, resource_alloc=None, array_types=('E',), derivative_dimension=None, verbosity=0)¶
Constructs an circuitoutcomeprobabilityarray (COPA) layout for a list of circuits.
 Parameters
circuits (list) – The circuits whose outcome probabilities should be included in the layout.
dataset (DataSet) – The source of data counts that will be compared to the circuit outcome probabilities. The computed outcome probabilities are limited to those with counts present in dataset.
resource_alloc (ResourceAllocation) – A available resources and allocation information. These factors influence how the layout (evaluation strategy) is constructed.
array_types (tuple, optional) – A tuple of stringvalued array types. See :method:`ForwardSimulator.create_layout`.
derivative_dimension (int, optional) – Optionally, the parameterspace dimension used when taking first and second derivatives with respect to the cirucit outcome probabilities. This must be nonNone when array_types contains ‘ep’ or ‘epp’ types.
verbosity (int or VerbosityPrinter) – Determines how much output to send to stdout. 0 means no output, higher integers mean more output.
 Returns
MapCOPALayout
 _bulk_fill_probs_atom(self, array_to_fill, layout_atom, resource_alloc)¶
 _bulk_fill_dprobs_atom(self, array_to_fill, dest_param_slice, layout_atom, param_slice, resource_alloc)¶
 _bulk_fill_hprobs_atom(self, array_to_fill, dest_param_slice1, dest_param_slice2, layout_atom, param_slice1, param_slice2, resource_alloc)¶
 _mapfill_hprobs_atom(self, array_to_fill, dest_indices, dest_param_indices1, dest_param_indices2, layout_atom, param_indices1, param_indices2, resource_alloc)¶
Helper function for populating hessian values by block.
 bulk_fill_timedep_chi2(self, array_to_fill, layout, ds_circuits, num_total_outcomes, dataset, min_prob_clip_for_weighting, prob_clip_interval, ds_cache=None)¶
Compute the chi2 contributions for an entire tree of circuits, allowing for time dependent operations.
Computation is performed by summing together the contributions for each time the circuit is run, as given by the timestamps in dataset.
 Parameters
array_to_fill (numpy ndarray) – an alreadyallocated 1D numpy array of length equal to the total number of computed elements (i.e. layout.num_elements)
layout (CircuitOutcomeProbabilityArrayLayout) – A layout for array_to_fill, describing what circuit outcome each element corresponds to. Usually given by a prior call to :method:`create_layout`.
ds_circuits (list of Circuits) – the circuits to use as they should be queried from dataset (see below). This is typically the same list of circuits used to construct layout potentially with some aliases applied.
num_total_outcomes (list or array) – a list of the total number of possible outcomes for each circuit (so len(num_total_outcomes) == len(ds_circuits_to_use)). This is needed for handling sparse data, where dataset may not contain counts for all the possible outcomes of each circuit.
dataset (DataSet) – the data set used to compute the chi2 contributions.
min_prob_clip_for_weighting (float, optional) – Sets the minimum and maximum probability p allowed in the chi^2 weights: N/(p*(1p)) by clipping probability p values to lie within the interval [ min_prob_clip_for_weighting, 1min_prob_clip_for_weighting ].
prob_clip_interval (2tuple or None, optional) – (min,max) values used to clip the predicted probabilities to. If None, no clipping is performed.
 Returns
None
 bulk_fill_timedep_dchi2(self, array_to_fill, layout, ds_circuits, num_total_outcomes, dataset, min_prob_clip_for_weighting, prob_clip_interval, chi2_array_to_fill=None, ds_cache=None)¶
Compute the chi2 jacobian contributions for an entire tree of circuits, allowing for time dependent operations.
Similar to :method:`bulk_fill_timedep_chi2` but compute the jacobian of the summed chi2 contributions for each circuit with respect to the model’s parameters.
 Parameters
array_to_fill (numpy ndarray) – an alreadyallocated ExM numpy array where E is the total number of computed elements (i.e. layout.num_elements) and M is the number of model parameters.
layout (CircuitOutcomeProbabilityArrayLayout) – A layout for array_to_fill, describing what circuit outcome each element corresponds to. Usually given by a prior call to :method:`create_layout`.
ds_circuits (list of Circuits) – the circuits to use as they should be queried from dataset (see below). This is typically the same list of circuits used to construct layout potentially with some aliases applied.
num_total_outcomes (list or array) – a list of the total number of possible outcomes for each circuit (so len(num_total_outcomes) == len(ds_circuits_to_use)). This is needed for handling sparse data, where dataset may not contain counts for all the possible outcomes of each circuit.
dataset (DataSet) – the data set used to compute the chi2 contributions.
min_prob_clip_for_weighting (float, optional) – Sets the minimum and maximum probability p allowed in the chi^2 weights: N/(p*(1p)) by clipping probability p values to lie within the interval [ min_prob_clip_for_weighting, 1min_prob_clip_for_weighting ].
prob_clip_interval (2tuple or None, optional) – (min,max) values used to clip the predicted probabilities to. If None, no clipping is performed.
chi2_array_to_fill (numpy array, optional) – when not None, an alreadyallocated lengthE numpy array that is filled with the percircuit chi2 contributions, just like in bulk_fill_timedep_chi2(…).
 Returns
None
 bulk_fill_timedep_loglpp(self, array_to_fill, layout, ds_circuits, num_total_outcomes, dataset, min_prob_clip, radius, prob_clip_interval, ds_cache=None)¶
Compute the loglikelihood contributions (within the “poisson picture”) for an entire tree of circuits.
Computation is performed by summing together the contributions for each time the circuit is run, as given by the timestamps in dataset.
 Parameters
 array_to_fillnumpy ndarray
an alreadyallocated 1D numpy array of length equal to the total number of computed elements (i.e. layout.num_elements)
 layoutCircuitOutcomeProbabilityArrayLayout
A layout for array_to_fill, describing what circuit outcome each element corresponds to. Usually given by a prior call to :method:`create_layout`.
 ds_circuitslist of Circuits
the circuits to use as they should be queried from dataset (see below). This is typically the same list of circuits used to construct layout potentially with some aliases applied.
 num_total_outcomeslist or array
a list of the total number of possible outcomes for each circuit (so len(num_total_outcomes) == len(ds_circuits_to_use)). This is needed for handling sparse data, where dataset may not contain counts for all the possible outcomes of each circuit.
 datasetDataSet
the data set used to compute the logl contributions.
 min_prob_clipfloat, optional
The minimum probability treated normally in the evaluation of the loglikelihood. A penalty function replaces the true loglikelihood for probabilities that lie below this threshold so that the loglikelihood never becomes undefined (which improves optimizer performance).
 radiusfloat, optional
Specifies the severity of rounding used to “patch” the zerofrequency terms of the loglikelihood.
 prob_clip_interval2tuple or None, optional
(min,max) values used to clip the predicted probabilities to. If None, no clipping is performed.
 Returns
 None
 bulk_fill_timedep_dloglpp(self, array_to_fill, layout, ds_circuits, num_total_outcomes, dataset, min_prob_clip, radius, prob_clip_interval, logl_array_to_fill=None, ds_cache=None)¶
Compute the (“poisson picture”)loglikelihood jacobian contributions for an entire tree of circuits.
Similar to :method:`bulk_fill_timedep_loglpp` but compute the jacobian of the summed logl (in posison picture) contributions for each circuit with respect to the model’s parameters.
 Parameters
array_to_fill (numpy ndarray) – an alreadyallocated ExM numpy array where E is the total number of computed elements (i.e. layout.num_elements) and M is the number of model parameters.
layout (CircuitOutcomeProbabilityArrayLayout) – A layout for array_to_fill, describing what circuit outcome each element corresponds to. Usually given by a prior call to :method:`create_layout`.
ds_circuits (list of Circuits) – the circuits to use as they should be queried from dataset (see below). This is typically the same list of circuits used to construct layout potentially with some aliases applied.
num_total_outcomes (list or array) – a list of the total number of possible outcomes for each circuit (so len(num_total_outcomes) == len(ds_circuits_to_use)). This is needed for handling sparse data, where dataset may not contain counts for all the possible outcomes of each circuit.
dataset (DataSet) – the data set used to compute the logl contributions.
min_prob_clip (float) – a regularization parameter for the loglikelihood objective function.
radius (float) – a regularization parameter for the loglikelihood objective function.
prob_clip_interval (2tuple or None, optional) – (min,max) values used to clip the predicted probabilities to. If None, no clipping is performed.
logl_array_to_fill (numpy array, optional) – when not None, an alreadyallocated lengthE numpy array that is filled with the percircuit logl contributions, just like in bulk_fill_timedep_loglpp(…).
 Returns
None