pygsti.extras.idletomography
Idle Tomography Subpackage
Submodules
Package Contents
Classes
A table of all the intrinsic rates found by idle tomography. 

A table of the largest N (in absolute value) observed error rates. 

A plot showing how an observed error rate is obtained by fitting a sequence 

A table showing the observed error rates relevant for determining a 

A container for idle tomography results: intrinsic and observable errors, 

A Nqubit state that is the tensor product of N 

A Nqubit pauli operator, consisting of 

A string of 0's and 1's representing a definite outcome in the Zbasis. 
Functions

Computes the Jacobian matrix element for a Hamiltonian error: how the 

Computes the "expected" outcome when the stochastic error error 

Computes the Jacobian matrix element for a Stochastic error: how the 

Computes the Jacobian matrix element for a Affine error: how the 

Computes the Jacobian matrix element for a Affine error: how the 

Construct a list of Paulibasis fiducial pairs for idle tomography. 

Infers what the preferred basis signs are based on the length of gatename 

Translate 

Intelligently determine preparation and measurement Pauli basis 

Construct the list of experiments needed to perform idle tomography. 

Construct lists of experiments, one for each maximumlength value, needed 

Extract the observed error rate from a series of experiments which prepares 

Extract the observed error rate from a series of experiments which prepares 

Analyze dataset using the idle tomography protocol to characterize 

Creates an Idle Tomography report, summarizing the results of running 

Lists every "error bit string" that co1uld be caused by an error of weight 

Lists every Pauli error operator for nqubits qubits with weight <= maxweight 

Lists every weight <= maxweight observable whose expectation value can be 

Tiles a set of base fiducial pairs on maxweight qubits to a 
List all nontrivial paulis of given weight wt. 


Set specific or random error terms (typically for a datagenerating model) 

Get error rates on the global idle operation within a 

Get the exact intrinsic rates that would be produced by simulating model 

Get the exact observable rates that would be produced by simulating 
 pygsti.extras.idletomography.hamiltonian_jac_element(prep, error, observable)
Computes the Jacobian matrix element for a Hamiltonian error: how the expectation value of observable in state prep changes due to Hamiltonian error.
Parameters
 prepNQPauliState
The state that is prepared.
 errorNQPauliOp
The type (as a pauli operator) of Hamiltonian error.
 observableNQPauliOp
The observable whose expectation value is measured. Note: giving a NQPauliState will be treated as an Nqubit Pauli operator whose sign is the product of the signs of the NQPauliState’s perqubit basis signs.
Returns
float
 pygsti.extras.idletomography.stochastic_outcome(prep, error, meas)
Computes the “expected” outcome when the stochastic error error occurs between preparing in prep and measuring in basis meas.
Note: currently, the preparation and measurement bases must be the same (up to signs) or an AssertionError is raised. (If they’re not, there isn’t a single expected outcome).
Parameters
 prepNQPauliState
The state that is prepared.
 errorNQPauliOp
The type (as a pauli operator) of Stochastic error.
 measNQPauliState
The basis which is measured. The ‘signs’ of the basis Paulis determine which state is measured as a ‘0’ vs. a ‘1’. (essentially the POVM.)
Returns
NQOutcome
 pygsti.extras.idletomography.stochastic_jac_element(prep, error, meas, outcome)
Computes the Jacobian matrix element for a Stochastic error: how the probability of outcome changes with respect to the rate of error when preparing state prep and measuring in basis meas.
Parameters
 prepNQPauliState
The state that is prepared.
 errorNQPauliOp
The type (as a pauli operator) of Stochastic error.
 measNQPauliState
The basis that is measured (essentially the POVM).
 outcomeNQOutcome
The measurement outcome that is considered.
Returns
float
 pygsti.extras.idletomography.affine_jac_element(prep, error, meas, outcome)
Computes the Jacobian matrix element for a Affine error: how the probability of outcome changes with respect to the rate of error when preparing state prep and measuring in basis meas.
Note: Affine error maps leave qubits corresponging to I’s in error alone. An affine error is defined as replacing portions of the density matrix corresponding to nontrivial Pauli operators with those operators.
Parameters
 prepNQPauliState
The state that is prepared.
 errorNQPauliOp
The type (as a pauli operator) of Affine error.
 measNQPauliState
The basis that is measured (essentially the POVM).
 outcomeNQOutcome
The measurement outcome that is considered.
Returns
float
 pygsti.extras.idletomography.affine_jac_obs_element(prep, error, observable)
Computes the Jacobian matrix element for a Affine error: how the expectation value of observable changes with respect to the rate of error when preparing state prep.
Note: Affine error maps leave qubits corresponging to I’s in error alone. An affine error is defined as replacing portions of the density matrix corresponding to nontrivial Pauli operators with those operators.
Parameters
 prepNQPauliState
The state that is prepared.
 errorNQPauliOp
The type (as a pauli operator) of Affine error.
 observableNQPauliOp
The observable whose expectation value is measured.
Returns
float
 pygsti.extras.idletomography.idle_tomography_fidpairs(nqubits, maxweight=2, include_hamiltonian=True, include_stochastic=True, include_affine=True, ham_tmpl='auto', preferred_prep_basis_signs=('+', '+', '+'), preferred_meas_basis_signs=('+', '+', '+'))
Construct a list of Paulibasis fiducial pairs for idle tomography.
This function constructs the “standard” set of fiducial pairs used to generate idle tomography sequences which probe Hamiltonian, Stochastic, and/or Affine errors in an idle gate.
Parameters
 nqubitsint
The number of qubits.
 maxweightint, optional
The maximum weight of errors to consider.
 include_hamiltonian, include_stochastic, include_affinebool, optional
Whether to include fiducial pairs for finding Hamiltonian, Stochastic, and Affinetype errors.
 ham_tmpltuple, optional
A tuple of lengthmaxweight Pauli strings (i.e. string w/letters “X”, “Y”, or “Z”), describing how to construct the fiducial pairs used to detect Hamiltonian errors. The special (and default) value “auto” uses (“X”,”Y”,”Z”) and (“ZY”,”ZX”,”XZ”,”YZ”,”YX”,”XY”) for maxweight equal to 1 and 2, repectively, and will generate an error if maxweight > 2.
 preferred_prep_basis_signs, preferred_meas_basis_signs: tuple, optional
A 3tuple of “+” or “” strings indicating which sign for preparing or measuring in the X, Y, and Z bases is preferable. Usually one orientation if preferred because it’s easier to achieve using the native model.
Returns
 list
a list of (prep,meas) 2tuples of NQPauliState objects, each of length nqubits, representing the fiducial pairs.
 pygsti.extras.idletomography.preferred_signs_from_paulidict(pauli_basis_dict)
Infers what the preferred basis signs are based on the length of gatename strings in pauli_basis_dict (shorter strings are preferred).
Parameters
 pauli_basis_dictdict
A dictionary w/keys like “+X” or “Y” and values that are tuples of gate names (not labels, which include qubit or other statespace designations), e.g. (“Gx”,”Gx”).
Returns
 tuple
A 3tuple of elements in {“+”, ““}, exactly the format expected by preferred_*_basis_signs arguments of
idle_tomography_fidpairs()
.
 pygsti.extras.idletomography.fidpairs_to_pauli_fidpairs(fidpairs_list, pauli_basis_dicts, nqubits)
Translate
GatesString
type fiducial pairs toNQPauliState
type “Pauli fiducial pairs” using pauli_basis_dicts.Parameters
 fidpairs_listlist
A list whose elements are 2tuples of
Circuit
objects. pauli_basis_dictstuple
A (prepPauliBasisDict,measPauliBasisDict) tuple of dictionaries specifying the way to prepare and measure in Pauli bases. See
preferred_signs_from_paulidict()
for details on each dictionary’s format. nqubitsint
The number of qubits. Needed because
Circuit
objects don’t contain this information.
Returns
 list
A list of 2tuples of
NQPauliState
objects.
 pygsti.extras.idletomography.determine_paulidicts(model)
Intelligently determine preparation and measurement Pauli basis dictionaries from a
Model
.The returned dictionaries are required for various parts of idle tomography, as they bridge the native model’s gates to the “Pauli basis language” used in idle tomography.
Parameters
 modelModel
The model which defines the available preparation, measurement, and operations. It is assumed that model’s operation are expressed in a Pauliproduct basis.
Returns
 pauli_basis_dicts or None
If successful, a (prepDict,measureDict) 2tuple of Pauli basis dictionaries. If unsuccessful, None.
 pygsti.extras.idletomography.make_idle_tomography_list(nqubits, max_lengths, pauli_basis_dicts, maxweight=2, idle_string=((),), include_hamiltonian=True, include_stochastic=True, include_affine=True, ham_tmpl='auto', preferred_prep_basis_signs='auto', preferred_meas_basis_signs='auto')
Construct the list of experiments needed to perform idle tomography.
Parameters
 nqubitsint
The number of qubits.
 max_lengthslist
A list of maximum germpower lengths. Each specifies a number many times to repeat the idle gate, and typically this is a list of the powers of 2 preceded by zero, e.g. [0,1,2,4,16]. The largest value in this list should be chosen to be the maximum number of idle gates you want to perform in a row (typically limited by performance or time constraints).
 pauli_basis_dictstuple
A (prepPauliBasisDict,measPauliBasisDict) tuple of dictionaries specifying the way to prepare and measure in Pauli bases. See
preferred_signs_from_paulidict()
for details on each dictionary’s format. maxweightint, optional
The maximum weight of errors to consider.
 idle_stringCircuitlike, optional
A Circuit or tuple of operation labels that represents the idle gate being characterized by idle tomography.
 include_hamiltonian, include_stochastic, include_affinebool, optional
Whether to include fiducial pairs for finding Hamiltonian, Stochastic, and Affinetype errors.
 ham_tmpltuple, optional
A tuple of lengthmaxweight Pauli strings (i.e. string w/letters “X”, “Y”, or “Z”), describing how to construct the fiducial pairs used to detect Hamiltonian errors. The special (and default) value “auto” uses (“X”,”Y”,”Z”) and (“ZY”,”ZX”,”XZ”,”YZ”,”YX”,”XY”) for maxweight equal to 1 and 2, repectively, and will generate an error if maxweight > 2.
 preferred_prep_basis_signs, preferred_meas_basis_signs: tuple, optional
A 3tuple of “+” or “” strings indicating which sign for preparing or measuring in the X, Y, and Z bases is preferable. Usually one orientation if preferred because it’s easier to achieve using the native model. Additionally, the special (and default) value “auto” may be used, in which case
preferred_signs_from_paulidict()
is used to choose preferred signs based on pauli_basis_dicts.
Returns
 list
A list of
Circuit
objects.
 pygsti.extras.idletomography.make_idle_tomography_lists(nqubits, max_lengths, pauli_basis_dicts, maxweight=2, idle_string=((),), include_hamiltonian=True, include_stochastic=True, include_affine=True, ham_tmpl='auto', preferred_prep_basis_signs='auto', preferred_meas_basis_signs='auto')
Construct lists of experiments, one for each maximumlength value, needed to perform idle tomography. This is potentiall useful for running GST on idle tomography data.
Parameters
 nqubitsint
The number of qubits.
 max_lengthslist
A list of maximum germpower lengths. Each specifies a number many times to repeat the idle gate, and typically this is a list of the powers of 2 preceded by zero, e.g. [0,1,2,4,16]. The largest value in this list should be chosen to be the maximum number of idle gates you want to perform in a row (typically limited by performance or time constraints).
 pauli_basis_dictstuple
A (prepPauliBasisDict,measPauliBasisDict) tuple of dictionaries specifying the way to prepare and measure in Pauli bases. See
preferred_signs_from_paulidict()
for details on each dictionary’s format. maxweightint, optional
The maximum weight of errors to consider.
 idle_stringCircuitlike, optional
A Circuit or tuple of operation labels that represents the idle gate being characterized by idle tomography.
 include_hamiltonian, include_stochastic, include_affinebool, optional
Whether to include fiducial pairs for finding Hamiltonian, Stochastic, and Affinetype errors.
 ham_tmpltuple, optional
A tuple of lengthmaxweight Pauli strings (i.e. string w/letters “X”, “Y”, or “Z”), describing how to construct the fiducial pairs used to detect Hamiltonian errors. The special (and default) value “auto” uses (“X”,”Y”,”Z”) and (“ZY”,”ZX”,”XZ”,”YZ”,”YX”,”XY”) for maxweight equal to 1 and 2, repectively, and will generate an error if maxweight > 2.
 preferred_prep_basis_signs, preferred_meas_basis_signs: tuple, optional
A 3tuple of “+” or “” strings indicating which sign for preparing or measuring in the X, Y, and Z bases is preferable. Usually one orientation if preferred because it’s easier to achieve using the native model. Additionally, the special (and default) value “auto” may be used, in which case
preferred_signs_from_paulidict()
is used to choose preferred signs based on pauli_basis_dicts.
Returns
 list
A list of lists of
Circuit
objects, one list per maxL value.
 pygsti.extras.idletomography.compute_observed_samebasis_err_rate(dataset, pauli_fidpair, pauli_basis_dicts, idle_string, outcome, max_lengths, fit_order=1)
Extract the observed error rate from a series of experiments which prepares and measures in the same Pauli basis and tracks a particular outcome.
Parameters
 datasetDataSet
The set of data counts (observations) to use.
 pauli_fidpairtuple
