Skip to main content

VeriQ AncillaGuard

Qiskit License: MIT

VeriQ AncillaGuard verifies whether a unitary Qiskit circuit restores selected dirty ancilla qubits for every possible input state. Unsafe targets are diagnosed as logic errors, phase errors, or both. Ancilla-local violations can also be repaired with a short sequence of single-qubit rotations.

The implementation accompanies the paper Formal Verification of Quantum Ancilla Safety. It provides two complementary verification backends:

  • MQT QCEC, an equivalence-checking backend that works out of the box.
  • Quokka-Sharp, the weighted-model-counting backend used by the paper.

This experimental 0.1 release intentionally bundles the paper-era Quokka-Sharp implementation. Migrating to the current upstream PyPI package is planned separately so that the validated research kernel remains stable.

Installation

VeriQ AncillaGuard requires Python 3.10 or newer and Qiskit 2.x.

python -m pip install veriq-ancillaguard

To install the latest source instead:

git clone https://github.com/veriq-toolkit/Ancilla-Safety.git
cd Ancilla-Safety
python -m pip install .

MQT QCEC is installed automatically. The Quokka backend additionally requires an executable GPMC weighted model counter. Point the package to it with either an argument or an environment variable:

export GPMC_PATH=/path/to/gpmc

The repository includes the pinned GPMC source under third_party/GPMC for reproducible Linux builds. Its build prerequisites are CMake, GMP, MPFR, zlib, and a C++ compiler.

Optional Docker Image

Docker is not required for the Python package. It is provided as a reproducible Linux environment that builds the pinned GPMC source and makes both backends available without a separate solver installation:

docker build -t veriq-ancillaguard .
docker run --rm veriq-ancillaguard --help
docker run --rm -v "$PWD:/data:ro" veriq-ancillaguard \
  verify /data/circuit.qasm --ancilla 0 --backend quokka

Installation Check

Run a built-in safe case and a known logic-error case after installation:

ancillaguard self-test

QCEC is always checked. Quokka is also checked when GPMC is available and is otherwise reported as skipped. To require a specific backend:

ancillaguard self-test --backend qcec
ancillaguard self-test --backend quokka --gpmc /path/to/gpmc

Quick Start

from qiskit import QuantumCircuit
from veriq_ancillaguard import verify_dirty_safety

circuit = QuantumCircuit(2)
circuit.cx(0, 1)
circuit.cx(0, 1)

result = verify_dirty_safety(
    circuit,
    ancillas=[circuit.qubits[1]],
    backend="qcec",
)

print(result.status)                  # SafetyStatus.SAFE
print(result.targets[0].logic_safe)  # True
print(result.targets[0].phase_safe)  # True

Targets may be Qiskit Qubit objects or global integer indices. Targets must be provided explicitly; the package never guesses which register contains ancillas.

To use Quokka-Sharp:

result = verify_dirty_safety(
    circuit,
    ancillas=[1],
    backend="quokka",
    gpmc_path="/path/to/gpmc",
)

Repair

The repair pipeline handles violations that remain local to an ancilla qubit. It returns a new circuit and leaves the input circuit unchanged.

from qiskit import QuantumCircuit
from veriq_ancillaguard import repair_dirty_safety

circuit = QuantumCircuit(1)
circuit.z(0)

result = repair_dirty_safety(circuit, ancillas=[0])
repaired = result.circuit

print(result.before.status)  # SafetyStatus.UNSAFE
print(result.after.status)   # SafetyStatus.SAFE
print(result.patches[0].angles)

Repair uses the Quokka backend and therefore requires GPMC. If an error leaves the ancilla entangled or correlated with other qubits, a local repair is not possible and the result reports the failure rather than changing unrelated qubits.

Command Line

OpenQASM 2 files can be checked without writing Python:

ancillaguard verify circuit.qasm --ancilla 'anc[0]' --backend qcec
ancillaguard verify circuit.qasm --ancilla 3 --backend quokka --gpmc /path/to/gpmc
ancillaguard repair circuit.qasm repaired.qasm --ancilla 'anc[0]' --gpmc /path/to/gpmc

