mthree.M3Mitigation

class M3Mitigation(system=None, iter_threshold=4096)[source]

Main M3 calibration class.

Parameters:
  • system (Backend) – Target backend.

  • iter_threshold (int) – Sets the bitstring count at which iterative mode is turned on (assuming reasonable error rates).

system

The target system or execution manager.

Type:

Backend

system_info

Information needed about the system

Type:

dict

cal_method

Calibration method used

Type:

str

cal_timestamp

Time at which cals were taken

Type:

str

single_qubit_cals

1Q calibration matrices

Type:

list

Methods

apply_correction(counts, qubits[, distance, ...])

Applies correction to given counts.

cals_from_file(cals_file)

Generated the calibration data from a previous runs output

cals_from_matrices(matrices)

Init calibration data from list of NumPy arrays.

cals_from_system([qubits, shots, method, ...])

Grab calibration data from system.

cals_to_file([cals_file])

Save calibration data to JSON file.

cals_to_matrices()

Return single qubit cals as list of NumPy arrays

readout_fidelity([qubits])

Compute readout fidelity for calibrated qubits.

reduced_cal_matrix(counts, qubits[, distance])

Return the reduced calibration matrix used in the solution.

tensored_cals_from_file(cals_file)

Generated the tensored calibration data from a previous runs output

tensored_cals_from_system([qubits, shots, ...])

Grab calibration data from system.

apply_correction(counts, qubits, distance=None, method='auto', max_iter=25, tol=0.0001, return_mitigation_overhead=False, details=False)[source]

Applies correction to given counts.

Parameters:
  • counts (dict, list) – Input counts dict or list of dicts.

  • qubits (dict, array_like) – Qubits on which measurements applied.

  • distance (int) – Distance to correct for. Default=num_bits

  • method (str) – Solution method: ‘auto’, ‘direct’ or ‘iterative’.

  • max_iter (int) – Max. number of iterations, Default=25.

  • tol (float) – Convergence tolerance of iterative method, Default=1e-4.

  • return_mitigation_overhead (bool) – Returns the mitigation overhead, default=False.

  • details (bool) – Return extra info, default=False.

Returns:

Dictionary of quasiprobabilities if

input is a single dict, else a collection of quasiprobabilities.

Return type:

QuasiDistribution or QuasiCollection

Raises:

M3Error – Bitstring length does not match number of qubits given.

cals_from_file(cals_file)[source]

Generated the calibration data from a previous runs output

Parameters:

cals_file (str) – A string path to the saved counts file from an earlier run.

Raises:

M3Error – Calibration in progress.

cals_from_matrices(matrices)[source]

Init calibration data from list of NumPy arrays.

Missing entires are set to None elements.

Parameters:

matrices (list_like) – List of cals as NumPy arrays

Raises:

M3Error – If system set error if list length != num_qubits on system

cals_from_system(qubits=None, shots=None, method=None, initial_reset=False, rep_delay=None, cals_file=None, async_cal=True, runtime_mode=None)[source]

Grab calibration data from system.

Parameters:
  • qubits (array_like) – Qubits over which to correct calibration data. Default is all.

  • shots (int) – Number of shots per circuit. min(1e4, max_shots).

  • method (str) – Type of calibration, ‘balanced’ (default for hardware), ‘independent’ (default for simulators), or ‘marginal’.

  • initial_reset (bool) – Use resets at beginning of calibration circuits, default=False.

  • rep_delay (float) – Delay between circuits on IBM Quantum backends.

  • cals_file (str) – Output path to write JSON calibration data to.

  • async_cal (bool) – Do calibration async in a separate thread, default is True.

  • runtime_mode (Batch or Session) – Mode to run jobs in if using IBM system, default=None

Returns:

List of jobs submitted.

Return type:

list

Raises:

M3Error – Called while a calibration currently in progress.

cals_to_file(cals_file=None)[source]

Save calibration data to JSON file.

Parameters:

cals_file (str) – File in which to store calibrations.

Raises:
  • M3Error – Calibration filename missing.

  • M3Error – Mitigator is not calibrated.

cals_to_matrices()[source]

Return single qubit cals as list of NumPy arrays

Returns:

List of cals as NumPy arrays

Return type:

list

readout_fidelity(qubits=None)[source]

Compute readout fidelity for calibrated qubits.

Parameters:

qubits (array_like) – Qubits to compute over, default is all.

Returns:

List of qubit fidelities.

Return type:

list

Raises:
  • M3Error – Mitigator is not calibrated.

  • M3Error – Qubit indices out of range.

reduced_cal_matrix(counts, qubits, distance=None)[source]

Return the reduced calibration matrix used in the solution.

Parameters:
  • counts (dict) – Input counts dict.

  • qubits (array_like) – Qubits on which measurements applied.

  • distance (int) – Distance to correct for. Default=num_bits

Returns:

2D array of reduced calibrations. dict: Counts in order they are displayed in matrix.

Return type:

ndarray

Raises:

M3Error – If bit-string length does not match passed number of qubits.

tensored_cals_from_file(cals_file)[source]

Generated the tensored calibration data from a previous runs output

Parameters:

cals_file (str) – A string path to the saved counts file from an earlier run.

tensored_cals_from_system(qubits=None, shots=None, method='balanced', rep_delay=None, cals_file=None)[source]

Grab calibration data from system.

Parameters:
  • qubits (array_like) – Qubits over which to correct calibration data. Default is all.

  • shots (int) – Number of shots per circuit. Default is min(1e4, max_shots).

  • method (str) – Type of calibration, ‘balanced’ (default), ‘independent’, or ‘marginal’.

  • rep_delay (float) – Delay between circuits on IBM Quantum backends.

  • cals_file (str) – Output path to write JSON calibration data to.