A (prep,measure) 2tuple of
NQPauliState
objects specifying the prepation state and measurement basis. pauli_basis_dictstuple
A (prepPauliBasisDict,measPauliBasisDict) tuple of dictionaries specifying the way to prepare and measure in Pauli bases. See
preferred_signs_from_paulidict()
for details on each dictionary’s format. idle_stringCircuit
The Circuit representing the idle operation being characterized.
 outcomeNQOutcome
The outcome being tracked.
 max_lengthslist
A list of maximum germpower lengths. The seriese of sequences considered is prepFiducial + idle_string^L + measFiducial, where L ranges over the values in max_lengths.
 fit_orderint, optional
The polynomial order used to fit the observed data probabilities.
Returns
 dict
A dictionary of information about the fit, including the observed error rate and the data points that were fit.
 pygsti.extras.idletomography.compute_observed_diffbasis_err_rate(dataset, pauli_fidpair, pauli_basis_dicts, idle_string, observable, max_lengths, fit_order=1)
Extract the observed error rate from a series of experiments which prepares and measures in different Pauli basis and tracks the expectation value of a particular observable.
Parameters
 datasetDataSet
The set of data counts (observations) to use.
 pauli_fidpairtuple
A (prep,measure) 2tuple of
NQPauliState
objects specifying the prepation state and measurement basis. pauli_basis_dictstuple
A (prepPauliBasisDict,measPauliBasisDict) tuple of dictionaries specifying the way to prepare and measure in Pauli bases. See
preferred_signs_from_paulidict()
for details on each dictionary’s format. idle_stringCircuit
The Circuit representing the idle operation being characterized.
 observableNQPauliOp
The observable whose expectation value is being tracked.
 max_lengthslist
A list of maximum germpower lengths. The seriese of sequences considered is prepFiducial + idle_string^L + measFiducial, where L ranges over the values in max_lengths.
 fit_orderint, optional
The polynomial order used to fit the observed data probabilities.
Returns
 dict
A dictionary of information about the fit, including the observed error rate and the data points that were fit.
 pygsti.extras.idletomography.do_idle_tomography(nqubits, dataset, max_lengths, pauli_basis_dicts, maxweight=2, idle_string=((),), include_hamiltonian='auto', include_stochastic='auto', include_affine='auto', advanced_options=None, verbosity=0, comm=None)
Analyze dataset using the idle tomography protocol to characterize idle_string.
Parameters
 nqubitsint
The number of qubits.
 datasetDataSet
The set of data counts (observations) to use.
 max_lengthslist
A list of maximum germpower lengths. Each specifies a number many times to repeat the idle gate, and typically this is a list of the powers of 2 preceded by zero, e.g. [0,1,2,4,16]. The largest value in this list should be chosen to be the maximum number of idle gates you want to perform in a row (typically limited by performance or time constraints).
 pauli_basis_dictstuple
A (prepPauliBasisDict,measPauliBasisDict) tuple of dictionaries specifying the way to prepare and measure in Pauli bases. See
preferred_signs_from_paulidict()
for details on each dictionary’s format. maxweightint, optional
The maximum weight of errors to consider.
 idle_stringCircuitlike, optional
A Circuit or tuple of operation labels that represents the idle gate being characterized by idle tomography.
 include_hamiltonian, include_stochastic, include_affine{True,False,”auto”}
Whether to extract Hamiltonian, Stochastic, and Affinetype intrinsic errors. If “auto” is specified, then the corresponding errortype is extracted only if there is enough data to reliably infer them (i.e. enough data to construct “full rank” Jacobian matrices).
 advanced_optionsdict, optional
A dictionary of optional advanced arguments which influence the way idle tomography is performed. Allowed keys are:
“jacobian mode”: {“separate”,”together”} how to evaluate jacobians
“preferred_prep_basis_signs” : 3tuple of “+”/”” or default=”auto”
“preferred_meas_basis_signs” : 3tuple of “+”/”” or default=”auto”
“pauli_fidpairs”: alternate list of pauli fiducial pairs to use
“fit order” : integer order for polynomial fits to data
“ham_tmpl” : see
make_idle_tomography_list()
 verbosityint, optional
How much detail to send to stdout.
 commmpi4py.MPI.Comm, optional
When not None, an MPI communicator for distributing the computation across multiple processors.
Returns
IdleTomographyResults
 class pygsti.extras.idletomography.IdleTomographyIntrinsicErrorsTable(ws, idtresults, display=('H', 'S', 'A'), display_as='boxes')
Bases:
pygsti.report.workspace.WorkspaceTable
A table of all the intrinsic rates found by idle tomography.
Create a IdleTomographyIntrinsicErrorsTable.
Parameters
 idtresultsIdleTomographyResults
The idle tomography results object from which to extract observedrate data.
 displaytuple of {“H”,”S”,”A”}
