Skip to content

🐛 Reject nonlinear QCO programs at checked boundaries - #2220

Merged
burgholzer merged 1 commit into
mainfrom
codex/qtensor-nonlinear-shrink-guard
Aug 27, 2026
Merged

🐛 Reject nonlinear QCO programs at checked boundaries#2220
burgholzer merged 1 commit into
mainfrom
codex/qtensor-nonlinear-shrink-guard

Conversation

@burgholzer

@burgholzer burgholzer commented Aug 23, 2026

Copy link
Copy Markdown
Member

🤖 AI text below 🤖

Description

Reject QCO programs that violate the linear quantum-value invariant at every checked ownership boundary.

Scalar qubits and rank-one qubit tensors and vectors are linear. Every quantum operation result and block argument must therefore have exactly one use. Transformation passes may rely on that invariant and do not need recovery paths for malformed IR.

This pull request:

  • adds the shared qco::verifyLinearity(Operation*) semantic verifier;
  • checks every nested quantum result and block argument and reports the actual use count;
  • routes textual and owned-module construction through checked QCOProgram factories;
  • validates direct QCO and converted QC/jeff input at the C++ pipeline and mqt-cc boundaries;
  • rejects a QCOProgram that a caller invalidated through mutable low-level MLIR access before any public transform runs; and
  • keeps QTensor transforms built on the linearity invariant and removes unreachable recovery branches.

This PR is based directly on main.

Validation:

  • complete compiler unit suite: 135/135 passed;
  • QTensor transform CTest: 1/1 passed;
  • mqt-cc CTests: 2/2 passed;
  • C++ lint: passed; and
  • full repository lint: passed.

Hosted CI is pending for the rebased revision.

AI assistance: OpenAI Codex assisted with implementation, review, testing, and this description.

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 fix Fix for something that isn't working MLIR Anything related to MLIR labels Aug 23, 2026
@burgholzer burgholzer self-assigned this Aug 23, 2026
@burgholzer
burgholzer force-pushed the codex/qtensor-nonlinear-shrink-guard branch from b783143 to 7b8c432 Compare August 23, 2026 22:02
@codecov

codecov Bot commented Aug 23, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.62366% with 5 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
mlir/lib/Compiler/Programs.cpp 92.6% 5 Missing ⚠️

📢 Thoughts on this report? Let us know!

@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 one looks good already.

@burgholzer
burgholzer force-pushed the codex/selected-payload-environment branch from ae5b72f to b0dd192 Compare August 24, 2026 13:31
@mergify mergify Bot added the conflict label Aug 24, 2026
@burgholzer
burgholzer force-pushed the codex/selected-payload-environment branch from b0dd192 to bb0240b Compare August 24, 2026 14:15
@burgholzer
burgholzer force-pushed the codex/qtensor-nonlinear-shrink-guard branch from 7b8c432 to 6c8caf5 Compare August 24, 2026 15:03
@burgholzer burgholzer changed the title 🐛 Skip qtensor shrinking for nonlinear values 🐛 Reject nonlinear QCO MLIR imports Aug 24, 2026
@burgholzer
burgholzer changed the base branch from codex/selected-payload-environment to codex/qdmi-target-environment-adapter August 24, 2026 15:03
@burgholzer burgholzer added the c++ Anything related to C++ code label Aug 24, 2026
@mergify mergify Bot removed the conflict label Aug 24, 2026
@burgholzer
burgholzer force-pushed the codex/qdmi-target-environment-adapter branch from 5aefae1 to f6ccb12 Compare August 24, 2026 15:35
@burgholzer
burgholzer force-pushed the codex/qtensor-nonlinear-shrink-guard branch from 6c8caf5 to 3e20de2 Compare August 24, 2026 15:40
@burgholzer burgholzer changed the title 🐛 Reject nonlinear QCO MLIR imports 🐛 Reject nonlinear QCO programs at checked boundaries Aug 24, 2026
@burgholzer
burgholzer force-pushed the codex/qdmi-target-environment-adapter branch from f6ccb12 to c463a53 Compare August 24, 2026 16:02
@burgholzer
burgholzer force-pushed the codex/qtensor-nonlinear-shrink-guard branch from 3e20de2 to 5c15cce Compare August 24, 2026 16:02
@burgholzer
burgholzer force-pushed the codex/qdmi-target-environment-adapter branch from c463a53 to 4289979 Compare August 24, 2026 16:22
@burgholzer
burgholzer force-pushed the codex/qtensor-nonlinear-shrink-guard branch 2 times, most recently from 0883404 to c139d2a Compare August 24, 2026 17:28
@burgholzer
burgholzer force-pushed the codex/qdmi-target-environment-adapter branch from 6d36be3 to 8099ad5 Compare August 24, 2026 18:03
@burgholzer
burgholzer force-pushed the codex/qtensor-nonlinear-shrink-guard branch 2 times, most recently from 85e1bba to d2cd2bf Compare August 24, 2026 18:59
@burgholzer
burgholzer force-pushed the codex/qdmi-target-environment-adapter branch from 756d7d6 to fcf7027 Compare August 24, 2026 19:03
@burgholzer
burgholzer force-pushed the codex/qtensor-nonlinear-shrink-guard branch from 2f5f79f to fb549ab Compare August 24, 2026 19:03
@burgholzer
burgholzer force-pushed the codex/qdmi-target-environment-adapter branch from fcf7027 to 0c598df Compare August 24, 2026 20:10
@burgholzer
burgholzer force-pushed the codex/qtensor-nonlinear-shrink-guard branch from fb549ab to 07896c0 Compare August 24, 2026 20:10
@burgholzer
burgholzer force-pushed the codex/qdmi-target-environment-adapter branch from 0c598df to 6d85e61 Compare August 24, 2026 23:47
@burgholzer
burgholzer force-pushed the codex/qtensor-nonlinear-shrink-guard branch from 07896c0 to 57286ea Compare August 24, 2026 23:47

@simon1hofmann simon1hofmann left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Also went through this and looks good to me!

@denialhaag denialhaag left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I also had a brief look at this. Apart from my three (non-blocking) nitpicks below, this LGTM! 😎

Comment thread mlir/lib/Dialect/QCO/IR/QCOUtils.cpp Outdated
Comment thread mlir/lib/Dialect/QCO/IR/QCOUtils.cpp Outdated
Comment thread mlir/lib/Dialect/QCO/IR/QCOUtils.cpp Outdated
@denialhaag

Copy link
Copy Markdown
Member

If I'm not missing anything right now, this could even be pulled out of the stack and merged immediately. 🤔

@burgholzer

Copy link
Copy Markdown
Member Author

If I'm not missing anything right now, this could even be pulled out of the stack and merged immediately. 🤔

Yeah. Most likely! And it feels independent enough, that we could just do it. Let me try to do that in the next iteration. This feels stable enough.

Verify that every scalar qubit, rank-one qubit tensor, and qubit vector result or block argument has exactly one use at checked C++ and CLI ownership boundaries. Keep transformation passes built on the linear IR invariant.

Assisted-by: GPT-5.6 Sol via Codex
@burgholzer
burgholzer force-pushed the codex/qtensor-nonlinear-shrink-guard branch from 57286ea to 56c3e10 Compare August 27, 2026 14:03
@burgholzer
burgholzer changed the base branch from codex/qdmi-target-environment-adapter to main August 27, 2026 14:03
@coderabbitai

coderabbitai Bot commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Important

Approval pending

CodeRabbit has no unresolved comments, but it has not reviewed the latest commit.

Use the checkbox below to review the latest commit. CodeRabbit will approve the changes if it finds no blocking issues.

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@burgholzer

Copy link
Copy Markdown
Member Author

@denialhaag @simon1hofmann pulled this one out of the PR chain and rebased it on current main. Just waiting for CI to spin up and finish!

@burgholzer
burgholzer marked this pull request as draft August 27, 2026 15:20
@burgholzer
burgholzer marked this pull request as ready for review August 27, 2026 15:20
@burgholzer
burgholzer enabled auto-merge (squash) August 27, 2026 15:47
@burgholzer
burgholzer merged commit baecdc5 into main Aug 27, 2026
25 checks passed
@burgholzer
burgholzer deleted the codex/qtensor-nonlinear-shrink-guard branch August 27, 2026 15:54
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 fix Fix for something that isn't working MLIR Anything related to MLIR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants