pygsti.layouts.cachedlayout

A object representing the indexing into a (flat) array of circuit outcome probabilities.

Module Contents

Classes

CachedCOPALayout

A COPA Layout that includes a generic per-circuit cache dictionary.

class pygsti.layouts.cachedlayout.CachedCOPALayout(circuits, unique_circuits, to_unique, elindex_outcome_tuples, unique_complete_circuits=None, param_dimensions=(), resource_alloc=None, cache=None)

Bases: pygsti.layouts.copalayout.CircuitOutcomeProbabilityArrayLayout

A COPA Layout that includes a generic per-circuit cache dictionary.

A commonly useful addition to the base COPA layout is to add a persistent “cache” dictionary that tags along with each circuit, so that parts of computations that depend only on the circuit (and its outcomes) can be computed just once.

Parameters

circuitslist of Circuits

The circuits whose outcome probabilities are to be computed. This list may contain duplicates.

unique_circuitslist of Circuits

The same as circuits, except duplicates are removed. Often this value is obtained by a derived class calling the class method _compute_unique_circuits().

to_uniquedict

A mapping that translates an index into circuits to one into unique_circuits. Keys are the integers 0 to len(circuits) and values are indices into unique_circuits.

elindex_outcome_tuplescollections.OrderedDict

A dictionary whose keys are integer indices into unique_circuits and whose values are lists of (element_index, outcome_label) tuples that give the element index within the 1D array of the probability (or other quantity) corresponding to the given circuit and outcome label. Note that outcome labels themselves are tuples of instrument/POVM member labels.

unique_complete_circuitslist, optional

A list, parallel to unique_circuits, that contains the “complete” version of these circuits. This information is currently unused, and is included for potential future expansion and flexibility.

param_dimensionstuple, optional

A tuple containing, optionally, the parameter-space dimension used when taking first and second derivatives with respect to the circuit outcome probabilities. This is meta-data bundled along with the main layout information, and is needed for allocating arrays with derivative dimensions.

resource_allocResourceAllocation, optional

The resources available for computing circuit outcome probabilities.

cachedict

The cache dictionary for this layout. Its keys are the elements of circuits and its values can be whatever the user wants. These values are provided when calling iter_unique_circuits_with_cache(), so that a forward simulator using this layout can cache arbitrary precomputed information within the layout.

classmethod create_from(circuits, model, dataset=None, param_dimensions=(), resource_alloc=None, cache=None)

Creates a CachedCOPALayout from a list of circuits.

Parameters
circuitslist of Circuits

The circuits to include in the layout. Note that the produced layout may not retain the ordering of these circuits internally, but that it’s .global_layout does.

modelModel, optional

A model used to “complete” the circuits (add implied prep and/or POVM layers). Usually this is a/the model that will be used to compute outcomes probabilities using this layout. If None, then each element of circuits is assumed to be a complete circuit, i.e., to begin with a state preparation layer and end with a POVM layer.

datasetDataSet, optional

If not None, restrict what is simplified to only those probabilities corresponding to non-zero counts (observed outcomes) in this data set.

param_dimensionstuple, optional

A tuple containing, optionally, the parameter-space dimension used when taking first and second derivatives with respect to the circuit outcome probabilities.

resource_allocResourceAllocation, optional

The resources available for computing circuit outcome probabilities.

cachedict

A dictionary whose keys are the elements of circuits and values can be whatever the user wants. These values are provided when calling iter_unique_circuits_with_cache().

iter_unique_circuits_with_cache()

Iterate over the element-indices, circuit, outcomes, and cache of each unique circuit in this layout.

A generator used to iterate over a (element_indices, circuit, outcomes, cache) tuple for each unique circuit held by this layout, where element_indices and outcomes are the values that would be retrieved by the indices() and outcomes() methods, circuit is the unique circuit itself, and cache is the user-defined value of the cache-dictionary entry for this circuit.

Returns

generator