Skip to main content
Once you have built and certified an ExactProgram, you can serialize it to JSON for storage, transmission, or caching. b01t includes a round-trip serialization format called exact-oracle-v1 that captures the full program structure — registers, operations, ancilla discipline, and certification level — and re-validates all structural invariants on load.

Serializing an ExactProgram

Import the serialization functions from b01t:

To JSON

exact_program_to_json() returns a deterministic, sorted-key JSON string. The output is always consistent for the same program.

To dict

If you need to embed the program data in a larger JSON object or manipulate it as a Python dictionary:

The JSON format

The serialized format uses the tag "exact-oracle-v1" in the "format" field. Here is an example of what the JSON looks like for the single-qubit oracle above:
Each operation is tagged with "op": "gate" for a single gate, "ancilla" for an ancilla block, and "par" for parallel composition. Ancilla blocks include the "middle_kind" field — either "phase" for the CPU pattern or "apply" for the CMA pattern.

Deserializing

From JSON

From dict

Deserialization validates the "format" field. If it is missing or wrong, a DSLValidationError is raised:
All structural invariants — wire declarations, ancilla discipline, gate classifications — are re-checked on load. A program that was safe when serialized is safe when restored.

Round-trip example

Managing collections with PackageRegistry

PackageRegistry lets you publish, save, and load a collection of programs. Each entry is a PackageMeta that holds a program alongside metadata like tags, version, and documentation.
Load the registry back later:
The saved file is a JSON array. Each entry that has an exact_program includes it under the "exact_oracle" key in exact-oracle-v1 format, with full structural validation on load.
Use registry.find_by_tag("oracle") to retrieve all programs with a particular tag. This is useful when you have a collection of related circuits and want to filter by purpose.