fiqci.ems.backend.core#

FiQCI backend wrapper for seamless error mitigation.

FiQCIBackend wraps an IQM backend and applies error mitigation (e.g. M3 readout error correction) to every circuit execution. It handles calibration, caching, and result post-processing automatically, so users get mitigated results through the standard Qiskit backend interface without additional code.

Classes

FiQCIBackend(backend[, mitigation_level, ...])

FiQCI backend wrapper that applies error mitigation automatically.

class FiQCIBackend(backend: IQMBackendBase, mitigation_level: int = 1, calibration_shots: int = 1000, calibration_file: str | None = None)#

Bases: object

FiQCI backend wrapper that applies error mitigation automatically.

Mitigation levels:
  • 0: No error mitigation (raw results)

  • 1: Readout error mitigation using M3 (default)

  • 2: Level 1 + dynamical decoupling (DD)

  • 3: Level 2 + Pauli twirling

Parameters:
  • backend – An IQMBackendBase instance to wrap.

  • mitigation_level – Error mitigation level (0-3). Default is 1.

  • calibration_shots – Number of shots for calibration circuits. Default is 1000.

  • calibration_file – Optional path to save/load M3 calibration data.

__init__(backend: IQMBackendBase, mitigation_level: int = 1, calibration_shots: int = 1000, calibration_file: str | None = None) None#

Initialize the FiQCI backend wrapper.

Parameters:
  • backend – An IQMBackendBase instance to wrap.

  • mitigation_level – Error mitigation level (0-3). Default is 1.

  • calibration_shots – Number of shots for calibration circuits. Default is 1000.

  • calibration_file – Optional path to save/load M3 calibration data.

Raises:

ValueError – If mitigation_level is not in range 0-3.

property backend: IQMBackendBase#

Get the underlying backend.

property mitigation_level: int#

Get the current mitigation level.

property raw_counts: list[dict[str, int]] | None#

Get the raw (unmitigated) counts from the most recent run.

The list is flat with one entry per circuit submitted to the backend, in submission order. With Pauli twirling enabled this is the per-twirl counts before any averaging, so the length is num_input_circuits * (num_twirls + 1) and entries for the same input circuit are contiguous.

Note

Because post-processing is now lazy, this is populated only after the run’s mitigated result() has been retrieved at least once. It returns None until then.

Returns:

List of raw count dictionaries, or None if no run’s result has been computed yet.

property mitigator_options: dict[str, Any]#

Get current mitigator settings.

Returns:

A dictionary of current mitigator settings and their values.

total_circuits_generated(num_base_circuits: int, detailed: bool = False) int | dict[str, int]#

Calculate total circuits generated for a given number of base circuits and observables.

init_pauli_twirl(enabled: bool, num_twirls: int = 10, gates_to_twirl: Iterable[Gate] | None = None) None#

Initialize Pauli twirling settings.

Parameters:
  • enabled – Whether Pauli twirling is enabled.

  • num_twirls – Number of twirled circuits to generate per input circuit.

  • gates_to_twirl – Optional list of gates to twirl, if None, all two-qubit basis gates will be twirled.

dd(enabled: bool = True, gate_sequences: list[tuple[int, str | list[tuple[float, float]], str]] | None = None) None#

Set dynamical decoupling settings for the backend.

Parameters:
  • enabled – Whether to enable dynamical decoupling.

  • gate_sequences – List of (threshold_length, sequence, strategy) tuples defining DD behavior. See build_dd_options for details on each field.

rem(enabled: bool = True, calibration_shots: int = 1000, calibration_file: str | None = None) None#

Set readout error mitigation settings for the backend.

Parameters:
  • enabled – Whether to enable readout error mitigation.

  • calibration_shots – Number of shots to use for calibration circuits (default: 1000).

  • calibration_file – Optional calibration file to use for readout error mitigation.

pauli_twirl(enabled: bool, num_twirls: int = 10, gates_to_twirl: list | None = None) None#

Set Pauli twirling settings for the backend.

Parameters:
  • enabled – Whether to enable Pauli twirling.

  • num_twirls – Number of twirled circuits to generate per input circuit (default: 10).

  • gates_to_twirl – Optional list of gates to twirl, if None, all two-qubit basis gates will be twirled.

run(circuits: QuantumCircuit | list[QuantumCircuit], shots: int = 1024, max_batch_size: int = 100, **kwargs: Any) MitigatedJob | BatchedJob#

Submit quantum circuits and return a lazy job handle immediately.

Circuits are submitted to the backend (in batches), and a handle is returned right away without waiting for results: the per-batch job_id()``s and ``status() are available immediately, and any configured error mitigation is deferred until the handle’s result() is first called.

Parameters:
  • circuits – Single quantum circuit or list of circuits to execute.

  • shots – Number of shots. Default is 1024.

  • max_batch_size – Maximum number of circuits per backend job. The (post-twirl) circuit list is flattened and split into batches of this size; the resulting jobs are wrapped so that the returned handle’s result() exposes a single combined Result indexed in submission order (default: 100).

  • **kwargs – Additional keyword arguments passed to backend.run().

Returns:

A BatchedJob handle (level 0) or a MitigatedJob view (level 1+). In both cases mitigation/combination is computed lazily on the first result() call.

Raises:

ValueError – If circuits is empty or invalid.