pygsti.extras.ibmq

Exteneral Device Specifications Sub-package

Submodules

Package Contents

Classes

_ProtocolData

Represents the experimental data needed to run one or more QCVV protocols.

IBMQExperiment

Functions

reverse_dict_key_bits(counts_dict)

partial_trace(ordered_target_indices, input_dict)

q_list_to_ordered_target_indices(q_list, num_qubits)

Attributes

_qiskit

_attribute_to_json

_attribute_to_pickle

class pygsti.extras.ibmq._ProtocolData(edesign, dataset=None, cache=None)

Bases: pygsti.protocols.treenode.TreeNode

Represents the experimental data needed to run one or more QCVV protocols.

This class contains a ProtocolIput, which describes a set of circuits, and a DataSet (or MultiDataSet) that holds data for these circuits. These members correspond to the .edesign and .dataset attributes.

Parameters
  • edesign (ExperimentDesign) – The experiment design describing what circuits this object contains data for. If None, then an unstructured ExperimentDesign is created containing the circuits present in dataset.

  • dataset (DataSet or MultiDataSet, optional) – The data counts themselves.

  • cache (dict, optional) – A cache of values which holds values derived only from the experiment design and data in this object.

passes

A dictionary of the data on a per-pass basis (works even it there’s just one pass).

Type

dict

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

Initialize a new ProtocolData object from dirname.

Parameters
  • dirname (str) – The root directory name (under which there are ‘edesign’ and ‘data’ subdirectories).

  • parent (ProtocolData, optional) – The parent data object, if there is one. This is needed for sub-data objects which reference/inherit their parent’s dataset. 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 components that may take a long time, e.g. the actual raw data set(s). 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.

Returns

ProtocolData

__getstate__(self)
__setstate__(self, state_dict)
_create_childval(self, key)

Create the value for key on demand.

copy(self)

Make a copy of this object.

Returns

ProtocolData

property passes(self)

A dictionary of the data on a per-pass basis (works even it there’s just one pass).

Returns

dict

is_multipass(self)

Whether this protocol data contains multiple passes.

More accurately, whether the .dataset of this object is a MultiDataSet.

Returns

bool

prune_tree(self, paths, paths_are_sorted=False)

Prune the tree rooted here to include only the given paths, discarding all else.

Returns a new ProtocolData object with a subset of the data-tree paths contained under this one.

Parameters
  • paths (list) – A list of the paths to keep. Each path is a tuple of keys, delineating a path in the data-tree.

  • paths_are_sorted (bool, optional) – Whether paths has already been sorted lexographically.

Returns

ProtocolData

write(self, dirname=None, parent=None)

Write this protocol data to a directory.

Parameters
  • dirname (str) – The root directory to write into. This directory will have ‘edesign’ and ‘data’ subdirectories, 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 (ProtocolData, optional) – The parent protocol data, when a parent is writing this data as a sub-protocol-data object. Otherwise leave as None.

Returns

None

setup_nameddict(self, final_dict)

Initializes a set of nested NamedDict dictionaries describing this data.

This function is used by ProtocolResults objects when they’re creating nested dictionaries of their contents. 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.

Returns

NamedDict

to_dataframe(self, pivot_valuename=None, pivot_value=None, drop_columns=False)

Create a Pandas dataframe with this data.

Parameters
  • pivot_valuename (str, optional) – If not None, the resulting dataframe is pivoted using pivot_valuename as the column whose values name the pivoted table’s column names. If None and pivot_value is not None,`”ValueName”` is used.

  • pivot_value (str, optional) – If not None, the resulting dataframe is pivoted such that values of the pivot_value column are rearranged into new columns whose names are given by the values of the pivot_valuename column. If None and pivot_valuename is not None,`”Value”` is used.

  • drop_columns (bool or list, optional) – A list of column names to drop (prior to performing any pivot). If True appears in this list or is given directly, then all constant-valued columns are dropped as well. No columns are dropped when drop_columns == False.

Returns

pandas.DataFrame

pygsti.extras.ibmq._qiskit
pygsti.extras.ibmq._attribute_to_json = ['remove_duplicates', 'randomized_order', 'circuits_per_batch', 'num_shots', 'job_ids']
pygsti.extras.ibmq._attribute_to_pickle = ['pspec', 'pygsti_circuits', 'pygsti_openqasm_circuits', 'qiskit_QuantumCircuits',...
pygsti.extras.ibmq.reverse_dict_key_bits(counts_dict)
pygsti.extras.ibmq.partial_trace(ordered_target_indices, input_dict)
pygsti.extras.ibmq.q_list_to_ordered_target_indices(q_list, num_qubits)
class pygsti.extras.ibmq.IBMQExperiment(edesign, pspec, remove_duplicates=True, randomized_order=True, circuits_per_batch=75, num_shots=1024)

Bases: dict

submit(self, ibmq_backend)

Submits the jobs to IBM Q, that implements the experiment specified by the ExperimentDesign used to create this object.

Parameters

ibmq_backend (qiskit.providers.ibmq.ibmqbackend.IBMQBackend) – The IBM Q backend to submit the jobs to. Should be the backend corresponding to the processor that this experiment has been designed for.

Returns

None

monitor(self)

Queries IBM Q for the status of the jobs.

retrieve_results(self)

Gets the results of the completed jobs from IBM Q, and processes them into a pyGSTi DataProtocol object (stored as the key ‘data’), which can then be used in pyGSTi data analysis routines (e.g., if this was a GST experiment, it can input into a GST protocol object that will analyze the data).

write(self, dirname=None)

Writes to disk, storing both the pyGSTi DataProtocol object in pyGSTi’s standard format and saving all of the IBM Q submission information stored in this object, written into the subdirectory ‘ibmqexperiment’.

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).

classmethod from_dir(cls, dirname)

Initialize a new IBMQExperiment object from dirname.

Parameters

dirname (str) – The directory name.

Returns

IBMQExperiment