qec_code, qec_decode and qec_threshold call the engine's error correction in-process, each answer sealed in a job's form, and run() takes mitigate=. The tests decode every error of weight up to two on the distance-5 colour code to a trivial residual, check a certificate and a forged one, and hold each answer to the command line's. Co-Authored-By: Claude Opus 5.5 <[email protected]>
129 lines
3.3 KiB
Python
129 lines
3.3 KiB
Python
"""WAI Quantum in Python.
|
|
|
|
The shared job engine runs in this process: the same request gives the same
|
|
plan, the same result and the same receipt as the command line, the job
|
|
service, the MCP servers, the Studio and the desktop app.
|
|
|
|
>>> import wai_quantum as wq
|
|
>>> bell = "OPENQASM 3.0; qubit[2] q; bit[2] c; h q[0]; cx q[0], q[1]; c = measure q;"
|
|
>>> job = wq.run(bell, shots=1000, key=wq.Key.demo())
|
|
>>> job.method, job.accuracy, sorted(job.counts)
|
|
('stabilizer', 'exact', ['00', '11'])
|
|
>>> bool(wq.verify(job))
|
|
True
|
|
|
|
- ``run``, ``plan``, ``lint``, ``draw``, ``layout``, ``critique``,
|
|
``improve``, ``shortcuts``, ``equivalent``, ``verify``, ``verdict``,
|
|
``repair``, ``seal``, ``canonical``, ``digest``, ``methods``,
|
|
``accuracy_classes``, ``bloch``, ``history``, ``estimate``,
|
|
``verify_estimate``, ``qec_code``, ``qec_decode`` and ``qec_threshold``:
|
|
the engine.
|
|
- ``run(program, noise=..., mitigate="zne")`` mitigates a noisy run's
|
|
values, each raw and mitigated with its error bar and the method's
|
|
assumptions.
|
|
- ``run(program, intent=...)`` checks what the program must do with the run;
|
|
``job.verdict`` says how far the engine checked (refused, parsed,
|
|
executed, evidence, proof), sealed by the receipt.
|
|
- ``Key``: the key a receipt is signed with.
|
|
- ``Service``: the job service, over HTTPS, its receipts checked here.
|
|
- ``Circuit``, ``Result``, ``Receipt``, ``Bloch`` (``wai_quantum.widgets``):
|
|
notebook widgets, with static fallbacks.
|
|
|
|
Answers are plain dicts and lists; a job is a ``Job`` (a dict) with helpers
|
|
(``counts``, ``probabilities()``, ``expectations``, ``amplitudes``,
|
|
``method``, ``accuracy``, ``receipt``). A refusal raises ``EngineError``
|
|
with the engine's message.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import Any
|
|
|
|
from ._engine import UNMETERED, __version__
|
|
from ._api import (
|
|
DEFAULT_MEMORY_GB,
|
|
accuracy_classes,
|
|
bloch,
|
|
canonical,
|
|
critique,
|
|
digest,
|
|
draw,
|
|
equivalent,
|
|
estimate,
|
|
history,
|
|
improve,
|
|
job_request,
|
|
layout,
|
|
lint,
|
|
methods,
|
|
plan,
|
|
qec_code,
|
|
qec_decode,
|
|
qec_threshold,
|
|
repair,
|
|
run,
|
|
seal,
|
|
shortcuts,
|
|
verdict,
|
|
verify,
|
|
verify_estimate,
|
|
)
|
|
from ._job import Job, Verification
|
|
from .errors import EngineError, ServiceError
|
|
from .keys import DEMO_SEED, Key
|
|
from .service import DEFAULT_SERVICE, USER_AGENT, Service
|
|
|
|
__all__ = [
|
|
"__version__",
|
|
"UNMETERED",
|
|
"DEFAULT_MEMORY_GB",
|
|
"DEFAULT_SERVICE",
|
|
"USER_AGENT",
|
|
"DEMO_SEED",
|
|
"run",
|
|
"plan",
|
|
"lint",
|
|
"draw",
|
|
"layout",
|
|
"critique",
|
|
"improve",
|
|
"shortcuts",
|
|
"equivalent",
|
|
"verify",
|
|
"verdict",
|
|
"repair",
|
|
"seal",
|
|
"canonical",
|
|
"digest",
|
|
"methods",
|
|
"accuracy_classes",
|
|
"bloch",
|
|
"history",
|
|
"estimate",
|
|
"verify_estimate",
|
|
"qec_code",
|
|
"qec_decode",
|
|
"qec_threshold",
|
|
"job_request",
|
|
"Job",
|
|
"Verification",
|
|
"Key",
|
|
"Service",
|
|
"EngineError",
|
|
"ServiceError",
|
|
"Circuit",
|
|
"Result",
|
|
"Receipt",
|
|
"Bloch",
|
|
]
|
|
|
|
_WIDGETS = ("Circuit", "Result", "Receipt", "Bloch")
|
|
|
|
|
|
def __getattr__(name: str) -> Any:
|
|
# The widgets load their library only when first asked for.
|
|
if name in _WIDGETS:
|
|
from . import widgets
|
|
|
|
return getattr(widgets, name)
|
|
raise AttributeError(f"module 'wai_quantum' has no attribute {name!r}")
|