Skip to content

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

Merged
burgholzer merged 1 commit into
mainfrom
codex/qiskit-reusable-gates
Sep 6, 2026
Merged

✨ Preserve reusable gates across Qiskit import and export#2342
burgholzer merged 1 commit into
mainfrom
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. MLIR call-graph and SCC traversal provides callee-first export order. Definition interning uses source-name/parameter-hash buckets plus Qiskit circuit equality so copied but equivalent Gate objects share one function without a global quadratic scan. The 64-level import and export bounds fail closed on arbitrary mutable Python definition graphs and keep emitted circuits re-importable.

Codex implemented and tested the changes with independent Qiskit/MLIR specialist review. Regressions cover nested and parameterized gates, modifiers, unsupported boundaries, export/reimport, a 60-helper shared graph, and depth limits.

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

  • 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
@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!

@burgholzer
burgholzer force-pushed the codex/qiskit-reusable-gates branch from 7fdb302 to 6328d48 Compare September 4, 2026 21:59
@burgholzer
burgholzer force-pushed the codex/openqasm-reusable-gates branch from 86f99a1 to e16931c Compare September 4, 2026 21:59
@burgholzer burgholzer added the Core Anything related to the Core library and IR label Sep 4, 2026
@burgholzer
burgholzer force-pushed the codex/qiskit-reusable-gates branch from 6328d48 to 26e83a0 Compare September 5, 2026 13:09
@burgholzer
burgholzer force-pushed the codex/openqasm-reusable-gates branch from e16931c to 6bc8251 Compare September 5, 2026 13:09
@burgholzer
burgholzer force-pushed the codex/qiskit-reusable-gates branch from 26e83a0 to d2688e6 Compare September 5, 2026 15:00
@burgholzer
burgholzer force-pushed the codex/openqasm-reusable-gates branch 2 times, most recently from 8f02f58 to 87ebcfa Compare September 6, 2026 11:17
@mergify mergify Bot added the conflict label Sep 6, 2026
Base automatically changed from codex/openqasm-reusable-gates to main September 6, 2026 11:56
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
@burgholzer
burgholzer force-pushed the codex/qiskit-reusable-gates branch from d2688e6 to 1e71124 Compare September 6, 2026 12:06
@mergify mergify Bot removed the conflict label Sep 6, 2026
@burgholzer burgholzer added this to the v4.0.0 - IEEE Quantum Week milestone Sep 6, 2026
@burgholzer burgholzer self-assigned this Sep 6, 2026

@burgholzer burgholzer left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks reasonable enough for now. I am pretty sure a cross-check between OpenQASM and Qiskit support will reveal a couple of areas for improvement and simplifications, but I'd rather get this in now than worry about it for too long.

@burgholzer
burgholzer merged commit d7f39ce into main Sep 6, 2026
26 checks passed
@burgholzer
burgholzer deleted the codex/qiskit-reusable-gates branch September 6, 2026 20:02
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 python Anything related to Python code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant