mimiqcircuits.backends.fidelity

Typed fidelity values returned by Backend.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

as_expected(f)

Reduce f to a central / expected scalar.

as_interval(f)

(lo, hi) band.

as_lower_bound(f)

Reduce f to a conservative scalar lower bound.

Classes

EstimatedFidelity(mean, stderr)

Sample-based fidelity estimate with a standard error.

ExactFidelity()

The simulator believes the state is exact.

Fidelity()

Base class for typed fidelity values.

LowerBoundPerStep(values)

Per-step lower-bound contributions.

TruncationLowerBound(value)

A single scalar lower bound on the whole-circuit fidelity.

UnknownFidelity()

The backend does not track fidelity.

class mimiqcircuits.backends.fidelity.Fidelity[source]

Bases: object

Base class for typed fidelity values. See the module docstring for the list of variants and the reducer functions.

class mimiqcircuits.backends.fidelity.ExactFidelity[source]

Bases: Fidelity

The 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.

__init__()
class mimiqcircuits.backends.fidelity.UnknownFidelity[source]

Bases: Fidelity

The backend does not track fidelity.

Reducers return nan. Prefer this variant over inventing a placeholder value when you genuinely do not know.

__init__()
class mimiqcircuits.backends.fidelity.TruncationLowerBound(value)[source]

Bases: Fidelity

A single scalar lower bound on the whole-circuit fidelity.

Typical for MPS / MPO simulators, where value is the product of singular-value tails discarded during compression.

value: float
__init__(value)
class mimiqcircuits.backends.fidelity.LowerBoundPerStep(values)[source]

Bases: Fidelity

Per-step lower-bound contributions.

as_lower_bound returns prod(clip(values, 0, 1)), which is a lower bound on the circuit fidelity only when successive truncation errors are uncorrelated. If your backend cannot make that assumption, collapse to a single TruncationLowerBound at construction time.

values: tuple[float, ...]
__init__(values)
class mimiqcircuits.backends.fidelity.EstimatedFidelity(mean, stderr)[source]

Bases: Fidelity

Sample-based fidelity estimate with a standard error.

Use for randomised benchmarking, direct fidelity estimation, or cross-entropy benchmarking. as_lower_bound returns max(0, mean 3·stderr); as_interval returns the ±1σ band.

mean: float
stderr: float
__init__(mean, stderr)
mimiqcircuits.backends.fidelity.as_lower_bound(f)[source]

Reduce f to a conservative scalar lower bound.

Returns nan when f is UnknownFidelity so that statistics over mixed-type fidelities do not silently treat “unknown” as “good”.

mimiqcircuits.backends.fidelity.as_expected(f)[source]

Reduce f to a central / expected scalar.

For TruncationLowerBound the lower bound is the estimate; for EstimatedFidelity it is the sample mean. Returns nan for UnknownFidelity.

mimiqcircuits.backends.fidelity.as_interval(f)[source]

(lo, hi) band. ±1σ for EstimatedFidelity; otherwise (as_lower_bound, as_expected).