Specifes which columns to include: the intrinsic Hamiltonian, Stochastic, and/or Affine errors. Note that if an error type is not included in idtresults it’s column will not be displayed regardless of the value of display.
 display_as{“numbers”, “boxes”}, optional
How to display the matrices, as either numerical grids (fine for small matrices) or as a plot of colored boxes (spaceconserving and better for large matrices).
Returns
ReportTable
 class pygsti.extras.idletomography.IdleTomographyObservedRatesTable(ws, idtresults, threshold=1.0, mdl_simulator=None)
Bases:
pygsti.report.workspace.WorkspaceTable
A table of the largest N (in absolute value) observed error rates.
Create a IdleTomographyObservedRatesTable object.
Parameters
 idtresultsIdleTomographyResults
The idle tomography results object from which to extract observedrate data.
 thresholdint or float
Specifies how many observed error rates to display. If an integer, display the top threshold rates. If a float, display the top threshold fraction of all the rates (e.g. 0.2 will show the to 20%).
 mdl_simulatorModel, optional
If not None, use this Model to simulate the observed data points and plot these simulated values alongside the data.
Returns
ReportTable
 class pygsti.extras.idletomography.IdleTomographyObservedRatePlot(ws, idtresults, typ, fidpair, obs_or_outcome, title='auto', scale=1.0, mdl_simulator=None)
Bases:
pygsti.report.workspace.WorkspacePlot
A plot showing how an observed error rate is obtained by fitting a sequence of observed data to a simple polynomial.
Create a IdleTomographyObservedRatePlot.
Parameters
 idtresultsIdleTomographyResults
The idle tomography results object from which to extract observedrate data.
 typ{“samebasis”,”diffbasis”}
The type of observedrate: samebasis or definiteoutcome rates prepare and measure in the same Pauli basis. Other rates prepare and measure in different bases, and so have nondefiniteoutcomes.
 fidpairtuple
A (prep,measure) 2tuple of
NQPauliState
objects specifying the fiducial pair (a constant) for the data used to obtain the observed rate being plotted. obs_or_outcomeNQPauliOp or NQOutcome
The observable (if typ == “diffbasis”) or outcome (if typ == “samebasis”) identifying the observed rate to plot.
 titlestr, optional
The plot title to use. If “auto”, then one is created based on the parameters.
 scalefloat, optional
Scaling factor to adjust the size of the final figure.
 mdl_simulatorModel, optional
If not None, use this Model to simulate the observed data points and plot these simulated values alongside the data.
 class pygsti.extras.idletomography.IdleTomographyObservedRatesForIntrinsicRateTable(ws, idtresults, typ, error_op, threshold=1.0, mdl_simulator=None)
Bases:
pygsti.report.workspace.WorkspaceTable
A table showing the observed error rates relevant for determining a particular intrinsic rate. Output can be limited to just the largest observed rates.
Create a IdleTomographyObservedRatesForIntrinsicRateTable.
Parameters
 idtresultsIdleTomographyResults
The idle tomography results object from which to extract observedrate data.
 typ{“hamiltonian”, “stochastic”, “affine”}
The type of the intrinsic rate to target.
 error_opNQPauliOp
The intrinsic error (of the given typ), specified as a Nqubit Pauli operator.
 thresholdint or float
Specifies how many observed error rates to consider. If an integer, display the top threshold rates of all the observed rates. For example, if threshold=10 and none of the top 10 rates are applicable to the given typ,`error_op` error, then nothing is displayed. If a float, display the top threshold fraction, again of all the rates (e.g. 0.2 means the top 20%).
 mdl_simulatorModel, optional
If not None, use this Model to simulate the observed data points and plot these simulated values alongside the data.
Returns
ReportTable
 pygsti.extras.idletomography.create_idletomography_report(results, filename, title='auto', ws=None, auto_open=False, link_to=None, brevity=0, advanced_options=None, verbosity=1)
Creates an Idle Tomography report, summarizing the results of running idle tomography on a data set.
Parameters
 resultsIdleTomographyResults
An object which represents the set of results from an idle tomography run, typically obtained from running
do_idle_tomography()
OR a dictionary of such objects, representing multiple idle tomography runs to be compared (typically all with different data sets). The keys of this dictionary are used to label different data sets that are selectable in the report. filenamestring, optional
The output filename where the report file(s) will be saved. If None, then no output file is produced (but returned Workspace still caches all intermediate results).
 titlestring, optional
The title of the report. “auto” causes a random title to be generated (which you may or may not like).
 wsWorkspace, optional
The workspace used as a scratch space for performing the calculations and visualizations required for this report. If you’re creating multiple reports with similar tables, plots, etc., it may boost performance to use a single Workspace for all the report generation.
 auto_openbool, optional
If True, automatically open the report in a web browser after it has been generated.
 link_tolist, optional
If not None, a list of one or more items from the set {“tex”, “pdf”, “pkl”} indicating whether or not to create and include links to Latex, PDF, and Python pickle files, respectively. “tex” creates latex source files for tables; “pdf” renders PDFs of tables and plots ; “pkl” creates Python versions of plots (pickled python data) and tables (pickled pandas DataFrams).
 advanced_optionsdict, optional
A dictionary of advanced options for which the default values aer usually are fine. Here are the possible keys of advanced_options:
 connectedbool, optional
Whether output HTML should assume an active internet connection. If True, then the resulting HTML file size will be reduced because it will link to web resources (e.g. CDN libraries) instead of embedding them.
 cachefilestr, optional
filename with cached workspace results
 precisionint or dict, optional
The amount of precision to display. A dictionary with keys “polar”, “sci”, and “normal” can separately specify the precision for complex angles, numbers in scientific notation, and everything else, respectively. If an integer is given, it this same value is taken for all precision types. If None, then {‘normal’: 6, ‘polar’: 3, ‘sci’: 0} is used.
 resizablebool, optional
Whether plots and tables are made with resize handles and can be resized within the report.
 autosize{‘none’, ‘initial’, ‘continual’}
Whether tables and plots should be resized, either initially – i.e. just upon first rendering (“initial”) – or whenever the browser window is resized (“continual”).
 verbosityint, optional
How much detail to send to stdout.
Returns
 Workspace
The workspace object used to create the report
 class pygsti.extras.idletomography.IdleTomographyResults(dataset, max_lengths, max_error_weight, fit_order, pauli_dicts, idle_str, error_list, intrinsic_rates, pauli_fidpairs, observed_rate_infos)
Bases:
object
A container for idle tomography results: intrinsic and observable errors, along with supporting information.
Create a IdleTomographyResults object.
Parameters
 datasetDataSet
The dataset that was analyzed, containing the observed counts.
 max_lengthslist
The series of maximum lengths used.
 max_error_weightint
The maximum error weight.
 fit_orderint
The order of the polynomial fits used.
 pauli_dictstuple
A 2tuple of (prepDict,measDict) Pauli basis dictionaries.
 idle_strCircuit
The idle operation that was characterized.
 error_listlist
A list of
NQPauliOp
objects describing the errors Paulis considered for each intrinsicerror type. intrinsic_ratesdict
A dictionary of the intrinsic rates. Keys are intrinsicratetypes, i.e. ‘hamiltonian’, ‘stochastic’, or ‘affine’. Values are numpy arrays of length len(error_list).
 pauli_fidpairsdict
