Skip to content

✨ Preserve reusable gates across OpenQASM import and export - #2338

Open
burgholzer wants to merge 4 commits into
codex/qir-reusable-functionsfrom
codex/openqasm-reusable-gates
Open

✨ Preserve reusable gates across OpenQASM import and export#2338
burgholzer wants to merge 4 commits into
codex/qir-reusable-functionsfrom
codex/openqasm-reusable-gates

Conversation

@burgholzer

@burgholzer burgholzer commented Sep 3, 2026

Copy link
Copy Markdown
Member

🤖 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. Native MLIR call-graph traversal replaces recursive ordering and preserves the 64-level frontend limit. Gate-expression export keeps integer-to-float promotion, so expressions such as a converted loop index divided by two retain 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 50-helper dependency graph, numeric loop expressions, strict reparsing, and QC ↔ QCO round trips.

Integrated-stack validation: release build; 3,857 registered CTest cases with one expected skip; 259 Qiskit translation tests; whole-file C++ lint and repository lint. Stub generation passed without changes. Hosted CI remains separate and has not been claimed as passed.

Checklist

  • The pull request only contains commits that are focused and relevant to this change.
  • I have added appropriate tests that cover the new/changed functionality.
  • I have updated the documentation to reflect these changes.
  • I have added entries to the changelog for any noteworthy additions, changes, fixes, or removals.
  • I have added migration instructions to the upgrade guide (if needed).
  • The changes follow the project's style guidelines and introduce no new warnings.
  • The changes are fully tested and pass the CI checks.
  • I have reviewed my own code changes.

If PR contains AI-assisted content:

  • Any agent that created, edited, or submitted GitHub content was explicitly authorized for that scope, as required by our AI Usage Guidelines.
  • Every agent-authored or agent-edited public text body begins with the visible disclosure 🤖 *AI text below* 🤖 (titles are exempt).
  • I have disclosed AI assistance in the PR description.
  • I confirm that I have personally reviewed and understood all AI-generated content, and accept full responsibility for it.

@burgholzer burgholzer added c++ Anything related to C++ code Core Anything related to the Core library and IR feature New feature or request MLIR Anything related to MLIR OpenQASM Anything related to OpenQASM labels Sep 3, 2026
@burgholzer
burgholzer force-pushed the codex/openqasm-reusable-gates branch from a09bfa7 to 73cf929 Compare September 3, 2026 03:52
@burgholzer
burgholzer changed the base branch from codex/qco-function-model to codex/qir-reusable-functions September 3, 2026 03:52
@codecov

codecov Bot commented Sep 3, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.70507% with 18 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
.../Dialect/QC/Translation/TranslateQCToOpenQASM3.cpp 92.1% 14 Missing ⚠️
...lib/Dialect/QC/Translation/OpenQASMToQCEmitter.cpp 89.4% 4 Missing ⚠️

📢 Thoughts on this report? Let us know!

Represent custom gate definitions as reusable QC functions and emit supported function calls as dependency-ordered OpenQASM gate declarations.

Assisted-by: GPT-5.6 via Codex
Fold the follow-up into the existing OpenQASM launch changelog entry.

Assisted-by: GPT-5.6 via Codex
Bound recursive dependency traversal before descent, cache symbol resolution, and reject aliased rendered gate operands before emitting invalid OpenQASM.

Assisted-by: GPT-5.6 via Codex
Use MLIR call-graph traversal to order gate definitions without retaining
invalidated map references. Preserve floating promotion in gate expressions
so division of converted loop indices keeps its numeric meaning.

Assisted-by: Codex
@burgholzer
burgholzer force-pushed the codex/openqasm-reusable-gates branch from e784ed2 to 86f99a1 Compare September 3, 2026 23:12
@burgholzer
burgholzer force-pushed the codex/qir-reusable-functions branch from 763fafc to 6b1d409 Compare September 3, 2026 23:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++ Anything related to C++ code Core Anything related to the Core library and IR feature New feature or request MLIR Anything related to MLIR OpenQASM Anything related to OpenQASM

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant