Skip to main content
IBM Quantum Platform

qiskit_noise_learning.analysis.Fit

class qiskit_noise_learning.analysis.Fit(*, model: LinearMap[Hashable, FidelityIndex] | None = None, paths: list[Path] | None = None, instruction_sequences: list[InstructionSequence] | None = None, relations: set[tuple[int, int]] | None = None, _store: dict[type[LeveledData], list[LeveledData | AbsentType | SkippedType]] | None = None)

GitHub

Bases: object

Container for data at each level of the analysis hierarchy.

The LEVELS represent different stages of processed data. In order, they are:

  • RawData corresponding to bit counts of executed instruction sequences.
  • ObservableData corresponding to observables of randomizations of paths that traverse the instruction sequences.
  • AggregatedObservableData corresponding to a combination of observables aggregated across randomizations.
  • ModelData corresponding to model fit parameters.

Each level holds a history of all values written to it; the current value is always the most recent. New levels start as Absent. Levels bypassed by a stage are marked Skipped.

Example:

result = my_stage.run(my_raw_data)
result.raw_data           # current RawData
result.history.raw_data   # full write history at the RawData level

Parameters

  • model – The model to fit. If given, it must be a fidelity model, i.e. a LinearMap whose output space is a LogFidelitySpace (see is_fidelity_model()).
  • paths – The paths to analyze.
  • instruction_sequences – The instruction sequences used in the experiment.
  • relations – A pre-computed set of (path_idx, sequence_idx) tuples indicating which paths are traversed by which instruction sequences.

Raises

TypeError – If model is not None and is not a fidelity model.

__init__

__init__(*, model: LinearMap[Hashable, FidelityIndex] | None = None, paths: list[Path] | None = None, instruction_sequences: list[InstructionSequence] | None = None, relations: set[tuple[int, int]] | None = None, _store: dict[type[LeveledData], list[LeveledData | AbsentType | SkippedType]] | None = None)


Methods

Column 1
Column 2
__init__(*[, model, paths, ...])
copy()Return a copy preserving the full history at each level.
plot_qubit_pair_decays(pairs, *[, ...])Plot a grid of fidelity decays over qubit pairs, drawn from this fit's data.

Attributes

Column 1
Column 2
aggregated_observable_dataCurrent data at the AggregatedObservableData level.
historyThe full write history for each level.
instruction_sequencesThe instruction sequences used in the experiment, or None if not set.
modelThe fidelity model used for design matrix construction.
model_dataCurrent data at the ModelData level.
observable_dataCurrent data at the ObservableData level.
pathsThe paths to compute observables for.
raw_dataCurrent data at the RawData level.
relationsPath-to-sequence relations, or None if not set.

copy

copy() → Self

Return a copy preserving the full history at each level.

history

Type: FitHistory

The full write history for each level.

model

Type: LinearMap[Hashable, FidelityIndex] | None

The fidelity model used for design matrix construction.

raw_data

Type: RawData | AbsentType | SkippedType

Current data at the RawData level.

observable_data

Type: ObservableData | AbsentType | SkippedType

Current data at the ObservableData level.

aggregated_observable_data

Type: AggregatedObservableData | AbsentType | SkippedType

Current data at the AggregatedObservableData level.

model_data

Type: ModelData | AbsentType | SkippedType

Current data at the ModelData level.

paths

Type: list[Path]

The paths to compute observables for.

instruction_sequences

Type: list[InstructionSequence] | None

The instruction sequences used in the experiment, or None if not set.

relations

Type: set[tuple[int, int]] | None

Path-to-sequence relations, or None if not set.

plot_qubit_pair_decays

plot_qubit_pair_decays(pairs: Sequence[tuple[int, int]], *, observable_type: Literal['raw', 'means', 'both'] | None = None, exponential_fit: bool = False, model_prediction: bool = False, observable_marker_kwargs: Mapping[str, object] | None = None, means_marker_kwargs: Mapping[str, object] | None = None, exponential_fit_line_kwargs: Mapping[str, object] | None = None, model_line_kwargs: Mapping[str, object] | None = None, num_cols: int = 3, noise_site: Mapping[str, Literal['before', 'after']] | None = None, paths: Sequence[Path] | None = None, fragment_depths: Sequence[float] | None = None, title: str | None = None) → InteractiveFigure

Plot a grid of fidelity decays over qubit pairs, drawn from this fit’s data.

One subplot per pair, sharing labels/colors across pairs. Which decays are drawn is controlled by the toggles below; all default to off, so enable the ones you want. A requested decay whose data has not been computed on this fit yet is skipped with a warning.

Parameters

  • pairs – The qubit pairs to plot, one subplot each. A pair is unordered – (1, 0) names the same subplot as (0, 1) – so no pair may be repeated.
  • observable_type – How to draw the empirical observable data: "raw" (raw per-randomization scatter), "means" (per-fragment-depth means with error bars), "both", or None (the default) to omit the empirical points. Uses this fit’s ObservableData.
  • exponential_fit – Whether to draw the fitted exponential decay curve, from this fit’s AggregatedObservableData (its fragment_depth == -1 fitted parameters). Defaults to False.
  • model_prediction – Whether to draw the model-predicted decay curve, from this fit’s model and ModelData. Defaults to False.
  • observable_marker_kwargs – Optional marker overrides for the raw observable points.
  • means_marker_kwargs – Optional marker overrides for the observable-means points.
  • exponential_fit_line_kwargs – Optional line overrides for the exponential-fit curve.
  • model_line_kwargs – Optional line overrides for the model curve.
  • num_cols – The number of subplot columns; rows are derived from the pair count.
  • noise_site – An optional noise-site mapping forwarded to the label formatter (with the default "formula" label style this yields the compact f^{gate}_{pauli} label). Defaults to the noise site of the fit’s model when it is, or contains, a single PauliLindbladModel.
  • paths – The paths to draw across all layers. Defaults to the decay paths found in this fit’s observable/aggregated observable data, falling back to the fit’s own paths when no such data is present. Supply this to draw model-prediction curves for a fit that carries only a model (no observable or aggregated observable data to derive the paths from).
  • fragment_depths – The fragment-depth range for the curves. Defaults to 0 through the largest fragment depth in the empirical data present, or 0–10 when there is none.
  • title – An optional figure title.

Returns

The figure with interactive legends.

Raises

  • ValueError – If the fit has no model (and hence no gate set) to build labels from, or if pairs names the same pair twice.
  • ImportError – If matplotlib is not installed.
Was this page helpful?
Report a bug, typo, or request content on GitHub.