Add OpenQASM 3 circuit input via from_qasm (#14)#30
Closed
mk0dz wants to merge 1 commit into
Closed
Conversation
from_qasm parses a static subset of OpenQASM 3 into a GateCircuit: discrete gates plus parametric rx/ry/rz/p/cp/crz/u (registered through the existing EXTRA_GATES mechanism, like qft_circuit's cp_gate), both qubit[N]/qreg register syntaxes, 0->1 based index conversion, comments/barriers ignored, and ArgumentError on unsupported constructs. Angle expressions are parsed by a small recursive-descent evaluator (no eval). Includes 8 @testitem round-trip tests validated against circuit_unitary.
Member
|
We have many quality submissions and it was a tough decision, but there is still so much work to do on this package and we encourage everyone who made a submission to continue contributing and making suggestions, PRs, and issues on this repo. Thank you all! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #14
What was built
from_qasm(qasm::String) -> GateCircuitinsrc/qasm.jl, plus theinclude+export from_qasminsrc/Stretto.jl.Coverage (vs #24's 9 discrete gates):
id, x, y, z, h, s, sdg, t, tdg, sx, cx/cnot, cz, swap, ccx/toffoli, cczrx(θ), ry(θ), rz(θ), p/phase/u1(θ), cp/cphase(θ), crz(θ), u/u3(θ,φ,λ)qubit[N] q;(QASM3) andqreg q[N];(QASM2); 0→1 based index conversionOPENQASM,include),//and/* */comments,barrier,gphaseignoredArgumentErrorIdiomatic to Stretto: parametric gates register a unique symbol + matrix in
EXTRA_GATESand emitGateOp(sym, qubits)— exactly howlibrary.jl'sqft_circuithandlescp_gate. Socircuit_unitaryresolves them with no corechanges.
Security/quality note: angle expressions (
pi/2,3*pi/4,tau,-0.5) areevaluated by a small hand-written recursive-descent arithmetic parser — no
eval, so untrusted QASM can never execute code. (Replaced an initialwhitelisted-
evalversion after a security lint flagged it; the parser is bothsafer and cleaner for a library.)
Validation
8
@testitemblocks, 17 assertions, all pass, each checking correctness byround-tripping through
circuit_unitary(the issue's acceptance criterion):toffoli_circuit()rx/ry/rz/pvs their matrix definitions; two-qubitcpvsdiag(1,1,1,e^{iθ})3*pi/4≡-pi/2 + 5*pi/4;tau≡2*pi)measure, unknown gate, out-of-range index, 2 registers, no declaration)Package loads cleanly (the change is additive: one new file +
include/export),so the existing suite cannot regress from it.
Files changed (PR contents)
AI Acknowledgement: I would like to thanks claude sonnet 4.6 to make me understand the codebase and structure of Stretto