setup_budget¶
- setup_budget(*, max_error_per_slice=None, max_error_total=None, num_slices=None, p_norm=1)[source]¶
Calculate the budget available to each slice for observable term truncation.
This method makes the construction of a
TruncationErrorBudget
easier for an end-user. This error budget can be provided to thebackpropagate()
method to enable the truncation of low-weight Pauli terms. Refer to the how-to guide for a detailed discussion on truncating terms from the output operator and bounding the incurred error.- The construction logic is as follows:
if
max_error_per_slice
is provided its value is converted to a list and used immediately forTruncationErrorBudget.per_slice_budget
if the above is not the case,
max_error_total
has to be setif
num_slices
is not set,:attr:.TruncationErrorBudget.per_slice_budget gets set to[max_error_total]
resulting in the entire budget being consumed greedilyhowever, if
num_slices
is provided, thenTruncationErrorBudget.per_slice_budget
assumes an even distribution of the maximum total error across the specified number of slices:[max_error_total / num_slices]
Finally, if
max_error_total
is set, this puts a hard limit on the total maximum error to be accumulated throughout the entire backpropagation. Thus, settingmax_error_per_slice
andmax_error_total
can be of value.Note
Budget not spent during a previous iteration will carry over into subsequent iterations, meaning that the maximum budget for any slice during backpropagation may in fact exceed
TruncationErrorBudget.per_slice_budget
.- Parameters:
max_error_per_slice (float | Sequence[float] | None) – Specifies the maximum error per backpropagated slice. See above for more details.
max_error_total (float | None) – Specifies the total maximum error for the entire backpropagation. See above for more details.
num_slices (int | None) – The number of slices over which to distribute the budget. See above for more details.
p_norm (int) – The Lp norm of the error. This affects the gradual distribution of
max_error_total
in the case ofnum_slices
also being set (see above). Refer to the how-to guide for a detailed conversation on bounding truncation error using higher Lp-norms.
- Returns:
The resulting
TruncationErrorBudget
.- Raises:
ValueError – if
max_error_per_slice
andmax_error_total
are bothNone
.- Return type: