:py:mod:`pygsti.algorithms.core` ================================ .. py:module:: pygsti.algorithms.core .. autoapi-nested-parse:: Core GST algorithms Module Contents --------------- Functions ~~~~~~~~~ .. autoapisummary:: pygsti.algorithms.core.run_lgst pygsti.algorithms.core.gram_rank_and_eigenvalues pygsti.algorithms.core.run_gst_fit_simple pygsti.algorithms.core.run_gst_fit pygsti.algorithms.core.run_iterative_gst pygsti.algorithms.core.iterative_gst_generator pygsti.algorithms.core.find_closest_unitary_opmx Attributes ~~~~~~~~~~ .. autoapisummary:: pygsti.algorithms.core.CUSTOMLM pygsti.algorithms.core.FLOATSIZE .. py:data:: CUSTOMLM :value: 'True' .. py:data:: FLOATSIZE :value: '8' .. py:function:: run_lgst(dataset, prep_fiducials, effect_fiducials, target_model, op_labels=None, op_label_aliases=None, guess_model_for_gauge=None, svd_truncate_to=None, verbosity=0, check=True) Performs Linear-inversion Gate Set Tomography on the dataset. Parameters ---------- dataset : DataSet The data used to generate the LGST estimates prep_fiducials : list of Circuits Fiducial Circuits used to construct a informationally complete effective preparation. effect_fiducials : list of Circuits Fiducial Circuits used to construct a informationally complete effective measurement. target_model : Model A model used to specify which operation labels should be estimated, a guess for which gauge these estimates should be returned in. op_labels : list, optional A list of which operation labels (or aliases) should be estimated. Overrides the operation labels in target_model. e.g. ['Gi','Gx','Gy','Gx2'] op_label_aliases : dictionary, optional Dictionary whose keys are operation label "aliases" and whose values are circuits corresponding to what that operation label should be expanded into before querying the dataset. Defaults to the empty dictionary (no aliases defined) e.g. op_label_aliases['Gx^3'] = pygsti.baseobjs.Circuit(['Gx','Gx','Gx']) guess_model_for_gauge : Model, optional A model used to compute a gauge transformation that is applied to the LGST estimates before they are returned. This gauge transformation is computed such that if the estimated gates matched the model given, then the operation matrices would match, i.e. the gauge would be the same as the model supplied. Defaults to target_model. svd_truncate_to : int, optional The Hilbert space dimension to truncate the operation matrices to using a SVD to keep only the largest svdToTruncateTo singular values of the I_tildle LGST matrix. Zero means no truncation. Defaults to dimension of `target_model`. verbosity : int, optional How much detail to send to stdout. check : bool, optional Specifies whether we perform computationally expensive assertion checks. Computationally cheap assertions will always be checked. Returns ------- Model A model containing all of the estimated labels (or aliases) .. py:function:: gram_rank_and_eigenvalues(dataset, prep_fiducials, effect_fiducials, target_model) Returns the rank and singular values of the Gram matrix for a dataset. Parameters ---------- dataset : DataSet The data used to populate the Gram matrix prep_fiducials : list of Circuits Fiducial Circuits used to construct a informationally complete effective preparation. effect_fiducials : list of Circuits Fiducial Circuits used to construct a informationally complete effective measurement. target_model : Model A model used to make sense of circuit elements, and to compute the theoretical gram matrix eigenvalues (returned as `svalues_target`). Returns ------- rank : int the rank of the Gram matrix svalues : numpy array the singular values of the Gram matrix svalues_target : numpy array the corresponding singular values of the Gram matrix generated by target_model. .. py:function:: run_gst_fit_simple(dataset, start_model, circuits, optimizer, objective_function_builder, resource_alloc, verbosity=0) Performs core Gate Set Tomography function of model optimization. Optimizes the parameters of `start_model` by minimizing the objective function built by `objective_function_builder`. Probabilities are computed by the model, and outcome counts are supplied by `dataset`. Parameters ---------- dataset : DataSet The dataset to obtain counts from. start_model : Model The Model used as a starting point for the least-squares optimization. circuits : list of (tuples or Circuits) Each tuple contains operation labels and specifies a circuit whose probabilities are considered when trying to least-squares-fit the probabilities given in the dataset. e.g. [ (), ('Gx',), ('Gx','Gy') ] optimizer : Optimizer or dict The optimizer to use, or a dictionary of optimizer parameters from which a default optimizer can be built. objective_function_builder : ObjectiveFunctionBuilder Defines the objective function that is optimized. Can also be anything readily converted to an objective function builder, e.g. `"logl"`. resource_alloc : ResourceAllocation A resource allocation object containing information about how to divide computation amongst multiple processors and any memory limits that should be imposed. verbosity : int, optional How much detail to send to stdout. Returns ------- result : OptimizerResult the result of the optimization model : Model the best-fit model. .. py:function:: run_gst_fit(mdc_store, optimizer, objective_function_builder, verbosity=0) Performs core Gate Set Tomography function of model optimization. Optimizes the model to the data within `mdc_store` by minimizing the objective function built by `objective_function_builder`. Parameters ---------- mdc_store : ModelDatasetCircuitsStore An object holding a model, data set, and set of circuits. This defines the model to be optimized, the data to fit to, and the circuits where predicted vs. observed comparisons should be made. This object also contains additional information specific to the given model, data set, and circuit list, doubling as a cache for increased performance. This information is also specific to a particular resource allocation, which affects how cached values stored. optimizer : Optimizer or dict The optimizer to use, or a dictionary of optimizer parameters from which a default optimizer can be built. objective_function_builder : ObjectiveFunctionBuilder Defines the objective function that is optimized. Can also be anything readily converted to an objective function builder, e.g. `"logl"`. If `None`, then `mdc_store` must itself be an already-built objective function. verbosity : int, optional How much detail to send to stdout. Returns ------- result : OptimizerResult the result of the optimization objfn_store : MDCObjectiveFunction the objective function and store containing the best-fit model evaluated at the best-fit point. .. py:function:: run_iterative_gst(dataset, start_model, circuit_lists, optimizer, iteration_objfn_builders, final_objfn_builders, resource_alloc, verbosity=0) Performs Iterative Gate Set Tomography on the dataset. Parameters ---------- dataset : DataSet The data used to generate MLGST gate estimates start_model : Model The Model used as a starting point for the least-squares optimization. circuit_lists : list of lists of (tuples or Circuits) The i-th element is a list of the circuits to be used in the i-th iteration of the optimization. Each element of these lists is a circuit, specifed as either a Circuit object or as a tuple of operation labels (but all must be specified using the same type). e.g. [ [ (), ('Gx',) ], [ (), ('Gx',), ('Gy',) ], [ (), ('Gx',), ('Gy',), ('Gx','Gy') ] ] optimizer : Optimizer or dict The optimizer to use, or a dictionary of optimizer parameters from which a default optimizer can be built. iteration_objfn_builders : list List of ObjectiveFunctionBuilder objects defining which objective functions should be optimizized (successively) on each iteration. final_objfn_builders : list List of ObjectiveFunctionBuilder objects defining which objective functions should be optimizized (successively) on the final iteration. resource_alloc : ResourceAllocation A resource allocation object containing information about how to divide computation amongst multiple processors and any memory limits that should be imposed. verbosity : int, optional How much detail to send to stdout. Returns ------- models : list of Models list whose i-th element is the model corresponding to the results of the i-th iteration. optimums : list of OptimizerResults list whose i-th element is the final optimizer result from that iteration. final_objfn : MDSObjectiveFunction The final iteration's objective function / store, which encapsulated the final objective function evaluated at the best-fit point (an "evaluated" model-dataSet-circuits store). .. py:function:: iterative_gst_generator(dataset, start_model, circuit_lists, optimizer, iteration_objfn_builders, final_objfn_builders, resource_alloc, starting_index=0, verbosity=0) Performs Iterative Gate Set Tomography on the dataset. Same as `run_iterative_gst`, except this function produces a generator for producing the output for each iteration instead of returning the lists of outputs all at once. Parameters ---------- dataset : DataSet The data used to generate MLGST gate estimates start_model : Model The Model used as a starting point for the least-squares optimization. circuit_lists : list of lists of (tuples or Circuits) The i-th element is a list of the circuits to be used in the i-th iteration of the optimization. Each element of these lists is a circuit, specifed as either a Circuit object or as a tuple of operation labels (but all must be specified using the same type). e.g. [ [ (), ('Gx',) ], [ (), ('Gx',), ('Gy',) ], [ (), ('Gx',), ('Gy',), ('Gx','Gy') ] ] optimizer : Optimizer or dict The optimizer to use, or a dictionary of optimizer parameters from which a default optimizer can be built. iteration_objfn_builders : list List of ObjectiveFunctionBuilder objects defining which objective functions should be optimizized (successively) on each iteration. final_objfn_builders : list List of ObjectiveFunctionBuilder objects defining which objective functions should be optimizized (successively) on the final iteration. resource_alloc : ResourceAllocation A resource allocation object containing information about how to divide computation amongst multiple processors and any memory limits that should be imposed. starting_index : int, optional (default 0) Index of the iteration to start the optimization at. Primarily used when warmstarting the iterative optimization from a checkpoint. verbosity : int, optional How much detail to send to stdout. Returns ------- generator Returns a generator which when queried the i-th time returns a tuple containing: - model: the model corresponding to the results of the i-th iteration. - optimums : the final OptimizerResults from the i-th iteration. - final_objfn : If the final iteration the MDSObjectiveFunction function / store, which encapsulated the final objective function evaluated at the best-fit point (an "evaluated" model-dataset-circuits store). .. py:function:: find_closest_unitary_opmx(operation_mx) Find the closest (in fidelity) unitary superoperator to `operation_mx`. Finds the closest operation matrix (by maximizing fidelity) to `operation_mx` that describes a unitary quantum gate. Parameters ---------- operation_mx : numpy array The operation matrix to act on. Returns ------- numpy array The resulting closest unitary operation matrix.