pygsti.modelpacks.stdtarget

Helper functions for standard model modules.

Module Contents

Functions

_get_cachefile_names(std_module, param_type, simulator, py_version)

Get the standard cache file names for a module

_write_calccache(calc_cache, key_fn, val_fn, json_too=False, comm=None)

Write caclcache, a dictionary of compact polys, to disk in two files,

_load_calccache(key_fn, val_fn)

The complement to _write_calccache, this function loads a cache

_copy_target(std_module, param_type, simulator='auto', gscache=None)

Returns a copy of std_module._target_model in the given parameterization.

stdmodule_to_smqmodule(std_module)

Converts a pyGSTi "standard module" to a "standard multi-qubit module".

pygsti.modelpacks.stdtarget._get_cachefile_names(std_module, param_type, simulator, py_version)

Get the standard cache file names for a module

pygsti.modelpacks.stdtarget._write_calccache(calc_cache, key_fn, val_fn, json_too=False, comm=None)

Write caclcache, a dictionary of compact polys, to disk in two files, one for the keys and one for the values.

This function can be called by multiple ranks and passed comm to synchronize collecting and writing a single set of cache files.

Parameters
  • calc_cache (dict) – The cache of calculated (compact) polynomial to save to disk.

  • key_fn (str) – key and value filenames.

  • val_fn (str) – key and value filenames.

  • json_too (bool, optional) – When true, the keys are also written in JSON format (to facilitate python2 & 3 compatibility)

  • comm (mpi4py.MPI.comm) – Communicator for synchronizing across multiple ranks (each with different calc_cache args that need to be gathered.

Returns

None

pygsti.modelpacks.stdtarget._load_calccache(key_fn, val_fn)

The complement to _write_calccache, this function loads a cache dictionary from key and value filenames.

Parameters
  • key_fn (str) – key and value filenames.

  • val_fn (str) – key and value filenames.

Returns

dict – The cache of calculated (compact) polynomials.

pygsti.modelpacks.stdtarget._copy_target(std_module, param_type, simulator='auto', gscache=None)

Returns a copy of std_module._target_model in the given parameterization.

Parameters
  • std_module (module) – The standard model module whose target model should be copied and returned.

  • param_type ({"TP", "CPTP", "H+S", "S", ... }) – The gate and SPAM vector parameterization type. See :function:`Model.set_all_parameterizations` for all allowed values.

  • simulator (ForwardSimulator or {"auto", "matrix", "map"}) – The simulator (or type) to be used for model calculations (leave as “auto” if you’re not sure what this is).

  • gscache (dict, optional) – A dictionary for maintaining the results of past calls to _copy_target. Keys are (param_type, simulator) tuples and values are Model objects. If gscache contains the requested param_type and simulator then a copy of the cached value is returned instead of doing any real work. Furthermore, if gscache is not None and a new Model is constructed, it will be added to the given gscache for future use.

Returns

Model

pygsti.modelpacks.stdtarget.stdmodule_to_smqmodule(std_module)

Converts a pyGSTi “standard module” to a “standard multi-qubit module”.

PyGSTi provides a number of 1- and 2-qubit models corrsponding to commonly used gate sets, along with related meta-information. Each such model+metadata is stored in a “standard module” beneath pygsti.modelpacks.legacy (e.g. pygsti.modelpacks.legacy.std1Q_XYI is the standard module for modeling a single-qubit quantum processor which can perform X(pi/2), Y(pi/2) and idle operations). Because they deal with just 1- and 2-qubit models, multi-qubit labelling conventions are not used to improve readability. For example, a “X(pi/2)” gate is labelled “Gx” (in a 1Q context) or “Gix” (in a 2Q context) rather than “Gx:0” or “Gx:1” respectively.

There are times, however, when you many want a standard module with this multi-qubit labelling convention (e.g. performing 1Q-GST on the 3rd qubit of a 5-qubit processor). We call such a module a standard multi-qubit module, and these typically begin with “smq” rather than “std”.

Standard multi-qubit modules are created by this function. For example, If you want the multi-qubit version of pygsti.modelpacks.legacy.std1Q_XYI you must:

  1. import std1Q_XYI (from pygsti.modelpacks.legacy import std1Q_XYI)

  2. call this function (i.e. stdmodule_to_smqmodule(std1Q_XYI))

  3. import smq1Q_XYI (from pygsti.modelpacks.legacy import smq1Q_XYI)

The smq1Q_XYI module will look just like the std1Q_XYI module but use multi-qubit labelling conventions.

Deprecated since version v0.9.9: stdmodule_to_smqmodule will be removed in future versions of pyGSTi. Instead, import pre-built SMQ modelpacks directly from pygsti.modelpacks.

Parameters

std_module (Module) – The standard module to convert to a standard-multi-qubit module.

Returns

Module – The new module, although it’s better to import this using the appropriate “smq”-prefixed name as described above.