Skip to main content

QSafety QAE

qsafety-qae is a small research package for testing quantum amplitude estimation (QAE) on safety and reliability probability models. It separates a validated probability model from the estimator, simulator, circuit builder, and optional QPU runner so that examples are reproducible without depending on the original project directory.

The package supports:

  • finite mixtures of fault, failure, or accident-scenario probabilities;
  • exact weighted probability calculation;
  • classical Monte Carlo and ideal maximum-likelihood QAE (ML-QAE) at the same equivalent oracle-query budget;
  • Qiskit state preparation, Grover amplification checks, and Aer simulation;
  • opt-in IBM Quantum preview and execution with a mandatory confirmation flag.

Installation

Core estimators require only NumPy:

python -m pip install qsafety-qae

Install optional circuit or IBM Runtime support when needed:

python -m pip install "qsafety-qae[qiskit]"
python -m pip install "qsafety-qae[ibm]"

Python interface

from qsafety import RiskDistribution, compare_estimators

risk = RiskDistribution(
    weights=[0.25, 0.25, 0.25, 0.25],
    probabilities=[0.0095, 0.0145, 0.0231, 0.0638],
    labels=["very low", "low", "medium", "high"],
)

print(risk.probability)

mc, qae = compare_estimators(
    risk,
    powers=[0, 1, 2],
    shots=1024,
    repeats=1000,
    seed=42,
)
print(mc.rmse, qae.rmse)

Build and validate actual Qiskit circuits:

from qsafety.circuits import build_qae_circuits, run_aer, validate_bundle

print(validate_bundle(risk, powers=[0, 1, 2]))
bundle = build_qae_circuits(risk, powers=[0, 1, 2])
result = run_aer(risk, powers=[0, 1, 2], shots=4096, seed=42)
print(result.estimate.probability)

CSV and command-line interface

Input CSV files need one row per scenario or risk stratum:

label,weight,probability
very_low,0.25,0.0095
low,0.25,0.0145
medium,0.25,0.0231
high,0.25,0.0638
qsafety validate examples/phmsa_risk_strata.csv --label-column label
qsafety compare examples/phmsa_risk_strata.csv --label-column label \
  --powers 0 1 2 --shots 1024 --repeats 1000
qsafety circuits examples/phmsa_risk_strata.csv --label-column label

Commands print machine-readable JSON. The circuit command is available only with the qiskit extra.

IBM Quantum safety guard

preview_ibm transpiles circuits but does not submit them. The returned backend and circuit resources should be reviewed before calling run_ibm. Submission is blocked unless confirm=True is passed explicitly.

from qsafety.ibm import preview_ibm, run_ibm

preview = preview_ibm(risk, shots=512, open_plan_only=True)
print(preview.backend, preview.executions, preview.resources)

# This is the only call that submits a QPU workload.
result = run_ibm(preview, confirm=True)

Credentials are read by qiskit-ibm-runtime; this package never stores API tokens.

Interpretation limits

The MC/QAE comparison is an algorithm-level comparison at an equal equivalent oracle-query budget. It is not a wall-clock speed, energy-use, or end-to-end quantum-advantage claim. State preparation, transpilation, QPU queue time, and error mitigation are separate costs. Input-data and model uncertainty can also be larger than either estimator's sampling error.

The included PHMSA-derived four-stratum file is a compact worked example, not a pipeline-segment prediction model. It estimates a conditional outcome among reported incidents and must not be used as an operational safety decision rule.

Reproducible development

python -m pip install -e ".[dev,qiskit]"
pytest
python -m build
twine check dist/*

Legacy research scripts remain in the repository for traceability. Generated study data and results stay local and are excluded from the public package. Stable third-party integrations should use the public qsafety interface documented above.

License and citation

The software is released under the Apache License 2.0. Citation metadata is in CITATION.cff. The version DOI will be added after the first Zenodo archive is created.

Metadata

Release files for qsafety-qae 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for qsafety-qae 0.1.1
File Size Uploaded
qsafety_qae-0.1.1.tar.gz 21.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for qsafety-qae 0.1.1
File Interpreter ABI Platform
qsafety_qae-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 38.8 kB

Release files / qsafety_qae-0.1.1.tar.gz

Download URL qsafety_qae-0.1.1.tar.gz
Size 21.5 kB
Tags Source
SHA-256 checksum
How to use checksums
8dd56c28a6f6194f238d265e87e5f909c1ad1ae9c10099f0c8e75901883aa7fa
BLAKE2b-256 checksum
How to use checksums
9878d7e0eb7c52a761ede7fe3d83efb7ec9448d72b6e83b63bea0f913a5bb35c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 5, 2026.

Transparency log

Release files / qsafety_qae-0.1.1-py3-none-any.whl

Download URL qsafety_qae-0.1.1-py3-none-any.whl
Size 17.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f0e0108f2e5a1f041426870d61665bf65b334d8238ae7a240d125a7c9ab4cce0
BLAKE2b-256 checksum
How to use checksums
0c8605e4e12cd3dd2ecee3b58d578c05a2aab23b8381414731b1d6ec49d89363
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 5, 2026.

Transparency log

Release history Release notifications | RSS feed

0.1.3

2 release files

0.1.2

2 release files

This release

0.1.1 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page