Skip to main content

Automatic quantum error mitigation recipe generator for NISQ circuits

Project description

EMRG

CI

Error Mitigation Recipe Generator -- Automatic quantum error mitigation for NISQ circuits.

EMRG analyzes your quantum circuit and generates ready-to-run, explained Mitiq-powered error mitigation code. No manual tuning required.

Status: v0.2.0 -- ZNE + PEC support. Actively developed, grant-funded roadmap ahead.


Why EMRG?

Noise limits every computation on today's hardware. Error mitigation techniques like Zero-Noise Extrapolation (ZNE) and Probabilistic Error Cancellation (PEC) can boost fidelity 2--10x, but configuring them manually is tedious:

  • Which technique -- ZNE or PEC?
  • Which extrapolation factory? Linear, Richardson, Polynomial?
  • What scale factors for your circuit depth?
  • How do you balance overhead vs. accuracy?

EMRG handles this automatically. Give it a circuit, get back optimized mitigation code with clear explanations of why each choice was made. EMRG selects between techniques, not just tunes settings.

How It Works

Quantum Circuit --> [Analyze] --> [Technique Selection] --> [Code Generator] --> Mitigated Code
                                   ZNE or PEC
  1. Parse & Validate -- Load a Qiskit QuantumCircuit or QASM file
  2. Extract Features -- Depth, gate counts, multi-qubit gate density, estimated noise factor, PEC overhead
  3. Select Technique -- Choose between ZNE and PEC based on circuit characteristics
  4. Generate Code -- Output runnable Python with Mitiq imports, config, and inline rationale

Heuristic Rules (v0.2)

Circuit Profile Technique Configuration Rationale
Depth ≤ 30 + noise model + overhead < 1000 PEC Depolarizing representations Unbiased error cancellation when overhead is manageable
Depth < 20, low multi-qubit gates ZNE LinearFactory [1.0, 1.5, 2.0] Conservative for shallow circuits
Depth 20--50 ZNE RichardsonFactory [1.0, 1.5, 2.0, 2.5] Better extrapolation for moderate noise
Depth > 50 or high noise ZNE PolyFactory (deg 2--3) [1.0, 1.5, 2.0, 2.5, 3.0] Handles non-linear noise scaling

Quick Start

Installation

pip install emrg

Or from source:

git clone https://github.com/FedorShind/EMRG.git
cd EMRG
pip install -e ".[dev]"

CLI Usage

# Generate mitigation recipe from a QASM file
emrg generate docs/examples/bell_state.qasm

# With verbose explanation
emrg generate docs/examples/bell_state.qasm --explain

# Save to file
emrg generate circuit.qasm -o mitigated.py

# Analyze circuit features
emrg analyze docs/examples/simple_vqe.qasm

# JSON output (for scripting)
emrg analyze circuit.qasm --json

# Force PEC technique (requires noise model)
emrg generate circuit.qasm --technique pec --noise-model

# Force ZNE even when PEC is viable
emrg generate circuit.qasm --technique zne

Python API

from qiskit import QuantumCircuit
from emrg import generate_recipe

# Create a circuit
qc = QuantumCircuit(2, 2)
qc.h(0)
qc.cx(0, 1)
qc.measure([0, 1], [0, 1])

# Generate mitigation recipe (one-liner)
result = generate_recipe(qc)
print(result)             # Ready-to-run Python script
print(result.rationale)   # Why these parameters were chosen
print(result.features)    # Circuit analysis details

# With verbose explanations
result = generate_recipe(qc, explain=True)

# With PEC (when a noise model is available)
result = generate_recipe(qc, noise_model_available=True)
print(result.recipe.technique)  # "pec" for shallow circuits

Example Output

# =============================================================
# EMRG v0.2.0 -- Error Mitigation Recipe
# Circuit: 2 qubits, depth 3, 1 multi-qubit gates
# Noise estimate: 0.011 (low)
# =============================================================
#
# Recommendation: LinearFactory + fold_global
#
# =============================================================

from mitiq.zne import execute_with_zne
from mitiq.zne.inference import LinearFactory
from mitiq.zne.scaling import fold_global

factory = LinearFactory(scale_factors=[1.0, 1.5, 2.0])

def execute(circuit):
    """Execute a circuit and return an expectation value (float)."""
    # Replace with your actual backend
    raise NotImplementedError("Replace this with your executor.")

mitigated_value = execute_with_zne(
    circuit,
    execute,
    factory=factory,
    scale_noise=fold_global,
)

print(f"Mitigated expectation value: {mitigated_value}")

Project Structure

EMRG/
├── src/emrg/
│   ├── __init__.py      # Public API and generate_recipe()
│   ├── _version.py      # Single source of truth for version
│   ├── analyzer.py      # Circuit feature extraction
│   ├── heuristics.py    # Rule-based decision engine
│   ├── codegen.py       # Template-based code generation
│   ├── cli.py           # Click CLI interface
│   └── py.typed         # PEP 561 type marker
├── tests/               # 215+ pytest tests, 99% coverage
├── docs/examples/       # Example circuits (Python + QASM)
└── pyproject.toml       # Package configuration

Benchmarks

Real measurements from EMRG v0.1.x (ZNE path), collected automatically by benchmarks/run_benchmark.py.

Environment: Python 3.12, Windows 11 | Qiskit 2.3.0, Mitiq 0.48.1

Tool Performance

EMRG relies on pure Qiskit introspection (no simulation), so generate_recipe() completes in sub-millisecond time even for large circuits. Median of 100 runs:

Circuit Qubits Depth Gates Multi-Q Factory Time Memory
Bell state 2 3 2 1 LinearFactory 0.033 ms 3.8 KB
GHZ-5 5 6 5 4 LinearFactory 0.047 ms 3.8 KB
GHZ-10 10 11 10 9 LinearFactory 0.069 ms 3.8 KB
Random 10q, 3 layers 10 7 45 15 LinearFactory 0.159 ms 4.1 KB
VQE 10q, 4 layers 10 20 76 36 PolyFactory 0.234 ms 3.9 KB
Random 20q, 6 layers 20 13 180 60 PolyFactory 0.478 ms 6.2 KB
Random 30q, 10 layers 30 21 450 150 PolyFactory 1.10 ms 7.9 KB
Random 50q, 15 layers 50 31 1125 375 PolyFactory 2.59 ms 11.1 KB

A 50-qubit, 1125-gate circuit is analyzed and produces a full mitigation recipe in under 3 ms with ~11 KB memory overhead.

ZNE Fidelity

To validate that EMRG selects effective mitigation parameters, we ran ZNE end-to-end on noisy simulations (Cirq DensityMatrixSimulator with per-gate depolarizing noise) and compared the <Z> expectation value on qubit 0:

Circuit Qubits Depth Noise Factory Ideal Noisy Mitigated Error Reduction
X-flip, 2q 2 3 p=0.01 LinearFactory -1.0000 -0.9761 -1.0003 77x
X-flip, 3q 3 4 p=0.01 LinearFactory -1.0000 -0.9761 -1.0003 77x
X-flip, 2q 2 3 p=0.05 LinearFactory -1.0000 -0.8836 -0.9906 12x
X-flip, 3q 3 4 p=0.05 LinearFactory -1.0000 -0.8836 -0.9906 12x
VQE 4q, 2 layers 4 8 p=0.01 LinearFactory 0.0850 0.0775 0.0794 1.4x
VQE 4q, 4 layers 4 14 p=0.01 LinearFactory -0.1915 -0.1766 -0.1850 2.3x
VQE 4q, 2 layers 4 8 p=0.05 LinearFactory 0.0850 0.0523 0.0586 1.2x

EMRG-generated ZNE recipes reduce error across all tested circuits, with improvements from 1.2x on high-noise VQE ansatze up to 77x on structured low-noise circuits.

Reproduce

pip install -e ".[dev]" qiskit-aer
python benchmarks/run_benchmark.py

Roadmap

Phase 1 -- MVP (complete)

Everything needed to go from circuit to mitigation recipe in one command:

  • Project structure and packaging
  • Circuit analyzer (feature extraction)
  • Heuristic engine (ZNE: Linear + Richardson + Poly)
  • Code generator (template-based)
  • CLI with generate and analyze commands
  • Public Python API (generate_recipe())
  • Example circuits (Python + QASM) and documentation

Phase 2 -- More techniques, better validation (current)

Expand beyond ZNE so EMRG can recommend the right technique, not just the right ZNE settings:

  • Probabilistic Error Cancellation (PEC) support
  • Multi-technique selection (ZNE vs PEC)
  • PEC code generation template
  • --technique override and --noise-model CLI flags
  • 215+ tests, 99% coverage, zero lint warnings
  • Layerwise Richardson integration
  • --preview mode (noisy simulation + fidelity plots)
  • Real hardware benchmarks (IBM Quantum devices)
  • Expanded tutorials (VQE, QAOA, random circuits)

Phase 3 -- Multi-framework and community

Make EMRG useful regardless of which framework you use:

  • Cirq and PennyLane input support
  • Configurable heuristics file
  • Web/Colab interface

Tech Stack

  • Python 3.11+
  • Qiskit >= 1.0 -- Circuit representation and introspection
  • Mitiq >= 0.48 -- Error mitigation primitives
  • Click >= 8.0 -- CLI framework

Contributing

EMRG is open source and contributions are welcome. If you have ideas, find bugs, or want to add support for new mitigation techniques, open an issue or PR.

License

MIT -- Free for academic and commercial use.

Acknowledgments

Built on Mitiq by Unitary Fund. Inspired by the need to make quantum error mitigation accessible to everyone working with NISQ hardware.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

emrg-0.2.0.tar.gz (34.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

emrg-0.2.0-py3-none-any.whl (22.5 kB view details)

Uploaded Python 3

File details

Details for the file emrg-0.2.0.tar.gz.

File metadata

  • Download URL: emrg-0.2.0.tar.gz
  • Upload date:
  • Size: 34.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for emrg-0.2.0.tar.gz
Algorithm Hash digest
SHA256 c96268a1c0a5b78a0519597b1f2dd49702cabc725546dd435ae8454e335be7ea
MD5 05521f23e3bd2bb66d4a32d5e0c20ebf
BLAKE2b-256 1fe83a1dafb8389873dd0e210718a9d2e037ee772726025e8bed3a1134e1e864

See more details on using hashes here.

Provenance

The following attestation bundles were made for emrg-0.2.0.tar.gz:

Publisher: publish.yml on FedorShind/EMRG

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file emrg-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: emrg-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 22.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for emrg-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d8b5a5b5c67d958e170a1c9eb1ed27ad321b7623f8ccd45d3e607f801024959f
MD5 66416ec17a51c195d5beeb6653662913
BLAKE2b-256 ac7050b53f53f093fdd321f4229452eb717372a6da00ac79473c14a9287f9ff2

See more details on using hashes here.

Provenance

The following attestation bundles were made for emrg-0.2.0-py3-none-any.whl:

Publisher: publish.yml on FedorShind/EMRG

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page