Bounds
qiskit_addon_slc.bounds
Bound computation functions.
This module provides various functions for computing the error bounds that make up a shaded lightcone.
compute_forward_bounds
compute_forward_bounds(circuit, noise_model_paulis, /, observable, *, evolution_max_terms=1000000, eigval_max_qubits=14, atol=1e-08, atol_simplify=1e-08, atol_eigenvalue=1e-08, **kwargs)
Compute the forward-evolved unequal-time commutator bounds.
Starting at the end of the circuit, compute the forward-evolved unequal-time commutator bounds for all Pauli error terms of each noisy layer in the target circuit.
That is, compute for all error terms, , where is the target observable to be measured on circuit.
The error terms, , are dictated by noise_model_paulis. This dictionary maps noise model identifiers (samplomatic.InjectNoise.ref) to a list of Pauli error terms. The corresponding terms will be used whenever a BoxOp with a matching InjectNoise annotation is encountered during the iteration over circuit.
qiskit_addon_slc.bounds.forward.compute_forward_bounds()’s argument atol is deprecated as of qiskit-addon-slc 0.2.0. It will be removed no earlier than 3 months after the release date. Use atol_simplify and atol_eigenvalue instead.
Parameters
- circuit (QuantumCircuit) – the target circuit.
- noise_model_paulis (dict[str, QubitSparsePauliList]) – the Pauli error terms to consider for each noise model.
- observable (Pauli |PauliList |SparseObservable |SparsePauliOp) – the target observable to be measured at the end of the circuit.
- evolution_max_terms (int) – the maximum number of operator terms to keep track of during the evolution.
- eigval_max_qubits (int) – the maximum number of qubits of a commutator for which the eigenvalue will still be attempted to be computed. When this value is exceeded, the bound is approximated via a simpler and more loose triangle inequality.
- atol (float) – DEPRECATED use
atol_simplifyandatol_eigenvalueinstead! - atol_simplify (float) – the absolute tolerance used for trimming terms from the commutator. Loosening this tolerance will result in a greater truncation of the commutator’s terms, rendering the computation of its eigenvalue cheaper but less accurate.
- atol_eigenvalue (float) – the absolute tolerance used for detecting convergence of the commutator’s eigenvalue. Loosening this tolerance will result in a less accurate eigenvalue as computed by the iterative Davidson eigensolver.
- kwargs – any additional keyword arguments will be forward to
compute_bounds().
Returns
The unequal-time commutator bound.
Raises
NotImplementedError – when the observable contains more than a single Pauli term. If you run into this, you will need to call this function for each target Pauli separately.
Return type
tighten_with_speed_limit
tighten_with_speed_limit(bounds, circuit, noise_model_paulis, /, observable)
Tighten the provided bounds using limits on the speed of information propagation.
Inspired by the ideas behind the Lieb-Robinson bounds, this function leverages limits on the speed of information propagation to tighten previously computed forward-evolved unequal-time commutator bounds (see also compute_forward_bounds()).
Parameters
- bounds (dict[str, PauliLindbladMap]) – the previously computed forward-evolved unequal-time commutator bounds.
- circuit (QuantumCircuit) – the target circuit.
- noise_model_paulis (dict[str, QubitSparsePauliList]) – the Pauli error terms to consider for each noise model.
- observable (Pauli |PauliList |SparseObservable |SparsePauliOp) – the target observable to be measured at the end of the circuit.
Returns
A tightened copy of the unequal-time commutator bounds.
Raises
- NotImplementedError – when the
observablecontains more than a single Pauli term. If you run into this, you will need to call this function for each target Pauli separately. - ValueError – when encountering a gate that acts on more than 2 qubits.
Return type
compute_backward_bounds
compute_backward_bounds(circuit, noise_model_paulis, /, *, evolution_max_terms=1000000, **kwargs)
Compute the backward-evolved unequal-time commutator bounds.
Starting at the beginning of the circuit, compute the backward-evolved unequal-time commutator bounds for all Pauli error terms of each noisy layer in the target circuit.
That is, compute (using the Schatten 1-norm aka nuclear norm) for all error terms, , where is assumed to be the all-zero state, , on all active qubits in circuit.
The error terms, , are dictated by noise_model_paulis. This dictionary maps noise model identifiers (samplomatic.InjectNoise.ref) to a list of Pauli error terms. The corresponding terms will be used whenever a BoxOp with a matching InjectNoise annotation is encountered during the iteration over circuit.
Before computing the bounds, this function removes all Measure operations from circuit. This is required because the circuit is being inverted before being processed in reverse order, which allows the backward evolution to be treated like a forward evolution (in the inverted circuit).
Parameters
- circuit (QuantumCircuit) – the target circuit.
- noise_model_paulis (dict[str, QubitSparsePauliList]) – the Pauli error terms to consider for each noise model.
- evolution_max_terms (int) – the maximum number of operator terms to keep track of during the evolution. (If the operator exceeds this size, the smallest terms are truncated).
- kwargs – any additional keyword arguments will be forward to
compute_bounds().
Returns
The backward-evolved unequal-time commutator bounds.
Return type
merge_bounds
merge_bounds(circuit, forward_bounds, backward_bounds, /, noise_rates=None, *, is_clifford_circuit=False)
Merge forward and backward bounds.
The layer at which the switch from using backward bounds to using forward bounds takes place will be the same for all qubits. It is determined by taking into account the provided learned noise_rates. If these are not provided, uniform noise rates are assumed. While this is an unrealistic assumption, previewing the merged bounds may still be useful.
Parameters
- circuit (QuantumCircuit) – the target circuit.
- forward_bounds (dict[str, PauliLindbladMap] | None) – the forward bounds (see also
compute_forward_bounds()). - backward_bounds (dict[str, PauliLindbladMap] | None) – the backward bounds (see also
compute_backward_bounds()). - noise_rates (dict[str, PauliLindbladMap | None] | None) – the noise rates learned on the target backend.
- is_clifford_circuit (bool) – whether the target circuit is fully Clifford.
Returns
The merged bounds.
Raises
- ValueError – when both provided bounds are
None. - KeyError – when the
boundscontain anInjectNoise.modifier_refkey which does not occur in the targetcircuitor whoseInjectNoise.refis not found. - ValueError – if the noise model Pauli terms whose bounds are computed for a given
InjectNoise.modifier_refdo not match between theforward_boundsandbackward_bounds. - NotImplementedError – when
is_clifford_circuitisTrue.
Return type
dict[str, PauliLindbladMap] | None
compute_local_scales
compute_local_scales(circuit, bounds, /, noise_rates, *, sampling_cost_budget=inf, bias_tolerance=0.0)
Computes the local_scales argument to a Samplex.
This local_scales argument is used to specify which individual error terms to mitigate.
Either the sampling_cost_budget or bias_tolerance must be specified. The former puts an upper bound on the sampling cost while the latter puts an upper bound on the remaining bias to tolerate.
If the order of Pauli terms in bounds and noise_rates do not match, the output of this function will assume the order set forth by noise_rates in order to ensure that the scales are compatible with the rates that will also be provided to the QuantumProgram.
Parameters
- circuit (QuantumCircuit) – the target circuit.
- bounds (dict[str, PauliLindbladMap]) – the shaded lightcone bounds.
- noise_rates (dict[str, PauliLindbladMap | None]) – the learned noise model rates.
- sampling_cost_budget (float) – the maximum sampling cost to allow.
- bias_tolerance (float) – the maximum bias to tolerate.
Returns
- the
local_scalesdictionary to be provided as the direct input to thesamplomatic.samplex.Samplex.inputs(). - the sampling cost overhead () required to perform the sampling of
local_scales. - the remaining bias on expectation values computed with these bounds.
Return type
A tuple of length 3, the items of which are
Raises
- ValueError – if non-default values are provided for both, the
sampling_cost_budgetandbias_tolerance. - KeyError – if
noise_ratesis missing an entry for any noise model identifier (InjectNoise.ref) encountered incircuit.
This module also contains some lower level functions which are usually not accessed by an end-user directly, but may prove useful for additional development on top of this package.
compute_bounds
compute_bounds(circuit, noise_model_paulis, light_cone, norm_fn, *, backwards, max_num_boxes=None, num_processes=1, timeout=None)
Computes the unequal time commutator bounds.
Given a circuit with BoxOp instructions with InjectNoise annotations and a mapping of noise model identifiers (InjectNoise.ref) to list of Pauli error terms (noise_model_paulis), this function computes the unequal time commutator bounds (the details of which are implemented by norm_fn). In doing so, it only considers gates that lie within the light-cone of the observable (initialized by light_cone). These computed bounds form the basis of the shaded light-cone.
Since this function performs a long-running computation, it gracefully handles KeyboardInterrupt exceptions, allowing the user to interrupt the computation at an arbitrary point in time and still obtain the results that have been computed up to that point.
Parameters
- circuit (QuantumCircuit) – the target circuit.
- noise_model_paulis (dict[str, QubitSparsePauliList]) – the Pauli error terms to consider for each noise model.
- light_cone (LightCone) – the initialized and stateful
LightConetracker. - norm_fn (Callable[[Pauli, RotationGates], CommutatorBounds]) – the function implementing the specific unequal time commutator.
- backwards (bool) – whether to iterate over the
circuitin reverse. - max_num_boxes (int | None) – the maximum number of boxes for which to compute bounds. Bounds for any additional boxes will be given the trivial upper bound value of .
- num_processes (int) – the number of parallel processes to use.
- timeout (float | None) – an optional timeout (in seconds) after which all remaining layers are filled with trivial numerical bounds of
2.0. Note, that this is not a strict timeout and the layer being processed at the time of reaching this timeout will complete normally.
Returns
The computed unequal time commutator bounds.
Return type
CommutatorBounds
class CommutatorBounds(commutator_bound, truncation_bias, fallback_to_tri_ineq)
Bases: NamedTuple
A dataclass to store metadata about the computed commutator bounds.
Create new instance of CommutatorBounds(commutator_bound, truncation_bias, fallback_to_tri_ineq)
Parameters
commutator_bound
Type: float
The bound on the commutator.
This bound will be computed in different means depending on the application. For example, backward bounds will compute the nuclear norm (Schatten 1-norm) while forward bounds are typically computed using the spectral norm (Schatten infinity-norm).
If the norm computation exceeds specified difficulty limits, it will be abandoned in favor of a simpler bound based on the triangle inequality, which is indicated by fallback_to_tri_ineq being set to True.
This value may be NaN when the computation of the commutor bound was aborted. This can happen when the truncation_bias already exceeds the theoretical bound of 2.0.
fallback_to_tri_ineq
Type: bool
Whether commutator_bound was computed “loosely” using a simple triangle inequality.
min
min()
Returns the minimum bound encoded by this metadata.
The minimal bound is the smaller of the sum of commutator_bound and truncation_bias or the theoretical bound of 2.0.
The value of 2.0 is used because a Pauli observable bounded on the range [-1, +1] cannot be biased by more than 2.0.
Return type
truncation_bias
Type: float
The bias on the bound due to truncation of the commutator.