OBPMetadata
class OBPMetadata(truncation_error_budget, num_slices, operator_budget, backpropagation_history, num_backpropagated_slices)
Bases: object
A container for metadata generated during the backpropagate()
method.
Attributes
Parameters
- truncation_error_budget (TruncationErrorBudget)
- num_slices (int | None)
- operator_budget (OperatorBudget)
- backpropagation_history (list[SliceMetadata])
- num_backpropagated_slices (int)
truncation_error_budget
Type: TruncationErrorBudget
Values specifying the observable truncation strategy.
num_slices
Type: int | None
The total number of slices to attempt to backpropagate.
operator_budget
Type: OperatorBudget
Values specifying how large the operator may grow.
backpropagation_history
Type: list[SliceMetadata]
A sequence of metadata objects to track the progression of the backpropagation.
num_backpropagated_slices
Type: int
The number of backpropagated slices.
This value can differ from len(backpropagation_history)
in cases where a stopping criterion such as operator_budget.max_paulis
or operator_budget.max_qwc_groups
caused the backpropagation to terminate. Then, this value should be equal to len(backpropagation_history) - 1
because the last slice caused the thresholds to be exceeded. However, for convenience these values are still recorded for the end-user to inspect them.
Methods
accumulated_error
accumulated_error(observable_idx, slice_idx=None)
Compute the accumulated error for a given observable at a given “time”.
This method computes the accumulated error for a given observable index at a given “time” during the course of the backpropagation. In this context, “time” is to be understood as the discrete steps of already backpropagated slices.
The accumulated error is computed as the sum of the individual SliceMetadata.slice_errors
. These in turn may be computed within a specified TruncationErrorBudget.p_norm
. Thus, the computed accumulated error is an upper bound to the real accumulated error as given by the Minkowski inequality (the generalization of the triangle inequality for Lp-norms other than p=2
).
Since a general Lp-norm (other than p=2
) is not an inner product norm, it does not satisfy the parallelogram law. Hence, we must use the Minkowski inequality as the upper bound of the accumulated error.
Parameters
- observable_idx (int) – the index of the observable whose accumulated error to compute.
- slice_idx (int | None) – the index of the slice (the discrete “time” step) up to which to compute the accumulated error. If this is
None
, it will default toself.num_backpropagated_slices
which is equivalent to computing the accumulated error of an observable at the latest point in time which has not surpassed any stopping criteria in the algorithm
Returns
The accumulated error computed per the explanations above.
Return type
from_json
classmethod from_json(json_file)
Load a metadata from a json file.
Parameters
json_file (str) – the path to the file to be loaded.
Returns
The loaded metadata.
Return type
left_over_error_budget
left_over_error_budget(observable_idx, slice_idx=None)
Compute the left-over error budget for a given observable at a given “time”.
This method computes the left-over error budget for a given observable index at a given “time” during the course of the backpropagation. In this context, “time” is to be understood as the discrete steps of already backpropagated slices.
The left-over error budget is computed as the remainder of the total budget minus the sum of the individual SliceMetadata.slice_errors
. These in turn may be computed within a specified TruncationErrorBudget.p_norm
.
See also the explanations in accumulated_error()
for more details on how the individual slice errors are summed up to form an upper bound to the real error via the Minkowski inequality.
The left-over error budget is relative to the value of self.truncation_error_budget.max_error_total
which may be numpy.inf
in which case the returned value of this method will be numpy.inf
, too.
Parameters
- observable_idx (int) – the index of the observable whose left-over error budget to compute.
- slice_idx (int | None) – the index of the slice (the discrete “time” step) up to which to compute the left-over error budget. If this is
None
, it will default toself.num_backpropagated_slices
which is equivalent to computing the left-over error budget of an observable at the latest point in time which has not surpassed any stopping criteria in the algorithm
Returns
The left-over error budget computed per the explanations above.
Return type
to_json
to_json(json_file, **kwargs)
Dump this metadata to a json file.
Parameters
- json_file (str) – the path to the file into which to dump the metadata.
- kwargs – keyword arguments to be passed on towards
json.dump()
.
Return type
None