03. QAE Risk Analysis
Archived Quadratic speedup negated by I/OQuadratic O(1/ε) speedup proven but QEC overhead requires ε < 10⁻⁴. Distribution loading is O(N). Archived per Troyer framework.
Resource Estimation (Azure Quantum RE)
Resource Breakdown
Stage D: Advantage Evidence Package
Quadratic speedup is provable but practical advantage requires efficient amplitude encoding. Current O(2^n) state preparation circuit eliminates speedup for structured distributions.
- Amplitude encoding circuit depth scales exponentially — practical advantage requires efficient state preparation
- 293k physical qubits required — beyond current NISQ devices
- No noise model applied; fault-tolerant execution assumed
- Classical importance sampling may close the gap for structured distributions
Noise Resilience (Depolarizing Simulation)
Ideal outcome: [Zero, One] (41% probability)
Cross-Platform Emulator Results (100 shots)
Troyer Utility-Scale Classification
QAE provides provable quadratic speedup for amplitude estimation. However, the constant-factor overhead of error correction means utility requires problems with ε < 10⁻⁴ where the quadratic advantage overcomes QEC cost.
Multi-Model Resource Comparison
Physical qubit requirements across 6 qubit technologies × 2 QEC schemes (inspired by Troyer Architecture Series, Part 3).
| Qubit Model | QEC | Physical Qubits | Logical Qubits |
|---|---|---|---|
| Majorana (ns, 1e-6) | surface_code | 17,000 | 40 |
| Superconducting (ns, 1e-4) | surface_code | 30,000 | 40 |
| Trapped Ion (μs, 1e-4) | surface_code | 30,000 | 40 |
| Majorana (ns, 1e-6) (Floquet) | floquet_code | 47,520 | 40 |
| Trapped Ion (μs, 1e-3) | surface_code | 140,120 | 40 |
| Superconducting (ns, 1e-3) | surface_code | 293,120 | 40 |
| Majorana (ns, 1e-4) | surface_code | 375,000 | 40 |
| Majorana (ns, 1e-4) (Floquet) | floquet_code | 430,480 | 40 |
Problem Documentation
Problem 03: Quantum Amplitude Estimation for Risk Analysis
Overview
Quantum Amplitude Estimation (QAE) estimates the probability of marked states inside a quantum superposition. Applied to risk analysis, it enables tail probability estimation with quadratically fewer oracle queries than classical Monte Carlo sampling.
Algorithm
The QAE workflow for risk estimation consists of the following stages:
1. Encode the loss distribution as amplitudes of a quantum state.
2. Mark “tail risk” outcomes (loss exceeding a threshold) with an oracle.
3. Apply Iterative Quantum Amplitude Estimation (IQAE): adaptive rounds of Grover amplification with Clopper-Pearson confidence intervals no QPE register or QFT needed.
4. Achieve ε precision using O(1/ε) calls to the oracle, compared with O(1/ε²) samples for classical Monte Carlo.
Implementation
- **Q# code**: `qsharp/src/Main.qs` implements both **canonical QAE** (QPE-based) and **IQAE** (iterative, no QPE register). IQAE is the recommended default per QAEUpdates2026 guidelines.
- **IQAE Python driver**: `python/iqae_driver.py` provides the full adaptive IQAE algorithm with Clopper-Pearson confidence intervals, variance-reduced MC baselines, and CVaR/VaR bisection search.
- **Hardware kernel**: `qsharp/HardwareKernel.qs` contains QIR-compatible kernels for Azure Quantum submission (syntax checker validated).
- **Python tooling**: `python/` contains Monte Carlo baselines and visualization scripts.
- **Instances**: `instances/` provides YAML files that parameterize the loss distribution and thresholds.
- **Estimates**: `estimates/` captures resource estimation outputs produced by Azure Quantum tooling.
- **Documentation**: See [QAE_IMPLEMENTATION_SUMMARY.md](QAE_IMPLEMENTATION_SUMMARY.md) for comprehensive technical details.
Mathematical Background
Risk Model
Consider a portfolio with loss distribution L. The quantity of interest is the tail probability P(L > threshold), the chance that losses exceed a specified VaR boundary.
Quantum Encoding
1. State preparation loads the loss distribution into amplitudes using controlled rotations (final circuit to be published alongside the quantum implementation).
2. Oracle marking flips an ancilla qubit whenever the simulated loss breaches the threshold.
3. Amplitude estimation extracts the amplitude of the marked subspace, which equals the desired tail probability.
Quantum Advantage
- **Classical**: O(1/ε²) samples for additive precision ε.
- **Quantum**: O(1/ε) oracle invocations for the same precision.
- **Outcome**: Quadratic speedup becomes meaningful for high confidence levels and expensive payoff calculations.
Usage
Build and Test
make build
make test
make run INSTANCE=small
Resource Estimation
make estimate # Surface-code defaults
make estimate TARGET=qubit_gate_ns_e3 # Specific hardware target
make sweep # Precision sweep for comparison
Analysis and Plotting
make analyze INSTANCE=small # Generate comparison plots (instance-driven)
make calibrate INSTANCE=medium CALIBRATION_RUNS=10
make compare # Compare quantum vs classical
Problem Instances
Small (`instances/small.yaml`)
- Log-normal loss distribution with μ = 0, σ = 1.
- Tail threshold at the 95th percentile (VaR 95%).
- Precision ε = 0.1 requiring roughly 8–10 logical qubits.
Medium (`instances/medium.yaml`)
- Mixture of log-normal components producing fat tails.
- Tail threshold at the 99th percentile (VaR 99%).
- Precision ε = 0.01 requiring roughly 12–15 logical qubits.
Current repository instances include small and medium.
Status Checklist
- [x] Problem specification
- [x] **Canonical QAE implementation** with Grover operators and QPE
- [x] Azure Quantum resource estimation
- [x] Classical Monte Carlo baseline
- [x] Analysis and visualization
- [x] Comprehensive technical documentation
- [x] Calibrated baseline instance (phase/oracle alignment and entrypoint fix)
- [ ] Broader calibration hardening across more instances and seeds
Objective Maturity Gate
- **Current gate**: **Stage C complete** (hardware-aware validation baseline in place with uncertainty-bounded calibration evidence).
- **Next gate target**: **Stage D** (advantage evidence package hardened for promotion from `projected` to `demonstrated` claim category).
Stage C evidence references for this problem:
- Uncertainty-bounded estimates: `estimates/quantum_estimate_ensemble.json` and run-level samples in `estimates/quantum_estimate_run*.json`.
- Calibration trend history: `estimates/quantum_calibration_history.json`.
- Runtime mapping and execution assumptions: `qsharp/RuntimeConfig.qs` generated via `python/write_runtime_config.py`; layout overhead and estimator assumptions documented in this README and `QAE_IMPLEMENTATION_SUMMARY.md`.
- Validation-oriented claim language synchronized in `README.md`, this problem README, and `docs/QAE_PROJECT_COMPLETION.md`.
DiVincenzo Readiness (Stage C/D Overlay)
| Criterion | Status | Evidence / Notes |
|---|---|---|
| Scalable qubit system | met | Logical/physical resource estimates are tracked per architecture in estimates/ and summarized in this README. |
| Initialization | partial | Distribution loading and threshold marking are documented, but production-grade portfolio data loaders are still future work. |
| Coherence vs gate time | partial | Runtime and T-state projections are available; backend-calibrated coherence margins remain part of Stage D hardening. |
| Universal gate set | met | Canonical QAE with Grover + QPE is implemented in qsharp/Program.qs and compiled through supported Q# toolchain assumptions. |
| Qubit-specific measurement | partial | Ensemble-based uncertainty artifacts exist (estimates/quantum_estimate_ensemble.json), but hardware readout characterization is still pending. |
Results Summary
Test Case: 4 loss qubits (16 levels), 6 precision qubits, log-normal(0,1), threshold=2.5, theoretical tail probability 18.98%
Latest Azure Quantum Resource Estimates:
| Architecture | Physical Qubits | Runtime | T-States | Logical Qubits |
|--------------|-----------------|---------|----------|----------------|
| gate_ns_e3 (optimal) | 594k | 6.4s | 965k | 13 (38 layout) |
| gate_ns_e4 | 561k | 6.7s | 965k | 13 (38 layout) |
| maj_ns_e4 (Majorana) | 400k | 28.5s | 965k | 13 (38 layout) |
T-State Breakdown (gate_ns_e3):
- Rotation gates: 36.9k × 20 = **738k** (76%)
- CCZ gates: 56.8k × 4 = **227k** (24%)
- Direct T gates: 240 (<1%)
Comparison with Other Quantum Algorithms:
- **QAE**: 594k qubits, 6.4s, 965k T-states
- **HHL** (Problem 01): 18.7k qubits, 52ms, 903 T-states (31.8× less qubits)
- **VQE** (Problem 01): 48.5k-110k qubits, 47-182μs, 18 T-gates (5.4-12.2× less qubits)
Classical Comparison
Current Test Results:
- **Classical Monte Carlo** (10k samples): 18.98% ± 0.39% (0% relative error)
- **QAE Current** (20 ensemble runs, 24 repetitions/run): 19.58% ± 1.82% (about 3.2% relative error)
- **Theoretical**: 18.98%
Complexity Analysis:
- **Classical Monte Carlo**: O(1/ε²) samples
- For ε = 0.01: ~10,000 samples
- **Quantum Amplitude Estimation**: O(1/ε) oracle calls
- For ε = 0.01: ~100 queries
- **Quadratic speedup** for high precision
Implementation Status: Calibrated baseline instance is accurate with proper Grover operators and QPE; next work is robustness hardening across additional instances and ensemble seeds.
Advantage Claim Contract
- **Claim category (current)**: `projected`.
- **Speedup statement**: QAE provides asymptotic O(1/epsilon) query scaling versus classical O(1/epsilon^2), contingent on oracle/state-preparation and error-correction assumptions.
- **Fair baseline**: Monte Carlo baseline in `python/classical_baseline.py` with documented confidence intervals.
- **Assumption log**:
- Tail-probability model uses parameterized synthetic loss distributions, not full production portfolios.
- Current QAE output quality depends on calibration and ensemble averaging settings.
- Resource estimates assume fault-tolerant profiles from Azure Quantum Resource Estimator.
- **Promotion rule**: Upgrade claim to `demonstrated` only after Stage C evidence is satisfied and instance-level uncertainty targets are met.
Stage D Hardening Package
- Stage D evidence file: `STAGE_D_ADVANTAGE_EVIDENCE.md`.
- This package captures baseline-fairness review status, uncertainty methodology, backend assumptions, sensitivity analysis, and promotion checklist criteria.
Calibration Workflow
make calibrate INSTANCE=small CALIBRATION_RUNS=20
make calibrate-track INSTANCE=medium CALIBRATION_FAST_RUNS=3
This command runs repeated Q# executions through python/analyze.py --ensemble-runs ..., stores per-run outputs in estimates/quantum_estimate_run*.json, and writes aggregate metrics to estimates/quantum_estimate_ensemble.json.
make calibrate-track runs a fast ensemble, appends a persistent record to estimates/quantum_calibration_history.json, and syncs the latest headline numbers into docs/QAE_PROJECT_COMPLETION.md.
Quantum advantage becomes compelling when:
- Sub-percent tail probabilities are required for regulatory reporting.
- Loss distributions are expensive to sample due to complex correlations.
- Multiple related risk metrics must be estimated simultaneously.
- Precision requirements are high (ε < 0.01).
References
- [Quantum Amplitude Estimation](https://arxiv.org/abs/quant-ph/0005055) Brassard et al.
- [Quantum Risk Analysis](https://arxiv.org/abs/1906.02573) Woerner & Egger.
- [Financial Applications](https://arxiv.org/abs/1905.02666) Egger et al.
- [Azure Quantum QAE](https://learn.microsoft.com/azure/quantum/user-guide/libraries/numerics/amplitude-estimation).
Notes
This benchmark demonstrates a pathway to quantum advantage in financial risk analytics. Production deployments will require:
- More expressive state preparation that captures real portfolio loss distributions.
- Noise-aware algorithm design and error mitigation techniques.
- Integration with classical risk pipelines and data governance policies.
- Holistic cost/benefit analysis against classical accelerators.
High-impact use cases include regulatory stress testing, extreme tail-risk monitoring, and rapid what-if scenario analysis across large derivative books.
Reproduce It
cd problems/03_qae_risk
make classical # Run classical baseline
make analyze # Generate plots
make build # Validate Q# compilation
make run # Run Q# entry pointKey Files
qsharp/src/Main.qsQuantum algorithm implementationqsharp/HardwareKernel.qsAzure-submittable QIR kernelpython/classical_baseline.pyClassical reference implementationestimates/classical_baseline.jsonBaseline metrics