pygsti.protocols.rb.InterleavedRBDesign#

class InterleavedRBDesign(pspec, clifford_compilations, depths, circuits_per_depth, interleaved_circuit, qubit_labels=None, randomizeout=False, citerations=20, compilerargs=(), exact_compilation_key=None, descriptor='An Interleaved RB experiment', add_default_protocol=False, seed=None, verbosity=1, num_processes=1, interleave=False)#

Bases: CombinedExperimentDesign

Experiment design for interleaved randomized benchmarking (IRB).

IRB encapsulates a pair of “Clifford randomized benchmarking” (CRB) experiments. One of these CRB designs is a ‘standard’ one, but the other interleaves some clifford gate of interest between each random clifford operation. The circuits created by this function will respect the connectivity and gate-set of the device encoded by pspec (see the QubitProcessorSpec object docstring for how to construct the relevant pspec for a device).

Parameters:
  • pspec (QubitProcessorSpec) – The QubitProcessorSpec for the device that the CRB experiment is being generated for, which defines the “native” gate-set and the connectivity of the device. The returned CRB circuits will be over the gates in pspec, and will respect the connectivity encoded by pspec.

  • clifford_compilations (dict) – A dictionary with the potential keys ‘absolute’ and ‘paulieq’ and corresponding class:CompilationRules values. These compilation rules specify how to compile the “native” gates of pspec into Clifford gates.

  • depths (list of ints) – The “CRB depths” of the circuit; a list of integers >= 0. The CRB length is the number of Cliffords in the circuit - 2 before each Clifford is compiled into the native gate-set.

  • circuits_per_depth (int) – The number of (possibly) different CRB circuits sampled at each length.

  • interleaved_circuit (Circuit) – Circuit to use in the construction of the interleaved CRB experiment. This is the circuit whose error rate is to be estimated by the IRB experiment.

  • qubit_labels (list, optional) – If not None, a list of the qubits that the RB circuits are to be sampled for. This should be all or a subset of the qubits in the device specified by the QubitProcessorSpec pspec. If None, it is assumed that the RB circuit should be over all the qubits. Note that the ordering of this list is the order of the “wires” in the returned circuit, but is otherwise irrelevant. If desired, a circuit that explicitly idles on the other qubits can be obtained by using methods of the Circuit object.

  • randomizeout (bool, optional) – If False, the ideal output of the circuits (the “success” or “survival” outcome) is always the all-zeros bit string. This is probably considered to be the “standard” in CRB. If True, the ideal output a circuit is randomized to a uniformly random bit-string. This setting is useful for, e.g., detecting leakage/loss/measurement-bias etc.

  • citerations (int, optional) – Some of the Clifford compilation algorithms in pyGSTi (including the default algorithm) are randomized, and the lowest-cost circuit is chosen from all the circuit generated in the iterations of the algorithm. This is the number of iterations used. The time required to generate a CRB circuit is linear in citerations * (CRB length + 2). Lower-depth / lower 2-qubit gate count compilations of the Cliffords are important in order to successfully implement CRB on more qubits.

  • compilerargs (list, optional) –

    A list of arguments that are handed to compile_clifford() function, which includes all the optional arguments of compile_clifford() after the iterations option (set by citerations). In order, this list should be values for:

    • algorithm : str. A string that specifies the compilation algorithm. The default in compile_clifford() will always be whatever we consider to be the ‘best’ all-round algorithm.

    • aargs : list. A list of optional arguments for the particular compilation algorithm.

    • costfunction : ‘str’ or function. The cost-function from which the “best” compilation for a Clifford is chosen from all citerations compilations. The default costs a circuit as 10x the num. of 2-qubit gates in the circuit + 1x the depth of the circuit.

    • prefixpaulis : bool. Whether to prefix or append the Paulis on each Clifford.

    • paulirandomize : bool. Whether to follow each layer in the Clifford circuit with a random Pauli on each qubit (compiled into native gates). I.e., if this is True the native gates are Pauli-randomized. When True, this prevents any coherent errors adding (on average) inside the layers of each compiled Clifford, at the cost of increased circuit depth. Defaults to False.

    For more information on these options, see the compile_clifford() docstring.

  • descriptor (str, optional) – A string describing the experiment generated, which will be stored in the returned dictionary.

  • add_default_protocol (bool, optional) – Whether to add a default RB protocol to the experiment design, which can be run later (once data is taken) by using a DefaultProtocolRunner object.

  • seed (int, optional) – A seed to initialize the random number generator used for creating random clifford circuits. The first of the two subdesigns will use the specified seed directly, while the second will use seed+1.

  • verbosity (int, optional) – If > 0 the number of circuits generated so far is shown.

  • interleave (bool, optional) – Whether the circuits of the standard CRB and IRB sub designs should be interleaved to form the circuit ordering of this experiment design. E.g. when calling the all_circuits_needing_data attribute.

Create a new CombinedExperimentDesign object.

Parameters:
  • sub_designs (dict or list) – A dictionary of other ExperimentDesign objects whose keys are names for each sub-edesign (used for directories and to index the sub-edesigns from this experiment design). If a list is given instead, a default names of the form “ subdesign-<number> “ are used.

  • all_circuits (list, optional) – A list of Circuit`s, specifying all the circuits needing data.  This can include additional circuits that are not in any of `sub_designs. By default, the union of all the circuits in the sub-designs is used.

  • qubit_labels (tuple, optional) – The qubits that this experiment design applies to. If None, the line labels of the first circuit is used.

  • sub_design_dirs (dict, optional) – A dictionary whose values are directory names and keys are sub-edesign names (the same as the keys of sub_designs). If None, then the keys of sub_designs must be strings and are used as directory names. Directory names are used when saving the object (via write()).

  • interleave (bool, optional) – Whether the circuits of the sub_designs should be interleaved to form the circuit ordering of this experiment design.

Return type:

CombinedExperimentDesign

Methods

__init__(pspec, clifford_compilations, ...)

Create a new CombinedExperimentDesign object.

add_default_protocol(default_protocol_instance)

Add a "default" protocol to this experiment design.

add_mongodb_write_ops(write_ops, mongodb[, ...])

Accumulate write and update operations for writing this object to a MongoDB database.

average_native_gates_per_clifford()

The average number of native gates per Clifford for all circuits

from_dir(dirname[, parent, name, quick_load])

Initialize a new ExperimentDesign object from dirname.

from_edesign(edesign, name)

Create a combined experiment design out of an existing experiment design.

from_existing_designs(crb_subdesign, ...[, ...])

from_mongodb(mongodb, doc_id, **kwargs)

Create and initialize an object from a MongoDB instance.

from_mongodb_doc(mongodb, collection_name, ...)

Create and initialize an object from a MongoDB instance and pre-loaded primary document.

items()

An iterator over the (child_name, child_node) pairs of this node.

keys()

An iterator over the keys (child names) of this tree node.

map_qubit_labels(mapper)

Creates a new experiment design whose circuits' qubit labels are updated according to a given mapping.

promote_to_combined([name])

Promote this experiment design to be a combined experiment design.

promote_to_simultaneous()

Promote this experiment design to be a simultaneous experiment design.

prune_tree(paths[, paths_are_sorted])

Prune the tree rooted here to include only the given paths, discarding all other leaves & branches.

remove_from_mongodb(mongodb, doc_id[, ...])

Remove the documents corresponding to an instance of this class from a MongoDB database.

remove_me_from_mongodb(mongodb[, session, ...])

set_actual_circuits_executed(actual_circuits)

Sets a list of circuits that will actually be executed.

setup_nameddict(final_dict)

Initializes a set of nested NamedDict dictionaries describing this design.

truncate_to_available_data(dataset)

Builds a new experiment design containing only those circuits present in dataset.

truncate_to_circuits(circuits_to_keep)

Builds a new experiment design containing only the specified circuits.

truncate_to_design(other_design)

Truncates this experiment design by only keeping the circuits also in other_design

underlying_tree_paths()

Dictionary paths leading to data objects/nodes beneath this one.

view(keys_to_keep)

Get a "view" of this tree node that only has a subset of this node's children.

write([dirname, parent])

Write this experiment design to a directory.

write_to_mongodb(mongodb[, session, ...])

Write this object to a MongoDB database.

Attributes

collection_name

add_default_protocol(default_protocol_instance)#

Add a “default” protocol to this experiment design.

Default protocols are a way of designating protocols you mean to run on the the data corresponding to an experiment design before that data has been taken. Use a DefaultRunner object to run (all) the default protocols of the experiment designs within a ProtocolData object.

Note that default protocols are indexed by their names, and so when adding multiple default protocols they need to have distinct names (usually given to the protocol when it is constructed).

Parameters:

default_protocol_instance (Protocol) – The protocol to add. This protocol’s name is used to index it.

Return type:

None

add_mongodb_write_ops(write_ops, mongodb, overwrite_existing=False, **kwargs)#

Accumulate write and update operations for writing this object to a MongoDB database.

Similar to write_to_mongodb() but collects write operations instead of actually executing any write operations on the database. This function may be preferred to write_to_mongodb() when this object is being written as a part of a larger entity and executing write operations is saved until the end.

As in write_to_mongodb(), self.collection_name is the collection name and _id is either: 1) the ID used by a previous write or initial read-in, if one exists, OR 2) a new random bson.objectid.ObjectId

Parameters:
  • write_ops (WriteOpsByCollection) – An object that keeps track of pymongo write operations on a per-collection basis. This object accumulates write operations to be performed at some point in the future.

  • mongodb (pymongo.database.Database) – The MongoDB instance to write data to.

  • overwrite_existing (bool, optional) – Whether existing documents should be overwritten. The default of False causes a ValueError to be raised if a document with the given _id already exists and is different from what is being written.

  • **kwargs (dict) – Additional keyword arguments potentially used by subclass implementations. Any arguments allowed by a subclass’s _add_auxiliary_write_ops_and_update_doc method is allowed here.

Returns:

The identifier (_id value) of the main document that was written.

Return type:

bson.objectid.ObjectId

average_native_gates_per_clifford()#

The average number of native gates per Clifford for all circuits

Returns:

A tuple of the average number of native gates per Clifford for the contained standard CRB design, and interleaved CRB design, respectively.

Return type:

tuple of floats

classmethod from_dir(dirname, parent=None, name=None, quick_load=False)#

Initialize a new ExperimentDesign object from dirname.

This is specialized to regenerate all_circuits_needing_data if it was not serialized.

Parameters:
  • dirname (str) – The root directory name (under which there is a ‘edesign’ subdirectory).

  • parent (ExperimentDesign, optional) – The parent design object, if there is one. Primarily used internally - if in doubt, leave this as None.

  • name (str, optional) – The sub-name of the design object being loaded, i.e. the key of this data object beneath parent. Only used when parent is not None.

  • quick_load (bool, optional) – Setting this to True skips the loading of the potentially long circuit lists. This can be useful when loading takes a long time and all the information of interest lies elsewhere, e.g. in an encompassing results object.

Return type:

ExperimentDesign

classmethod from_edesign(edesign, name)#

Create a combined experiment design out of an existing experiment design.

This makes edesign the one and only member of a new combined experiment design, even in edesign is already a CombinedExperimentDesign.

Parameters:
  • edesign (ExperimentDesign) – The experiment design to convert (use as a base).

  • name (str) – The sub-name of edesign within the returned combined experiment design.

Return type:

CombinedExperimentDesign

classmethod from_mongodb(mongodb, doc_id, **kwargs)#

Create and initialize an object from a MongoDB instance.

Parameters:
  • mongodb (pymongo.database.Database) – The MongoDB instance to load from.

  • doc_id (bson.objecctid.ObjectId or dict) – The object ID or filter used to find a single object ID within the database. This document is loaded from the collection given by the collection_name attribute of this class.

  • **kwargs (dict) – Additional keyword arguments potentially used by subclass implementations. Any arguments allowed by a subclass’s _create_obj_from_doc_and_mongodb method is allowed here.

Return type:

object

classmethod from_mongodb_doc(mongodb, collection_name, doc, **kwargs)#

Create and initialize an object from a MongoDB instance and pre-loaded primary document.

Parameters:
  • mongodb (pymongo.database.Database) – The MongoDB instance to load from.

  • collection_name (str) – The collection name within mongodb that doc was loaded from. This is needed for the sole purpose of setting the created (returned) object’s database “coordinates”.

  • doc (dict) – The already-retrieved main document for the object being loaded. This takes the place of giving an identifier for this object.

  • **kwargs (dict) – Additional keyword arguments potentially used by subclass implementations. Any arguments allowed by a subclass’s _create_obj_from_doc_and_mongodb method is allowed here.

Return type:

object

items()#

An iterator over the (child_name, child_node) pairs of this node.

keys()#

An iterator over the keys (child names) of this tree node.

map_qubit_labels(mapper)#

Creates a new experiment design whose circuits’ qubit labels are updated according to a given mapping.

Parameters:

mapper (dict or function) – A dictionary whose keys are the existing self.qubit_labels values and whose value are the new labels, or a function which takes a single (existing qubit-label) argument and returns a new qubit-label.

Return type:

InterleavedRBDesign

promote_to_combined(name='subdesign-0')#

Promote this experiment design to be a combined experiment design.

Wraps this experiment design in a new CombinedExperimentDesign whose only sub-design is this one, and returns the combined design.

Parameters:

name (str, optional) – The sub-design-name of this experiment design within the created combined experiment design.

Return type:

CombinedExperimentDesign

promote_to_simultaneous()#

Promote this experiment design to be a simultaneous experiment design.

Wraps this experiment design in a new SimultaneousExperimentDesign whose only sub-design is this one, and returns the simultaneous design.

Return type:

SimultaneousExperimentDesign

prune_tree(paths, paths_are_sorted=False)#

Prune the tree rooted here to include only the given paths, discarding all other leaves & branches.

Parameters:
  • paths (list) – A list of tuples specifying the paths to keep.

  • paths_are_sorted (bool, optional) – Whether paths is sorted (lexicographically). Setting this to True will save a little time.

