uniqc.qem.m3 module¶
M3 readout error mitigator.
Provides confusion-matrix-based readout error mitigation with TTL-based calibration freshness enforcement.
- class uniqc.qem.m3.M3Mitigator(calibration_result=None, cache_path=None, max_age_hours=24.0, backend='dummy:local:simulator', qubit=None, cache_dir=None)[source]¶
Bases:
objectM3 (Matrix Misassignment Mitigation) readout error mitigator.
Uses a calibration confusion matrix to correct measurement outcomes via linear inversion. The calibration data can be provided directly or loaded from the calibration cache.
- Parameters:
calibration_result – Pre-loaded
ReadoutCalibrationResult.cache_path – Path to a cached calibration JSON file.
max_age_hours – Maximum acceptable age of calibration data in hours. If the cached data is older,
StaleCalibrationErroris raised.backend – Backend name used for cache lookup.
qubit – Qubit index or pair (for cache lookup).
- Raises:
StaleCalibrationError – If calibration data exceeds
max_age_hours.FileNotFoundError – If cache_path does not exist.
- apply(result)[source]¶
Apply mitigation to a
UnifiedResultand return a new one.This is the recommended pipeline-style API: call
M3Mitigator(...).apply(result)and feed the returned object straight back into any uniqc workflow that expects aUnifiedResult.- Parameters:
result – A
uniqc.backend_adapter.task.result_types.UnifiedResultproduced bysubmit_task/wait_for_result/simulate.- Returns:
A new
UnifiedResultwhosecounts/probabilitiesare mitigated.shots,platform,task_idand metadata are preserved; the original is kept asraw_result.
- property calibration_result¶
- mitigate_counts(counts)[source]¶
Apply M3 mitigation to measurement counts.
Uses linear inversion:
n_corrected = C⁻¹ · n_obs. The result is normalized so the total counts are preserved.- Parameters:
counts – Dict mapping outcome (int bitstring) → observed count.
- Returns:
Dict mapping outcome → corrected count (float, preserved total).