qp.labs.trotter_error.ImportanceConfig¶
- class ImportanceConfig(topk, weights, history=False)[source]¶
Bases:
objectEnable the importance sampling feature of
perturbation_error().This class is used as an optional argument to
perturbation_error(). When used, the perturbation error will be computed using only thetopkmost important commutators. The importance of a commutator is induced fromweightswhich stores a user-defined importance score for each fragment label. The keys inweightsmust be identical to the symbols used to build theProductFormulaobject passed intoperturbation_error().Example >>> import numpy as np >>> from pennylane.labs.trotter_error import NumpyFragment, NumpyState >>> from pennylane.labs.trotter_error import perturbation_error, ImportanceConfig, ProductFormula
>>> frags = {"A": NumpyFragment(np.array([[1, 1], [1, 0]])), "B": NumpyFragment(np.array([[1, 1], [1, 1]]))} >>> state = NumpyState(np.array([1, 0]))
>>> config = ImportanceConfig( >>> topk=3, >>> weights={"A": 0.95, "B": 0.5} >>> )
>>> second_order = ProductFormula([("A", 1/2), ("B", 1), ("A", 1/2)])
>>> perturbation_error(second_order, frags, state, order=3, importance=config)) defaultdict(<class 'int'>, {3: -0.25j})
Attributes
tracks the convergence history of the perturbation error per commutator evaluation.
samples the
topkmost important commutators to estimate the perturbation error.a dictionary mapping fragment labels to their importance score.
- history = False¶
tracks the convergence history of the perturbation error per commutator evaluation. when true the output of
perturbation_error()is modified to include the convergence history.
- topk = <dataclasses._MISSING_TYPE object>¶
samples the
topkmost important commutators to estimate the perturbation error.
- weights = <dataclasses._MISSING_TYPE object>¶
a dictionary mapping fragment labels to their importance score.