pygsti.extras.idletomography.idtcore¶

Core Idle Tomography routines

Module Contents¶

Functions¶

 hamiltonian_jac_element(prep, error, observable) Computes the Jacobian matrix element for a Hamiltonian error: how the stochastic_outcome(prep, error, meas) Computes the "expected" outcome when the stochastic error error stochastic_jac_element(prep, error, meas, outcome) Computes the Jacobian matrix element for a Stochastic error: how the affine_jac_element(prep, error, meas, outcome) Computes the Jacobian matrix element for a Affine error: how the affine_jac_obs_element(prep, error, observable) Computes the Jacobian matrix element for a Affine error: how the 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 Pauli-basis fiducial pairs for idle tomography. preferred_signs_from_paulidict(pauli_basis_dict) Infers what the preferred basis signs are based on the length of gate-name fidpairs_to_pauli_fidpairs(fidpairs_list, pauli_basis_dicts, nqubits) Translate GatesString-type fiducial pairs to determine_paulidicts(model) Intelligently determine preparation and measurement Pauli basis make_idle_tomography_list(nqubits, max_lenghts, 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. make_idle_tomography_lists(nqubits, max_lenghts, 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 maximum-length value, needed compute_observed_samebasis_err_rate(dataset, pauli_fidpair, pauli_basis_dicts, idle_string, outcome, max_lenghts, fit_order=1) Extract the observed error rate from a series of experiments which prepares compute_observed_diffbasis_err_rate(dataset, pauli_fidpair, pauli_basis_dicts, idle_string, observable, max_lenghts, fit_order=1) Extract the observed error rate from a series of experiments which prepares do_idle_tomography(nqubits, dataset, max_lenghts, 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
pygsti.extras.idletomography.idtcore.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
• prep (NQPauliState) – The state that is prepared.

• error (NQPauliOp) – The type (as a pauli operator) of Hamiltonian error.

• observable (NQPauliOp) – The observable whose expectation value is measured. Note: giving a NQPauliState will be treated as an N-qubit Pauli operator whose sign is the product of the signs of the NQPauliState’s per-qubit basis signs.

Returns

float

pygsti.extras.idletomography.idtcore.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
• prep (NQPauliState) – The state that is prepared.

• error (NQPauliOp) – The type (as a pauli operator) of Stochastic error.

• meas (NQPauliState) – 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.idtcore.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
• prep (NQPauliState) – The state that is prepared.

• error (NQPauliOp) – The type (as a pauli operator) of Stochastic error.

• meas (NQPauliState) – The basis that is measured (essentially the POVM).

• outcome (NQOutcome) – The measurement outcome that is considered.

Returns

float

pygsti.extras.idletomography.idtcore.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 non-trivial Pauli operators with those operators.

Parameters
• prep (NQPauliState) – The state that is prepared.

• error (NQPauliOp) – The type (as a pauli operator) of Affine error.

• meas (NQPauliState) – The basis that is measured (essentially the POVM).

• outcome (NQOutcome) – The measurement outcome that is considered.

Returns

float

pygsti.extras.idletomography.idtcore.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 non-trivial Pauli operators with those operators.

Parameters
• prep (NQPauliState) – The state that is prepared.

• error (NQPauliOp) – The type (as a pauli operator) of Affine error.

• observable (NQPauliOp) – The observable whose expectation value is measured.

Returns

float

pygsti.extras.idletomography.idtcore.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 Pauli-basis 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
• nqubits (int) – The number of qubits.

• maxweight (int, optional) – The maximum weight of errors to consider.

• include_hamiltonian (bool, optional) – Whether to include fiducial pairs for finding Hamiltonian-, Stochastic-, and Affine-type errors.

• include_stochastic (bool, optional) – Whether to include fiducial pairs for finding Hamiltonian-, Stochastic-, and Affine-type errors.

• include_affine (bool, optional) – Whether to include fiducial pairs for finding Hamiltonian-, Stochastic-, and Affine-type errors.

• ham_tmpl (tuple, optional) – A tuple of length-maxweight 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 (tuple, optional) – A 3-tuple 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.

• preferred_meas_basis_signs (tuple, optional) – A 3-tuple 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) 2-tuples of NQPauliState objects, each of length nqubits, representing the fiducial pairs.

pygsti.extras.idletomography.idtcore.preferred_signs_from_paulidict(pauli_basis_dict)

Infers what the preferred basis signs are based on the length of gate-name strings in pauli_basis_dict (shorter strings are preferred).

Parameters

pauli_basis_dict (dict) – A dictionary w/keys like “+X” or “-Y” and values that are tuples of gate names (not labels, which include qubit or other state-space designations), e.g. (“Gx”,”Gx”).

Returns

tuple – A 3-tuple of elements in {“+”, “-“}, exactly the format expected by preferred_*_basis_signs arguments of :function:`idle_tomography_fidpairs`.

pygsti.extras.idletomography.idtcore.fidpairs_to_pauli_fidpairs(fidpairs_list, pauli_basis_dicts, nqubits)

Translate GatesString-type fiducial pairs to NQPauliState-type “Pauli fiducial pairs” using pauli_basis_dicts.

Parameters
• fidpairs_list (list) – A list whose elements are 2-tuples of Circuit objects.

• pauli_basis_dicts (tuple) – A (prepPauliBasisDict,measPauliBasisDict) tuple of dictionaries specifying the way to prepare and measure in Pauli bases. See :function:`preferred_signs_from_paulidict` for details on each dictionary’s format.

• nqubits (int) – The number of qubits. Needed because Circuit objects don’t contain this information.

Returns

list – A list of 2-tuples of NQPauliState objects.

pygsti.extras.idletomography.idtcore.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

model (Model) – The model which defines the available preparation, measurement, and operations. It is assumed that model’s operation are expressed in a Pauli-product basis.

Returns

pauli_basis_dicts or None – If successful, a (prepDict,measureDict) 2-tuple of Pauli basis dictionaries. If unsuccessful, None.

pygsti.extras.idletomography.idtcore.make_idle_tomography_list(nqubits, max_lenghts, 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
• nqubits (int) – The number of qubits.

• max_lenghts (list) – A list of maximum germ-power 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_dicts (tuple) – A (prepPauliBasisDict,measPauliBasisDict) tuple of dictionaries specifying the way to prepare and measure in Pauli bases. See :function:`preferred_signs_from_paulidict` for details on each dictionary’s format.

• maxweight (int, optional) – The maximum weight of errors to consider.

• idle_string (Circuit-like, optional) – A Circuit or tuple of operation labels that represents the idle gate being characterized by idle tomography.

• include_hamiltonian (bool, optional) – Whether to include fiducial pairs for finding Hamiltonian-, Stochastic-, and Affine-type errors.

• include_stochastic (bool, optional) – Whether to include fiducial pairs for finding Hamiltonian-, Stochastic-, and Affine-type errors.

• include_affine (bool, optional) – Whether to include fiducial pairs for finding Hamiltonian-, Stochastic-, and Affine-type errors.

• ham_tmpl (tuple, optional) – A tuple of length-maxweight 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 (tuple, optional) – A 3-tuple 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 :function:`preferred_signs_from_paulidict` is used to choose preferred signs based on pauli_basis_dicts.

• preferred_meas_basis_signs (tuple, optional) – A 3-tuple 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 :function:`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.idtcore.make_idle_tomography_lists(nqubits, max_lenghts, 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 maximum-length value, needed to perform idle tomography. This is potentiall useful for running GST on idle tomography data.

Parameters
• nqubits (int) – The number of qubits.

• max_lenghts (list) – A list of maximum germ-power 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_dicts (tuple) – A (prepPauliBasisDict,measPauliBasisDict) tuple of dictionaries specifying the way to prepare and measure in Pauli bases. See :function:`preferred_signs_from_paulidict` for details on each dictionary’s format.

• maxweight (int, optional) – The maximum weight of errors to consider.

• idle_string (Circuit-like, optional) – A Circuit or tuple of operation labels that represents the idle gate being characterized by idle tomography.

• include_hamiltonian (bool, optional) – Whether to include fiducial pairs for finding Hamiltonian-, Stochastic-, and Affine-type errors.

• include_stochastic (bool, optional) – Whether to include fiducial pairs for finding Hamiltonian-, Stochastic-, and Affine-type errors.

• include_affine (bool, optional) – Whether to include fiducial pairs for finding Hamiltonian-, Stochastic-, and Affine-type errors.

• ham_tmpl (tuple, optional) – A tuple of length-maxweight 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 (tuple, optional) – A 3-tuple 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 :function:`preferred_signs_from_paulidict` is used to choose preferred signs based on pauli_basis_dicts.

• preferred_meas_basis_signs (tuple, optional) – A 3-tuple 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 :function:`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 max-L value.

pygsti.extras.idletomography.idtcore.compute_observed_samebasis_err_rate(dataset, pauli_fidpair, pauli_basis_dicts, idle_string, outcome, max_lenghts, 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
• dataset (DataSet) – The set of data counts (observations) to use.

• pauli_fidpair (tuple) – A (prep,measure) 2-tuple of NQPauliState objects specifying the prepation state and measurement basis.

• pauli_basis_dicts (tuple) – A (prepPauliBasisDict,measPauliBasisDict) tuple of dictionaries specifying the way to prepare and measure in Pauli bases. See :function:`preferred_signs_from_paulidict` for details on each dictionary’s format.

• idle_string (Circuit) – The Circuit representing the idle operation being characterized.

• outcome (NQOutcome) – The outcome being tracked.

• max_lenghts (list) – A list of maximum germ-power lengths. The seriese of sequences considered is prepFiducial + idle_string^L + measFiducial, where L ranges over the values in max_lenghts.

• fit_order (int, 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.idtcore.compute_observed_diffbasis_err_rate(dataset, pauli_fidpair, pauli_basis_dicts, idle_string, observable, max_lenghts, 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
• dataset (DataSet) – The set of data counts (observations) to use.

• pauli_fidpair (tuple) – A (prep,measure) 2-tuple of NQPauliState objects specifying the prepation state and measurement basis.

• pauli_basis_dicts (tuple) – A (prepPauliBasisDict,measPauliBasisDict) tuple of dictionaries specifying the way to prepare and measure in Pauli bases. See :function:`preferred_signs_from_paulidict` for details on each dictionary’s format.

• idle_string (Circuit) – The Circuit representing the idle operation being characterized.

• observable (NQPauliOp) – The observable whose expectation value is being tracked.

• max_lenghts (list) – A list of maximum germ-power lengths. The seriese of sequences considered is prepFiducial + idle_string^L + measFiducial, where L ranges over the values in max_lenghts.

• fit_order (int, 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.idtcore.do_idle_tomography(nqubits, dataset, max_lenghts, 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
• nqubits (int) – The number of qubits.

• dataset (DataSet) – The set of data counts (observations) to use.

• max_lenghts (list) – A list of maximum germ-power 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_dicts (tuple) – A (prepPauliBasisDict,measPauliBasisDict) tuple of dictionaries specifying the way to prepare and measure in Pauli bases. See :function:`preferred_signs_from_paulidict` for details on each dictionary’s format.

• maxweight (int, optional) – The maximum weight of errors to consider.

• idle_string (Circuit-like, optional) – A Circuit or tuple of operation labels that represents the idle gate being characterized by idle tomography.

• include_hamiltonian ({True,False,"auto"}) – Whether to extract Hamiltonian-, Stochastic-, and Affine-type intrinsic errors. If “auto” is specified, then the corresponding error-type is extracted only if there is enough data to reliably infer them (i.e. enough data to construct “full rank” Jacobian matrices).

• include_stochastic ({True,False,"auto"}) – Whether to extract Hamiltonian-, Stochastic-, and Affine-type intrinsic errors. If “auto” is specified, then the corresponding error-type is extracted only if there is enough data to reliably infer them (i.e. enough data to construct “full rank” Jacobian matrices).

• include_affine ({True,False,"auto"}) – Whether to extract Hamiltonian-, Stochastic-, and Affine-type intrinsic errors. If “auto” is specified, then the corresponding error-type is extracted only if there is enough data to reliably infer them (i.e. enough data to construct “full rank” Jacobian matrices).

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” : 3-tuple of “+”/”-” or default=”auto”

• ”preferred_meas_basis_signs” : 3-tuple 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 :function:`make_idle_tomography_list`

• verbosity (int, optional) – How much detail to send to stdout.

• comm (mpi4py.MPI.Comm, optional) – When not None, an MPI communicator for distributing the computation across multiple processors.

Returns

IdleTomographyResults