✨ Preserve reusable gates across OpenQASM import and export - #2338
Conversation
a09bfa7 to
73cf929
Compare
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
7debc7d to
763fafc
Compare
73cf929 to
e784ed2
Compare
e784ed2 to
86f99a1
Compare
6b1d409 to
01dce46
Compare
86f99a1 to
e16931c
Compare
01dce46 to
d0936e5
Compare
e16931c to
6bc8251
Compare
d0936e5 to
0d4f103
Compare
6bc8251 to
8f02f58
Compare
0d4f103 to
a05c17f
Compare
Keep custom gate definitions as private QC functions and applications as calls across import and export. Use source-order semantics and standard MLIR call-graph traversal to keep deep nonrecursive programs compact without a duplicate recursive validator. Assisted-by: Codex
8f02f58 to
87ebcfa
Compare
burgholzer
left a comment
There was a problem hiding this comment.
This one also looks clean.
I placed a couple of restrictions on the supported functions that we may want to lift in a follow up, but I still think this is fine to go in as-is for now as it genuinely expands the scope of constructs we can support.
Functions with structured control flow are currently never marked as unitary even though we could likely allow some subset of control flow while still calling an operation unitary (for loops in particular could be easily supported).
In addition, the handling around a gate called main is maybe not fully ideal. We may be able to simplify the code a little bit by making stronger assumptions about the potential names for custom gates/functions.
🤖 AI text below 🤖
Description
Preserve OpenQASM gate definitions as reusable QC functions and emit supported helpers as dependency-ordered OpenQASM gate declarations. Straight-line gates use the unitary-function contract; structured gate bodies remain private generic functions.
This PR is stacked on #2340. MLIR call-graph and SCC traversal provides callee-first export order, while the OpenQASM semantic analyzer rejects recursion before emission. Gate-expression export retains integer-to-float promotion, so expressions such as a converted loop index divided by two preserve floating-point semantics.
The exporter retains the current classical-register safeguards. Gate bodies cannot use mutable classical state; generic OpenQASM subroutines and a classical-reference call ABI are outside this change.
Codex implemented and tested the changes with independent OpenQASM/MLIR specialist review. Regressions cover a 100-function program, numeric loop expressions, strict reparsing, and QC ↔ QCO round trips.
Integrated-stack validation: release build; all 3,916 registered CTest cases with one expected skip; all 294 Qiskit translation tests; whole-file C++ lint and repository lint. Stub generation passed without tracked changes. Hosted CI is separate evidence and has not been claimed as passed.
Checklist
If PR contains AI-assisted content:
🤖 *AI text below* 🤖(titles are exempt).