Skip to content

✨ Derive the qubit and tensor correspondence of a call from its callee - #2194

Open
DRovara wants to merge 2 commits into
mainfrom
mlir/call-aware-iterators
Open

✨ Derive the qubit and tensor correspondence of a call from its callee#2194
DRovara wants to merge 2 commits into
mainfrom
mlir/call-aware-iterators

Conversation

@DRovara

@DRovara DRovara commented Aug 20, 2026

Copy link
Copy Markdown
Collaborator

🤖 AI text below 🤖

Description

Second of a stack replacing #1970. Builds on #2193.

WireIterator traverses func.call in both directions instead of stopping there, and atWireStart() reports whether a wire begins at the current operation — which a call result does only when the callee creates the qubit.

Which result continues which operand is derived by threading the callee's arguments through its body rather than assumed to be positional, so a callee handing its qubits back in a different order is followed correctly. The derivation is cached per callee by CallQubitMapping, with CallTensorMapping providing the same for qubit tensors. Declarations, recursive functions, and bodies that are incomplete or not a single straight-line block now fail explicitly instead of guessing a positional pairing.

Two defects this surfaced, fixed here:

  • Threading asked for a body's terminator before checking that one exists, which asserts on a function still under construction.
  • qtensor.from_elements was not treated as a wire sink even though it consumes qubits into a tensor exactly like qtensor.insert, so any wire reaching it aborted the process.

Testing

The QCO and QTensor utility suites cover threading, consuming, producing, reordering, nested calls, cache invalidation, declarations, and recursion. The affected suites pass with 125 QCO-utils tests, 10 QTensor-utils tests, 501 QCO-IR tests, and 246 optimization tests.

AI assistance

Code and this description were produced with Claude Code (Opus 5) and Codex, acting on my instructions and within the scope I authorized.

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.

@codecov

codecov Bot commented Aug 20, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.47619% with 20 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
mlir/lib/Dialect/QCO/Utils/WireIterator.cpp 92.0% 10 Missing ⚠️
mlir/lib/Dialect/QTensor/Utils/TensorIterator.cpp 87.5% 10 Missing ⚠️

📢 Thoughts on this report? Let us know!

@DRovara
DRovara force-pushed the mlir/call-aware-iterators branch 3 times, most recently from b6801d6 to cddcdbc Compare August 25, 2026 07:50
Base automatically changed from mlir/tensor-iteration-infra to main August 25, 2026 21:44
@burgholzer
burgholzer force-pushed the mlir/call-aware-iterators branch from a02e180 to a638b30 Compare August 25, 2026 21:44
@DRovara
DRovara force-pushed the mlir/call-aware-iterators branch from a638b30 to 06fdb61 Compare August 26, 2026 14:08
@DRovara
DRovara marked this pull request as ready for review August 26, 2026 14:36
@mergify mergify Bot added the conflict label Aug 26, 2026
@DRovara
DRovara force-pushed the mlir/call-aware-iterators branch from 58c8204 to c7d82fe Compare August 27, 2026 11:40
@mergify mergify Bot removed the conflict label Aug 27, 2026
@DRovara
DRovara force-pushed the mlir/call-aware-iterators branch from c7d82fe to 56a017d Compare August 27, 2026 13:16
@DRovara
DRovara requested a review from burgholzer August 28, 2026 07:17
@DRovara
DRovara force-pushed the mlir/call-aware-iterators branch 2 times, most recently from c7d82fe to 979bd40 Compare August 28, 2026 08:11
Thread qubit and tensor arguments through supported callees and fail closed when their correspondence cannot be derived.

Assisted-by: Claude Opus 5 <noreply@anthropic.com>

Assisted-by: Codex
Exercise reordered, nested, kept, declared, and recursive call mappings together with iterator traversal in both directions.

Assisted-by: Claude Opus 5 <noreply@anthropic.com>

Assisted-by: Codex
@burgholzer
burgholzer force-pushed the mlir/call-aware-iterators branch from 979bd40 to 79d8ea2 Compare August 28, 2026 12:30
@burgholzer burgholzer added feature New feature or request c++ Anything related to C++ code MLIR Anything related to MLIR labels Aug 28, 2026
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants