wai-quantum: OpenQASM 3 generators, one program for a family of circuits #466
Loading…
Reference in a new issue
No description provided.
Delete branch "wai/quantum-qasm-generators"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
The OpenQASM reader refused loops, so a family of circuits (a GHZ state on n qubits, the QFT, an adder) had to be written out once per size. This makes one program describe the whole family. It is the first piece of the specification-and-evaluator workbench: its proposers evolve such programs, and its evaluator checks them across n.
Reader (
wai-quantum, featurequantum_qasm):qasm::parse_with/parse_lines_withread a program at given integer inputs, andqasm::inputslists the inputs it declares.input int|uint n;andconst int|uint k = …;;for i in [a:b] { … }, plus[a:step:b](both ends included, as OpenQASM 3 reads a range) and{a, b, c}, nested;+ - * / %with C's truncating division,**, comparisons,&& || !;ifon integers alone, decided on reading. One that reads bits stays classical control.qasm::instantiatewrites the circuit at given inputs out as plain OpenQASM. It reads back as the same program, gate for gate (tested for the QFT at n = 1, 3 and 6).i, which is also the identity gate's name: integers are substituted only where they don't start a statement.input,constorforreads exactly as before: the unrolling pass returns its tokens untouched.CLI:
--input NAME=VALUEon every command, sorun,plan,critique,equivalentandshortcutseach read one circuit of the family.wai-quantum instance gen.qasm --input n=5prints that circuit.READMEs (engine, CLI, service) and the changelog are updated. The service reads
forandconstalready, and is told to send an instance for a generator with inputs.Checked on the build host:
cargo test --features quantum_qasm --lib qasm::: 19 pass. New:ifon integers is decided while one on bits stays control, inside a loop;cargo test --features full --lib --tests: 736 pass.cargo testpasses, includinga_generator_is_read_at_its_inputs_and_a_plain_program_as_it_is, which also runs a 12-qubit GHZ instance end to end.cargo clippy --all-targets -- -D warningsis clean.🤖 Generated with Claude Code
The reader refused loops, so a family of circuits (a GHZ state on n qubits, the QFT, an adder) had to be written out once per size. It now reads generators, the first piece of the specification-and-evaluator workbench, whose proposers evolve exactly such programs and whose evaluator checks them across n. - qasm::parse_with and qasm::parse_lines_with read a program at given integer inputs; qasm::inputs lists the inputs it declares. `input int`, `input uint`, `const int|uint`, and `for` over [a:b], [a:step:b] (both ends included) and {a, b, c}, nested, are unrolled on reading. Indices and sizes take integer arithmetic with C's truncating division, `%`, `**`, comparisons and `&& || !`. An `if` on integers alone is decided on reading; one on bits stays classical control. Unrolled gates keep the lines of their loop's body. - qasm::instantiate writes the circuit at given inputs out as plain OpenQASM, which reads back as the same program, gate for gate. - Bounded: at most 20 million tokens, checked integer arithmetic, and a name an integer would shadow (a register, a gate's parameter or qubit, a word of the language) is refused with its line. A loop variable may still share a gate's name, such as the identity `i`, since an integer is only substituted where it is not starting a statement. - The lexer reads `% < > <= >= && ||`. - The CLI takes `--input NAME=VALUE` on every command, and `instance` prints a generator written out. A program with no input, const or for reads exactly as before: the unrolling pass returns its tokens untouched. Co-Authored-By: Claude Opus 5.5 <[email protected]>