Skip to content

✨ Preserve reusable gates across Qiskit import and export - #2342

Open
burgholzer wants to merge 4 commits into
codex/openqasm-reusable-gatesfrom
codex/qiskit-reusable-gates
Open

✨ Preserve reusable gates across Qiskit import and export#2342
burgholzer wants to merge 4 commits into
codex/openqasm-reusable-gatesfrom
codex/qiskit-reusable-gates

Conversation

@burgholzer

@burgholzer burgholzer commented Sep 3, 2026

Copy link
Copy Markdown
Member

🤖 AI text below 🤖

Description

Preserve custom Qiskit Gate definitions as private unitary QC functions and export supported calls back to reusable Qiskit Gates. Retain nested calls, scalar parameters, external names, global phase, and supported inverse, control, and power modifiers. Generic Instruction definitions remain expanded because arbitrary Clbit calls require a classical-reference ABI.

This PR is stacked on #2338. Native MLIR call-graph traversal replaces recursive export ordering. Cached Qiskit Gate objects preserve shared definitions without recursively copying the same subgraph at every call; parameter binding still uses Qiskit's public conversion API. Import retains exact-name/parameter-hash bucketing and circuit equality for distinct specializations.

Codex implemented and tested the changes with independent Qiskit/MLIR specialist review. Regressions cover export and reimport of shared gate graphs and a 60-helper repeated-call program.

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 feature New feature or request MLIR Anything related to MLIR python Anything related to Python code labels Sep 3, 2026
Import custom Qiskit Gate definitions as private unitary QC functions and export supported QC calls back to Qiskit Gates. Preserve nested definitions, parameters, names, and supported modifiers while keeping generic Instructions flattened.

Bound definition interning and validation keep large reusable-gate graphs compact and fail closed on unsupported inputs.

Assisted-by: GPT-5.6 via Codex
Fold reusable custom Gate round trips into the existing Qiskit compiler changelog entry and record final validation in the implementation plan.

Assisted-by: GPT-5.6 via Codex
Convert enumeration indices explicitly at the checked-index boundary so platforms with a distinct size_t type select the unsigned overload consistently.

Assisted-by: GPT-5.6 via Codex
Use native MLIR call-graph traversal for callee-first export ordering without recursive DenseMap references. Reuse public Qiskit Gate definitions for parameter-free calls instead of recursively copying their nested bodies, and cover graph reuse through export and reimport.

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/qiskit-reusable-gates branch from afd7d4c to 7fdb302 Compare September 3, 2026 23:12
@codecov

codecov Bot commented Sep 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

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 feature New feature or request MLIR Anything related to MLIR python Anything related to Python code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant