Skip to content

✨ Support classical results in QCO conditionals#1938

Merged
burgholzer merged 10 commits into
mainfrom
agent/qco-if-classical-results
Jul 25, 2026
Merged

✨ Support classical results in QCO conditionals#1938
burgholzer merged 10 commits into
mainfrom
agent/qco-if-classical-results

Conversation

@burgholzer

Copy link
Copy Markdown
Member

🤖 AI text below 🤖

Summary

  • Allow qco.if and qco.index_switch to return ordinary classical SSA values
    before their existing linear quantum results.
  • Preserve result-bearing scf.if and scf.index_switch operations through
    QC-to-QCO and QCO-to-QC conversion without introducing scratch memory.
  • Update verification, parsing and printing, RegionBranch interfaces,
    tied-value helpers, builders, mapping, tensor traversal, module equivalence,
    and affected optimizations for the segmented result model.
  • Keep unsupported Jeff lowering explicit without constraining the standard
    QC → QCO → QC → QIR pipeline.

Motivation

This capability was identified while working on the OpenQASM integration in
#1910 and while reducing the structured-control-flow fixes that became #1935.
QCO conditionals previously represented only linear quantum results. Preserving
classical SCF results therefore required either rejecting otherwise valid
programs or lowering classical state through temporary memory.

The new representation keeps classical values in ordinary SSA form while
retaining QCO's explicit single-use quantum flow:

  1. classical result prefix;
  2. tied linear quantum result suffix.

Conditional region arguments remain linear-only. Classical inputs continue to
use normal SSA capture, while qco.yield returns the complete
classical-plus-linear result signature.

Implementation notes

  • Both conditional operations use AttrSizedResultSegments and expose explicit
    classical and linear result accessors.
  • Custom parsers infer the linear suffix from the args(...) assignments and
    retain quantum-only textual compatibility.
  • Parent-aware qco.yield verification preserves the stricter modifier
    contracts.
  • QC↔QCO conversions retain classical def-use chains directly and replace only
    linear results with QC references on the QC side.
  • Mapping handles every index-switch case and the default region, preserving
    classical yield operands while realigning only quantum values.
  • Module equivalence compares classical yield prefixes positionally while
    keeping the linear suffix permutation-aware.

Validation

All affected targets build successfully. The focused suites pass 933 tests in
total:

  • 450 QCO IR tests
  • 134 QC-to-QCO tests
  • 132 QCO-to-QC tests
  • 82 QCO utility tests
  • 3 QTensor utility tests
  • 15 mapping tests
  • 117 Jeff round-trip tests

Repository lint, changed-source clang-tidy, and git diff --check pass. Two
independent read-only reviews were performed; the final review found no
remaining actionable issues.

Assisted-by: GPT-5.6 via Codex
Assisted-by: GPT-5.6 via Codex
Assisted-by: GPT-5.6 via Codex
Assisted-by: GPT-5.6 via Codex
@codecov

codecov Bot commented Jul 24, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.80791% with 29 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
mlir/lib/Dialect/QCO/IR/QCOOps.cpp 77.5% 20 Missing ⚠️
mlir/lib/Dialect/QCO/IR/SCF/IfOp.cpp 95.3% 4 Missing ⚠️
mlir/lib/Dialect/QCO/IR/SCF/IndexSwitchOp.cpp 91.8% 3 Missing ⚠️
mlir/lib/Conversion/QCOToQC/QCOToQC.cpp 93.7% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

@burgholzer burgholzer added enhancement Improvement of existing feature c++ Anything related to C++ code MLIR Anything related to MLIR labels Jul 24, 2026
@burgholzer burgholzer added this to the MLIR Support milestone Jul 24, 2026
@burgholzer burgholzer self-assigned this Jul 24, 2026
Assisted-by: GPT-5.6 via Codex
Assisted-by: GPT-5.6 via Codex
Assisted-by: GPT-5.6 via Codex
Assisted-by: GPT-5.6 via Codex
Integrate the Python CI and Jeff return-placement fixes from #1939.

Assisted-by: GPT-5.6 via Codex
Assisted-by: GPT-5.6 via Codex
@burgholzer

Copy link
Copy Markdown
Member Author

This feels very reasonable to me and it passes all tests. I am proceeding to merge.

@MatthiasReumann for awareness as this also touches the IndexSwitchOp and its mapping. Hope this does not tae away too much of the work you had already done to support it.

@burgholzer
burgholzer marked this pull request as ready for review July 25, 2026 07:40
@burgholzer
burgholzer merged commit 7c50a17 into main Jul 25, 2026
33 checks passed
@burgholzer
burgholzer deleted the agent/qco-if-classical-results branch July 25, 2026 07:41
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 enhancement Improvement of existing feature MLIR Anything related to MLIR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant