mimiqcircuits.backends.fidelity¶
Typed fidelity values returned by LocalBackend.evolve().
Different simulators report fidelity with different semantics: a state-vector backend can claim exactness, an MPS backend can only return a truncation lower bound, and a randomised-benchmarking backend can return a sample-based estimate with a standard error.
A plain float return would silently lose those distinctions.
The tagged variants below preserve them:
Reduce to plain numbers via as_lower_bound() (conservative),
as_expected() (central), or as_interval() ((lo, hi)).
Functions
|
Reduce |
|
Reduce |
Reduce |
Classes
|
Sample-based fidelity estimate with a standard error. |
The simulator believes the state is exact. |
|
|
Base class for typed fidelity values. |
|
Per-step lower-bound contributions. |
|
A single lower bound on the fidelity of the whole circuit. |
The backend does not track fidelity. |
- class Fidelity[source]¶
Bases:
objectBase class for typed fidelity values.
The subclasses say what a fidelity number means:
ExactFidelity,UnknownFidelity,TruncationLowerBound,LowerBoundPerStepandEstimatedFidelity.as_lower_bound(),as_expected()andas_interval()reduce any of them to plain numbers.Examples
>>> from mimiqcircuits import * >>> from mimiqcircuits.backends import *
An MPS simulator that discarded 1% of the norm reports a lower bound, not an exact value.
>>> f = TruncationLowerBound(0.99) >>> as_lower_bound(f), as_expected(f) (0.99, 0.99)
An estimate with a standard error is reduced conservatively by
as_lower_bound()(mean minus three standard errors).>>> e = EstimatedFidelity(mean=0.9, stderr=0.01) >>> round(as_lower_bound(e), 2), as_expected(e) (0.87, 0.9) >>> as_lower_bound(UnknownFidelity()) nan
- class ExactFidelity[source]¶
Bases:
FidelityThe simulator believes the state is exact.
BLAS and SIMD round-off are not tracked; this is a structural claim about the algorithm, not a bit-perfect guarantee.
- class UnknownFidelity[source]¶
Bases:
FidelityThe backend does not track fidelity.
Reducers return
nan. Prefer this variant over inventing a placeholder value when you genuinely do not know.
- class TruncationLowerBound(value)[source]¶
Bases:
FidelityA single lower bound on the fidelity of the whole circuit.
Typical for MPS and MPO simulators, where the bound comes from the singular values discarded during compression. Return it even when the bound is exactly
1.0: a plain1.0fromLocalBackend.evolve()is read asExactFidelity.
- class LowerBoundPerStep(values)[source]¶
Bases:
FidelityPer-step lower-bound contributions.
as_lower_bound()returns the product of the values, each clipped to[0, 1]. That product bounds the circuit fidelity only when successive truncation errors are uncorrelated; a backend that cannot assume this returns a singleTruncationLowerBoundinstead.
- class EstimatedFidelity(mean, stderr)[source]¶
Bases:
FidelitySample-based fidelity estimate with a standard error.
Use it for randomised benchmarking, direct fidelity estimation, or cross-entropy benchmarking.
as_lower_bound()returnsmax(0, mean - 3 * stderr)andas_interval()returns(mean - stderr, mean + stderr).
- as_lower_bound(f)[source]¶
Reduce
fto a conservative lower bound.- Parameters:
f (Fidelity) – The fidelity.
- Returns:
1.0forExactFidelity;nanforUnknownFidelity, so that statistics over many results do not count an unknown fidelity as a good one; the value forTruncationLowerBound; the product of the clipped values forLowerBoundPerStep;max(0, mean - 3 * stderr)forEstimatedFidelity.- Raises:
TypeError – If
fis not one of these types.- Return type:
- as_expected(f)[source]¶
Reduce
fto a central estimate.- Parameters:
f (Fidelity) – The fidelity.
- Returns:
The same as
as_lower_bound(), except forEstimatedFidelity, which gives its mean.- Raises:
- Return type: