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 project's independently authored software is released under the MIT License. Third-party software, standards, data, and documentation retain their own terms; see THIRD_PARTY_NOTICES.md. Citation metadata is in CITATION.cff. The Zenodo concept DOI links the archived software versions. Cite a version-specific DOI when reporting results obtained with a particular release.

Research scripts

Selected estimator, uncertainty, and finite-oracle scripts are available in this repository. Their optional dependencies can be installed with python -m pip install -e ".[dev,qiskit,research]". See RESEARCH_CODE.md for the published scope, required local inputs, and data-free tests. Release 0.1.3 archives the research scripts in the tagged GitHub repository and Zenodo software record. The PyPI wheel and source distribution provide the core qsafety package, not the repository-only research scripts. Installing the research extra installs optional dependencies only; clone the tagged repository to obtain those scripts. No release bundles the full manuscript reproduction dataset.

Metadata

Release files for qsafety-qae 0.1.3

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.3
File Size Uploaded
qsafety_qae-0.1.3.tar.gz 23.8 kB Details

Built distribution (wheel)

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

Total release size: 38.0 kB

Release files / qsafety_qae-0.1.3.tar.gz

Download URL qsafety_qae-0.1.3.tar.gz
Size 23.8 kB
Tags Source
SHA-256 checksum
How to use checksums
48c53efc02536bb6be2f732c79f2de9b0be1b8f0ccc3a2d52bba6d731fa17474
BLAKE2b-256 checksum
How to use checksums
ddabe975ddc71704d3312dfd6d6bb8bf3bb9e6f38b70319c74ab7a97a47aedf6
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 Oct 9, 2026.

Transparency log

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

Download URL qsafety_qae-0.1.3-py3-none-any.whl
Size 14.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f6ca20a8965db33364b0ed4d8f95385d9dca249916804dfa78473f87270e7701
BLAKE2b-256 checksum
How to use checksums
9cd4354d9eb946cf9ab78158c68282b674814f4b509dfc476bd025efad84e219
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 Oct 9, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.3 This release

2 release files

0.1.2

2 release files

0.1.1

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