pygsti.forwardsims.distforwardsim
¶
Defines the DistributableForwardSimulator calculator class
Module Contents¶
Classes¶
A base class for forward simulators that use distributed COPA layouts. |
- class pygsti.forwardsims.distforwardsim.DistributableForwardSimulator(model=None, num_atoms=None, processor_grid=None, param_blk_sizes=None)¶
Bases:
pygsti.forwardsims.forwardsim.ForwardSimulator
A base class for forward simulators that use distributed COPA layouts.
This class contains implements the methods of
ForwardSimulator
assuming that the layout is aDistributableCOPALayout
object, and leaves a set of a simpler methods for derived classes to implement.In particular, because a distributed layout divides computations by assigning segments of the full element- and parameter-dimensions to individual processors, derived classes just implement the _bulk_fill_*probs_atom methods which compute a single section of the entire output array, and don’t need to worry about dealing with the distribution in element and parameter directions.
- 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.
num_atoms (int, optional) – The number of atoms to use when creating a 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 it 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 atom-processors, 1st-parameter-deriv-processors, and 2nd-parameter-deriv-processors. 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 2-tuple 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)¶
- _set_param_block_size(self, wrt_filter, wrt_block_size, comm)¶
- _bulk_fill_probs(self, array_to_fill, layout)¶
Note: we expect that array_to_fill points to the memory specifically for this processor (a subset of the memory for the host when memory is shared)
- _bulk_fill_probs_atom(self, array_to_fill, layout_atom, resource_alloc)¶
- _bulk_fill_dprobs(self, array_to_fill, layout, pr_array_to_fill)¶
Note: we expect that array_to_fill points to the memory specifically for this processor (a subset of the memory for the host when memory is shared)
- _bulk_fill_dprobs_atom(self, array_to_fill, dest_param_slice, layout_atom, param_slice, resource_alloc)¶
- _bulk_fill_hprobs(self, array_to_fill, layout, pr_array_to_fill, deriv1_array_to_fill, deriv2_array_to_fill)¶
Note: we expect that array_to_fill points to the memory specifically for this processor (a subset of the memory for the host when memory is shared)
- _bulk_fill_hprobs_atom(self, array_to_fill, dest_param_slice1, dest_param_slice2, layout_atom, param_slice1, param_slice2, resource_alloc)¶
- _bulk_fill_hprobs_dprobs_atom(self, array_to_fill, deriv1_array_to_fill, deriv2_array_to_fill, atom, param_slice1, param_slice2, resource_alloc)¶
- _iter_hprobs_by_rectangle(self, layout, wrt_slices_list, return_dprobs_12)¶
- _iter_atom_hprobs_by_rectangle(self, atom, wrt_slices_list, return_dprobs_12, resource_alloc)¶
- _bulk_fill_timedep_deriv(self, layout, dataset, ds_circuits, num_total_outcomes, deriv_array_to_fill, deriv_fill_fn, array_to_fill=None, fill_fn=None)¶
A helper method for computing (filling) the derivative of a time-dependent quantity.
A generic method providing the scaffolding used when computing (filling) the derivative of a time-dependent quantity. In particular, it distributes the computation among the subtrees of eval_tree and relies on the caller to supply “compute_cache” and “compute_dcache” functions which just need to compute the quantitiy being filled and its derivative given a sub-tree and a parameter-slice.
- Parameters
layout (TermCOPALayout) – The layout specifiying the quantities (circuit outcome probabilities) to be computed, and related information.
dataset (DataSet) – the data set passed on to the computation functions.
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)). This is needed for handling sparse data, where dataset may not contain counts for all the possible outcomes of each circuit.
deriv_array_to_fill (numpy ndarray) – an already-allocated 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.
deriv_fill_fn (function) – a function used to compute the objective funtion jacobian.
array_to_fill (numpy array, optional) – when not None, an already-allocated length-E numpy array that is filled with the per-circuit contributions computed using fn below.
fill_fn (function, optional) – a function used to compute the objective function.
- Returns
None
- _run_on_atoms(self, layout, fn, resource_alloc)¶
Runs fn on all the atoms of layout, returning a list of the local (current processor) return values.
- _compute_processor_distribution(self, array_types, nprocs, num_params, num_circuits, default_natoms)¶
Computes commonly needed processor-grid info for distributed layout creation (a helper function)