pygsti.extras.rpe
Robubst Phase Estimation Sub-package
Submodules
Package Contents
Classes
Encapsulates a collection of settings for an RPE run. Provides full specifications, |
Functions
|
Make a model for simulating RPE, paramaterized by rotation angles. Note |
|
Make cosine and sine circuit lists. These operation sequences are used to estimate the angle specified |
|
Generates a dictionary that contains operation sequences for all RPE cosine and |
|
Generate a fake RPE DataSet using the probabilities obtained from a model. |
|
For a single germ generation (k value), estimate the angle of rotation |
|
For a dataset containing sin and cos strings to estimate either alpha, |
|
For a dataset containing sin and cos strings to estimate theta, |
|
For a given model, obtain the angle of rotation about the "fixed axis" |
|
For a given model, obtain the angle of rotation about the "loose axis" |
|
For a given model, obtain the angle between the estimated "loose axis" and |
|
Check internal consistency |
|
Compute angle estimates and compare to true or target values for alpha, epsilon, |
- class pygsti.extras.rpe.RPEconfig(input_dict)
Encapsulates a collection of settings for an RPE run. Provides full specifications, including target gates, SPAM, sine and cosine strings for alpha, epsilon, and theta.
- pygsti.extras.rpe.create_parameterized_rpe_model(alpha_true, epsilon_true, aux_rot, spam_depol, gate_depol=None, with_id=True, rpeconfig_inst=None)
Make a model for simulating RPE, paramaterized by rotation angles. Note that the output model also has thetaTrue, alpha_true, and epsilon_true added attributes.
Parameters
- alpha_truefloat
Angle of rotation about “fixed axis”
- epsilon_truefloat
Angle of rotation about “loose axis”
- aux_rotfloat
Angle of rotation about the axis perpendicular to fixed and loose axes, that, by similarity transformation, changes loose axis.
- spam_depolfloat
Amount to depolarize SPAM by.
- gate_depolfloat, optional
Amount to depolarize gates by (defaults to None).
- with_idbool, optional
Do we include (perfect) identity or no identity? (Defaults to False; should be False for RPE, True for GST)
- rpeconfig_instRPEconfig object
Declares which model configuration RPE should be trying to fit; determines particular functions and values to be used.
Returns
- Model
The desired model for RPE; model also has attributes thetaTrue, alpha_true, and epsilon_true, automatically extracted.
- pygsti.extras.rpe.create_rpe_angle_circuit_lists(k_list, angle_name, rpeconfig_inst)
Make cosine and sine circuit lists. These operation sequences are used to estimate the angle specified by angle_name (‘alpha’, ‘epsilon’, or ‘theta’)
Parameters
- k_listlist of ints
The list of “germ powers” to be used. Typically successive powers of two; e.g. [1,2,4,8,16].
- angle_namestring
The angle to be deduced from these operation sequences. (Choices are ‘alpha’, ‘epsilon’, or ‘theta’)
- rpeconfig_instRPEconfig object
Declares which model configuration RPE should be trying to fit; determines particular functions and values to be used.
Returns
- cosStrListlist of Circuits
The list of “cosine strings” to be used for alpha estimation.
- sinStrListlist of Circuits
The list of “sine strings” to be used for alpha estimation.
- pygsti.extras.rpe.create_rpe_angle_circuits_dict(log2k_max_or_k_list, rpeconfig_inst)
Generates a dictionary that contains operation sequences for all RPE cosine and sine experiments for all three angles.
Parameters
- log2k_max_or_k_listint or list
int - log2(Maximum number of times to repeat an RPE germ) list - List of maximum number of times to repeat an RPE germ
- rpeconfig_instRPEconfig object
Declares which model configuration RPE should be trying to fit; determines particular functions and values to be used.
Returns
- totalStrListDdict
A dictionary containing all operation sequences for all sine and cosine experiments for alpha, epsilon, and theta. The keys of the returned dictionary are:
‘alpha’,’cos’ : List of operation sequences for cosine experiments used to determine alpha.
‘alpha’,’sin’ : List of operation sequences for sine experiments used to determine alpha.
- ‘epsilon’,’cos’List of operation sequences for cosine experiments used to
determine epsilon.
‘epsilon’,’sin’ : List of operation sequences for sine experiments used to determine epsilon.
‘theta’,’cos’ : List of operation sequences for cosine experiments used to determine theta.
‘theta’,’sin’ : List of operation sequences for sine experiments used to determine theta.
‘totalStrList’ : All above operation sequences combined into one list; duplicates removed.
- pygsti.extras.rpe.create_rpe_dataset(model_or_dataset, string_list_d, n_samples, sample_error='binomial', seed=None)
Generate a fake RPE DataSet using the probabilities obtained from a model. Is a thin wrapper for pygsti.data.simulate_data, changing default behavior of sample_error, and taking a dictionary of operation sequences as input.
Parameters
- model_or_datasetModel or DataSet object
If a Model, the model whose probabilities generate the data. If a DataSet, the data set whose frequencies generate the data.
- string_list_dDictionary of list of (tuples or Circuits)
Each tuple or Circuit contains operation labels and specifies a gate sequence whose counts are included in the returned DataSet. The dictionary must have the key ‘totalStrList’; easiest if this dictionary is generated by make_rpe_string_list_d.
- n_samplesint or list of ints or None
The simulated number of samples for each operation sequence. This only has effect when sample_error == “binomial” or “multinomial”. If an integer, all operation sequences have this number of total samples. If a list, integer elements specify the number of samples for the corresponding operation sequence. If None, then model_or_dataset must be a DataSet, and total counts are taken from it (on a per-circuit basis).
- sample_errorstring, optional
What type of sample error is included in the counts. Can be:
“none” - no sample error: counts are floating point numbers such that the exact probabilty can be found by the ratio of count / total.
“round” - same as “none”, except counts are rounded to the nearest integer.
“binomial” - the number of counts is taken from a binomial distribution. Distribution has parameters p = probability of the operation sequence and n = number of samples. This can only be used when there are exactly two outcome labels in model_or_dataset.
“multinomial” - counts are taken from a multinomial distribution. Distribution has parameters p_k = probability of the operation sequence using the k-th outcome label and n = number of samples. This should not be used for RPE.
- seedint, optional
If not None, a seed for numpy’s random number generator, which is used to sample from the binomial or multinomial distribution.
Returns
- DataSet
A static data set filled with counts for the specified operation sequences.
- pygsti.extras.rpe.extract_rotation_hat(xhat, yhat, k, nx, ny, angle_name='epsilon', previous_angle=None, rpeconfig_inst=None)
For a single germ generation (k value), estimate the angle of rotation for either alpha, epsilon, or Phi. (Warning: Do not use for theta estimate without further processing!)
Parameters
- xhatfloat
The number of 0 counts for the sin string being used.
- yhatfloat
The number of 0 counts for the cos string being used.
- kfloat
The generation of experiments that xhat and yhat come from.
- nxfloat
The number of sin string clicks.
- nyfloat
The number cos string clicks.
- angle_name{ “alpha”, “epsilon”, “Phi” }, optional
The angle to be extracted
- previous_anglefloat, optional
Angle estimate from previous generation; used to refine this generation’s estimate. Default is None (for estimation with no previous genereation’s data)
- rpeconfig_instDeclares which model configuration RPE should be trying to fit;
determines particular functions and values to be used.
Returns
- alpha_jfloat
The current angle estimate.
- pygsti.extras.rpe.estimate_angles(dataset, angle_sin_strs, angle_cos_strs, angle_name='epsilon', length_list=None, rpeconfig_inst=None)
For a dataset containing sin and cos strings to estimate either alpha, epsilon, or Phi return a list of alpha, epsilon, or Phi estimates (one for each generation). Note: this assumes the dataset contains ‘0’ and ‘1’ SPAM labels.
Parameters
- datasetDataSet
The dataset from which the angle estimates will be extracted.
- angle_sin_strslist of Circuits
The list of sin strs that the estimator will use.
- angle_cos_strslist of Circuits
The list of cos strs that the estimator will use.
- angle_name{ “alpha”, “epsilon”, “Phi” }, optional
The angle to be extracted
- length_listThe list of sequence lengths. Default is None;
If None is specified, then length_list becomes [1,2,4,…,2**(len(angle_sin_strs)-1)]
- rpeconfig_instRPEconfig object
Declares which model configuration RPE should be trying to fit; determines particular functions and values to be used.
Returns
- angleHatListlist of floats
A list of angle estimates, ordered by generation (k).
- pygsti.extras.rpe.estimate_thetas(dataset, angle_sin_strs, angle_cos_strs, epsilon_list, return_phi_fun_list=False, rpeconfig_inst=None)
For a dataset containing sin and cos strings to estimate theta, along with already-made estimates of epsilon, return a list of theta (one for each generation).
Parameters
- datasetDataSet
The dataset from which the theta estimates will be extracted.
- angle_sin_strslist of Circuits
The list of sin strs that the estimator will use.
- angle_cos_strslist of Circuits
The list of cos strs that the estimator will use.
- epsilon_listlist of floats
List of epsilon estimates.
- return_phi_fun_listbool, optional
Set to True to obtain measure of how well Eq. III.7 is satisfied. Default is False.
- rpeconfig_instRPEconfig object
Declares which model configuration RPE should be trying to fit; determines particular functions and values to be used.
Returns
- thetaHatListlist of floats
A list of theta estimates, ordered by generation (k).
- PhiFunListlist of floats
A list of _sin_phi2 vals at optimal theta values. If not close to 0, constraints unsatisfiable. Only returned if return_phi_fun_list is set to True.
- pygsti.extras.rpe.extract_alpha(model, rpeconfig_inst)
For a given model, obtain the angle of rotation about the “fixed axis”
WARNING: This is a gauge-covariant parameter! Gauge must be fixed prior to estimating.
Parameters
- modelModel
The model whose angle of rotation about the fixed axis is to be calculated.
- rpeconfig_instRPEconfig object
Declares which model configuration RPE should be trying to fit; determines particular functions and values to be used.
Returns
- alphaValfloat
The value of alpha for the input model.
- pygsti.extras.rpe.extract_epsilon(model, rpeconfig_inst)
For a given model, obtain the angle of rotation about the “loose axis”
WARNING: This is a gauge-covariant parameter! Gauge must be fixed prior to estimating.
Parameters
- modelModel
The model whose angle of rotation about the “loose axis” is to be calculated.
- rpeconfig_instRPEconfig object
Declares which model configuration RPE should be trying to fit; determines particular functions and values to be used.
Returns
- epsilonValfloat
The value of epsilon for the input model.
- pygsti.extras.rpe.extract_theta(model, rpeconfig_inst)
For a given model, obtain the angle between the estimated “loose axis” and the target “loose axis”.
WARNING: This is a gauge-covariant parameter! (I think!) Gauge must be fixed prior to estimating.
Parameters
- modelModel
The model whose loose axis misalignment is to be calculated.
- rpeconfig_instRPEconfig object
Declares which model configuration RPE should be trying to fit; determines particular functions and values to be used.
Returns
- thetaValfloat
The value of theta for the input model.
- pygsti.extras.rpe.consistency_check(angle_k, angle_final, k)
Check internal consistency
- pygsti.extras.rpe.analyze_rpe_data(input_dataset, true_or_target_model, string_list_d, rpeconfig_inst, do_consistency_check=False, k_list=None)
Compute angle estimates and compare to true or target values for alpha, epsilon, and theta. (“True” will typically be used for simulated data, when the true angle values are known a priori; “target” will typically be used for experimental data, where we do not know the true angle values, and can only compare to our desired angles.)
Parameters
- input_datasetDataSet
The dataset containing the RPE experiments.
- true_or_target_modelModel
The model used to generate the RPE data OR the target model.
- string_list_ddict
The dictionary of operation sequence lists used for the RPE experiments. This should be generated via make_rpe_string_list_d.
- rpeconfig_instRPEconfig object
Declares which model configuration RPE should be trying to fit; determines particular functions and values to be used.
Returns
- resultsDdict
A dictionary of the results. The keys of the dictionary are:
‘alphaHatList’ : List (ordered by k) of alpha estimates.
‘epsilonHatList’ : List (ordered by k) of epsilon estimates.
‘thetaHatList’ : List (ordered by k) of theta estimates.
‘alphaErrorList’ : List (ordered by k) of difference between true alpha and RPE estimate of alpha.
‘epsilonErrorList’ : List (ordered by k) of difference between true epsilon and RPE estimate of epsilon.
‘thetaErrorList’ : List (ordered by k) of difference between true theta and RPE estimate of theta.
‘PhiFunErrorList’ : List (ordered by k) of _sin_phi2 values.