A dictionary of the paulistate fiducial pairs. Keys are observedratetypes, i.e. ‘samebasis’ or ‘diffbasis’, and values are lists of (prep,meas) 2tuples of
NQPauliState
objects. observed_rate_infosdict
A dictionary of observedrate information dictionaries. Keys are observedratetypes, i.e. ‘samebasis’ or ‘diffbasis’, and values are further dictionaries indexed by fiducial pair (i.e. an element of pauli_fidpairs, then either a
NQOutcome
(for the “samebasis” case) orNQPauliOp
(for “diffbasis”) case. After these two indexes, the value is another dictionary of information about the observeable rate so defined. So, to get to an actual “info dict” you need to do something like: observed_rate_infos[typ][fidpair][obsORoutcome]
 pygsti.extras.idletomography.alloutcomes(prep, meas, maxweight)
Lists every “error bit string” that co1uld be caused by an error of weight up to maxweight when performing prep & meas (must be in same basis, but may have different signs).
Parameters
prep, meas : NQPauliState
maxweight : int
Returns
 list
A list of
NQOutcome
objects.
 pygsti.extras.idletomography.allerrors(nqubits, maxweight)
Lists every Pauli error operator for nqubits qubits with weight <= maxweight
Parameters
nqubits, maxweight : int
Returns
 list
A list of
NQPauliOp
objects.
 pygsti.extras.idletomography.allobservables(meas, maxweight)
Lists every weight <= maxweight observable whose expectation value can be extracted from the local Pauli measurement described by meas.
Parameters
meas : NQPauliState
maxweight : int
Returns
 list
A list of
NQPauliOp
objects.
 pygsti.extras.idletomography.tile_pauli_fidpairs(base_fidpairs, nqubits, maxweight)
Tiles a set of base fiducial pairs on maxweight qubits to a set of fiducial pairs on nqubits qubits such that every set of maxweight qubits takes on the values in each base pair in at least one of the returned pairs.
Parameters
 base_fidpairslist
A list of 2tuples of
NQPauliState
objects (on maxweight qubits). nqubitsint
The number of qubits.
 maxweightint
The maximum weight errors the base qubits are meant to detect. Equal to the number of qubits in the base pairs.
Returns
 list
A list of 2tuples of
NQPauliState
objects (on nqubits qubits).
 pygsti.extras.idletomography.nontrivial_paulis(wt)
List all nontrivial paulis of given weight wt.
Parameters
wt : int
Returns
 list
A list of tuples of ‘X’, ‘Y’, and ‘Z’, e.g. (‘X’,’Z’).
 pygsti.extras.idletomography.set_idle_errors(nqubits, model, errdict, rand_default=None, hamiltonian=True, stochastic=True, affine=True)
Set specific or random error terms (typically for a datagenerating model) within a noise model (a
CloudNoiseModel
object).Parameters
 nqubitsint
The number of qubits.
 modelCloudNoiseModel
The model, to set the idle errors of.
 errdictdict
A dictionary of errors to include. Keys are “S(<>)”, “H(<>)”, and “A(<>)” where <> is a string of ‘X’,’Y’,’Z’,and ‘I’ (e.g. “S(XIZ)”) and values are floating point error rates.
 rand_defaultfloat or numpy array, optional
Random error rates to insert into values not specified in errdict. If a floating point number, a random value between 0 and rand_default is used. If an array, then values are taken directly and sequentially from this array (typically of random rates). The array must be long enough to provide values for all unspecified rates.
 hamiltonian, stochastic, affinebool, optional
Whether model includes Hamiltonian, Stochastic, and/or Affine errors (e.g. if the model was built with “H+S” parameterization, then only hamiltonian and stochastic should be set to True).
Returns
 numpy.ndarray
The random rates the were used.
 pygsti.extras.idletomography.extract_idle_errors(nqubits, model, hamiltonian=True, stochastic=True, affine=True, scale_for_idt=True)
Get error rates on the global idle operation within a
CloudNoiseModel
object.Parameters
 nqubitsint
The number of qubits.
 modelCloudNoiseModel
The model, to get the idle errors of.
 hamiltonian, stochastic, affinebool, optional
Whether model includes Hamiltonian, Stochastic, and/or Affine errors (e.g. if the model was built with “H+S” parameterization, then only hamiltonian and stochastic should be set to True).
 scale_for_idtbool, optional
Whether rates should be scaled to match the intrinsic rates output by idle tomography. If False, then the rates are simply the coefficients of corresponding terms in the error generator.
Returns
 hamiltonian_rates, stochastic_rates, affine_ratesdict
Dictionaries of error rates. Keys are Pauli labels of length nqubits, e.g. “XIX”, “IIX”, “XZY”. Only nonzero rates are returned.
 pygsti.extras.idletomography.predicted_intrinsic_rates(nqubits, maxweight, model, hamiltonian=True, stochastic=True, affine=True)
Get the exact intrinsic rates that would be produced by simulating model (for comparison with idle tomography results).
Parameters
 nqubitsint
The number of qubits.
 maxweightint, optional
The maximum weight of errors to consider.
 modelCloudNoiseModel
The model to extract intrinsic error rates from.
 hamiltonian, stochastic, affinebool, optional
Whether model includes Hamiltonian, Stochastic, and/or Affine errors (e.g. if the model was built with “H+S” parameterization, then only hamiltonian and stochastic should be set to True).
Returns
 ham_intrinsic_rates, sto_intrinsic_rates, aff_intrinsic_ratesnumpy.ndarray
Arrays of intrinsic rates. None if corresponding hamiltonian, stochastic or affine is set to False.
 pygsti.extras.idletomography.predicted_observable_rates(idtresults, typ, nqubits, maxweight, model)
Get the exact observable rates that would be produced by simulating model (for comparison with idle tomography results).
Parameters
 idtresultsIdleTomographyResults
The idle tomography results object used to determing which observable rates should be computed, and the provider of the Jacobian relating the intrinsic rates internal to model to these observable rates.
 typ{“samebasis”,”diffbasis”}
The type of observable rates to predict and return.
 nqubitsint
The number of qubits.
 maxweightint
The maximum weight of errors to consider.
 modelCloudNoiseModel
The noise model to extract error rates from.
Returns
 ratesdict
A dictionary of the form: rate = rates[pauli_fidpair][obsORoutcome], to match the structure of an IdleTomographyResults object’s `
 class pygsti.extras.idletomography.NQPauliState(string_rep, signs=None)
Bases:
object
A Nqubit state that is the tensor product of N 1qubit Pauli eigenstates. These can be represented as a string of Xs, Ys and Zz (but not Is) each with a +/ sign indicating which of the two eigenstates is meant.
A NQPauliState object can also be used to represent a POVM whose effects are the projections onto the 2^N tensor products of (the given) Pauli eigenstates. The +/ sign in this case indicates which eigenstate is equated with the “0” (vs “1”) outcome.
Create a NQPauliState
Parameters
 string_repstr
A string with letters in {X,Y,Z} (note: I is not allowed!), specifying the Pauli basis for each qubit.
 signstuple, optional
A tuple of 0s and/or 1s. A zero means the “+” eigenvector is either prepared or corresponds to the “0” outcome (if this NQPauliState is used to describe a measurment basis). A one means the opposite: the “” eigenvector is prepared and it corresponds to a “0” outcome. The default is all zeros.
 to_circuit(pauli_basis_dict)
Convert this Pauli basis state or measurement to a fiducial operation sequence.
When the returned operation sequence follows a preparation in the 0…0> Zbasis state or is followed by a Zbasis measurement (with all “+” signs), then the Pauli state preparation or measurement described by this object will be performed.
Parameters
 pauli_basis_dictdict
A dictionary w/keys like “+X” or “Y” and values that are tuples of gate names (not labels, which include qubit or other statespace designations), e.g. (“Gx”,”Gx”). This dictionary describes how to prepare or measure in Pauli bases.
Returns
Circuit
 class pygsti.extras.idletomography.NQPauliOp(string_rep, sign=1)
Bases:
object
A Nqubit pauli operator, consisting of a 1qubit Pauli operation on each qubits.
Create a NQPauliOp.
Parameters
 string_repstr
A string with letters in {I,X,Y,Z}, specifying the Pauli operator for each qubit.
 sign{1, 1}
An overall sign (prefactor) for this operator.
 classmethod weight_1_pauli(n, i, pauli)
Creates a nqubit Pauli operator with the Pauli indexed by pauli in location i.
Parameters
 nint
The number of qubits
 iint
The index of the single nontrivial Pauli operator.
 pauliint
An integer 0 <= P <= 2 indexing the nontrivial Pauli at location i as follows: 0=’X’, 1=’Y’, 2=’Z’.
Returns
NQPauliOp
 classmethod weight_2_pauli(n, i, j, pauli1, pauli2)
Creates a nqubit Pauli operator with the Paulis indexed by pauli1 and pauli2 in locations i and j respectively.
Parameters
 nint
The number of qubits
 i, jint
The indices of the nontrivial Pauli operators.
 pauli1,pauli2int
Integers 0 <= pauli <= 2 indexing the nontrivial Paulis at locations i and j, respectively, as follows: 0=’X’, 1=’Y’, 2=’Z’.
Returns
NQPauliOp
 subpauli(indices)
Returns a new NQPauliOp object which sets all (1qubit) operators to “I” except those in indices, which remain as they are in this object.
Parameters
 indicesiterable
A sequence of integer indices between 0 and N1, where N is the number of qubits in this pauli operator.
Returns
NQPauliOp
 dot(other)
Computes the HilbertSchmidt dot product (normed to 1) between this Pauli operator and other.
Parameters
 otherNQPauliOp
The other operator to take a dot product with.
Returns
 integer
Either 0, 1, or 1.
 statedot(state)
Computes a dot product between state and this operator. (note that an Xbasis ‘+’ state is represented by (I+X) not just X)
Parameters
state : NQPauliState
Returns
int
 commuteswith(other)
Determine whether this operator commutes (or anticommutes) with other.
Parameters
other : NQPauliOp
Returns
bool
 icommutator_over_2(other)
Compute i[self, other]/2 where [,] is the commutator.
Parameters
 otherNQPauliOp or NQPauliState
The operator to take a commutator with. A NQPauliState is treated as an operator (i.e. ‘X’ basis state => ‘X’ Pauli operation) with sign given by the product of its 1qubit basis signs.
Returns
NQPauliOp
 class pygsti.extras.idletomography.NQOutcome(string_rep)
Bases:
object
A string of 0’s and 1’s representing a definite outcome in the Zbasis.
Create a NQOutcome.
Parameters
 string_repstr
A string of 0s and 1s, one per qubit, e.g. “0010”.
 classmethod weight_1_string(n, i)
creates a nbit string with a 1 in location i.
 classmethod weight_2_string(n, i, j)
creates a nbit string with 1s in locations i and j.