Commands print JSON results and return a nonzero exit code when verification does not establish safety.

Benchmark Examples

Four OpenQASM 2 examples are included under examples/benchmarks. Each checks one documented ancilla target and is expected to be safe with both backends. Run all examples from a source checkout:

python examples/run_benchmarks.py --backend qcec
python examples/run_benchmarks.py --backend both --gpmc /path/to/gpmc

The large GHZ example contains 1399 qubits and is intended to demonstrate the backend workflow, not to define a portable performance baseline.

Supported Circuits

The framework currently targets purely unitary circuits. Measurements, resets, delays, classical control flow, and unbound parameters are rejected.

The frozen Quokka backend accepts the following basis instructions:

id, x, y, z, h, s, sdg, t, tdg,
rx, ry, rz, cx, cz, cs, csdg, ccx

Transpile other unitary instructions explicitly before invoking Quokka. The package does not silently transpile user circuits because preserving the exact verification boundary is important.

Result Semantics

For every selected ancilla, the verifier checks commutativity against Pauli-Z and Pauli-X:

  • failed Z check: ErrorKind.LOGIC
  • failed X check: ErrorKind.PHASE
  • both checks pass: the target is dirty safe
  • backend cannot decide: SafetyStatus.INCONCLUSIVE

MQT QCEC's equivalent_up_to_global_phase result is a failed commutativity check here. A non-trivial relative global phase between U and P U P is an anti-commutation witness, not a successful exact equality.

Development

python -m pip install -e '.[dev]'
pytest
ruff check src tests examples
python -m build
python -m twine check dist/*

Quokka integration tests run when GPMC_PATH is configured; otherwise they are skipped. See CONTRIBUTING.md for the contribution workflow.

Provenance and Citation

The bundled research backend is pinned to Quokka-Sharp commit 9131a8eab786ffe983a77af6bb374ffdeab06dc4. Detailed third-party provenance is recorded in NOTICE.md. Citation metadata is available in CITATION.cff.

The original artifact-evaluation package and experimental outputs are archived separately at Zenodo. The paper used the former repository URL Veri-Q/Ancilla-Safety. GitHub redirects that transferred-repository URL to the canonical repository above. The software is published under the product name VeriQ AncillaGuard while the repository retains its original name for continuity with the paper.

License

VeriQ AncillaGuard, the bundled Quokka-Sharp snapshot, and the vendored GPMC source are available under the MIT License. See LICENSE and NOTICE.md.

Download files

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

Source Distribution

veriq_ancillaguard-0.1.0.tar.gz (1.4 MB view details)

Uploaded Source

Built Distribution

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

veriq_ancillaguard-0.1.0-py3-none-any.whl (65.1 kB view details)

Uploaded Python 3

File details

Details for the file veriq_ancillaguard-0.1.0.tar.gz.

File metadata

  • Download URL: veriq_ancillaguard-0.1.0.tar.gz
  • Upload date:
  • Size: 1.4 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for veriq_ancillaguard-0.1.0.tar.gz
Algorithm Hash digest
SHA256 c20a4868ab5c024c19d2c606890af06d9dd75c4043a146b74a6487f27d6750d7
MD5 e95836db006fc6562d9cc613180d6d9f
BLAKE2b-256 98b1a9038bb2c3a0b2f93332422f08ed05165e0fa51bf21b2606107b338b8e11

See more details on using hashes here.

Provenance

The following attestation bundles were made for veriq_ancillaguard-0.1.0.tar.gz:

Publisher: release.yml on veriq-toolkit/Ancilla-Safety

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

File details

Details for the file veriq_ancillaguard-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for veriq_ancillaguard-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6b6744ed94d72a5a746063ca84be102b0083911cf841389b1d6403e3e67212be
MD5 320d33e574c9d1f9fd27840a65b39225
BLAKE2b-256 19531afd55a9b3d19e5d7252ac3d598aac807faf88843ccacf3cfab723c1084a

See more details on using hashes here.

Provenance

The following attestation bundles were made for veriq_ancillaguard-0.1.0-py3-none-any.whl:

Publisher: release.yml on veriq-toolkit/Ancilla-Safety

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

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 files

Supported by

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