Returns:

A view of this node and its descendants where unwanted children have been removed.

Return type:

TreeNode

classmethod remove_from_mongodb(mongodb, doc_id, collection_name=None, session=None, recursive='default')#

Remove the documents corresponding to an instance of this class from a MongoDB database.

Parameters:
  • mongodb (pymongo.database.Database) – The MongoDB instance to remove documents from.

  • doc_id (bson.objectid.ObjectId) – The identifier of the root document stored in the database.

  • collection_name (str, optional) – the MongoDB collection within mongodb where the main document resides. If None, then <this_class>.collection_name is used (which is usually what you want).

  • session (pymongo.client_session.ClientSession, optional) – MongoDB session object to use when interacting with the MongoDB database. This can be used to implement transactions among other things.

  • recursive (RecursiveRemovalSpecification, optional) – An object that filters the type of documents that are removed. Used when working with inter-related experiment designs, data, and results objects to only remove the types of documents you know aren’t being shared with other documents.

Return type:

None

set_actual_circuits_executed(actual_circuits)#

Sets a list of circuits that will actually be executed.

This list must be parallel, and corresponding circuits must be logically equivalent, to those in self.all_circuits_needing_data. For example, when the circuits in this design are run simultaneously with other circuits, the circuits in this design may need to be padded with idles.

Parameters:

actual_circuits (list) – A list of Circuit objects that must be the same length as self.all_circuits_needing_data.

Return type:

None

setup_nameddict(final_dict)#

Initializes a set of nested NamedDict dictionaries describing this design.

This function is used by ProtocolResults objects when they’re creating nested dictionaries of their contents. This function returns a set of nested, single (key,val)-pair named-dictionaries which describe the particular attributes of this ExperimentDesign object named within its self._nameddict_attributes tuple. The final nested dictionary is set to be final_dict, which allows additional result quantities to easily be added.

Parameters:

final_dict (NamedDict) – the final-level (innermost-nested) NamedDict in the returned nested dictionary.

Return type:

NamedDict

truncate_to_available_data(dataset)#

Builds a new experiment design containing only those circuits present in dataset.

Parameters:

dataset (DataSet) – The dataset to filter based upon.

Return type:

ExperimentDesign

truncate_to_circuits(circuits_to_keep)#

Builds a new experiment design containing only the specified circuits.

Parameters:

circuits_to_keep (list) – A list of the circuits to keep.

Return type:

ExperimentDesign

truncate_to_design(other_design)#

Truncates this experiment design by only keeping the circuits also in other_design

Parameters:

other_design (ExperimentDesign) – The experiment design to compare with.

Returns:

The truncated experiment design.

Return type:

ExperimentDesign

underlying_tree_paths()#

Dictionary paths leading to data objects/nodes beneath this one.

Returns:

A list of tuples, each specifying the tree traversal to a child node. The first tuple is the empty tuple, referring to this (root) node.

Return type:

list

view(keys_to_keep)#

Get a “view” of this tree node that only has a subset of this node’s children.

Parameters:

keys_to_keep (iterable) – A sequence of key names to keep.

Return type:

TreeNode

write(dirname=None, parent=None)#

Write this experiment design to a directory.

This is specialized to skip writing all_circuits_needing_data if it can be regenerated from other class information.

Parameters:
  • dirname (str) – The root directory to write into. This directory will have an ‘edesign’ subdirectory, which will be created if needed and overwritten if present. If None, then the path this object was loaded from is used (if this object wasn’t loaded from disk, an error is raised).

  • parent (ExperimentDesign, optional) – The parent experiment design, when a parent is writing this design as a sub-experiment-design. Otherwise leave as None.

Return type:

None

write_to_mongodb(mongodb, session=None, overwrite_existing=False, **kwargs)#

Write this object to a MongoDB database.

The collection name used is self.collection_name, and the _id is either: 1) the ID used by a previous write or initial read-in, if one exists, OR 2) a new random bson.objectid.ObjectId

Parameters:
  • mongodb (pymongo.database.Database) – The MongoDB instance to write data to.

  • session (pymongo.client_session.ClientSession, optional) – MongoDB session object to use when interacting with the MongoDB database. This can be used to implement transactions among other things.

  • overwrite_existing (bool, optional) – Whether existing documents should be overwritten. The default of False causes a ValueError to be raised if a document with the given _id already exists and is different from what is being written.

  • **kwargs (dict) – Additional keyword arguments potentially used by subclass implementations. Any arguments allowed by a subclass’s _add_auxiliary_write_ops_and_update_doc method is allowed here.

Returns:

The identifier (_id value) of the main document that was written.

Return type:

bson.objectid.ObjectId