Skip to content

[Transformation] Preserve phase and wire SSA through apply specialization - #5071

Draft
cabreraam wants to merge 58 commits into
NVIDIA:mainfrom
cabreraam:phase-tracking-pt7
Draft

[Transformation] Preserve phase and wire SSA through apply specialization#5071
cabreraam wants to merge 58 commits into
NVIDIA:mainfrom
cabreraam:phase-tracking-pt7

Conversation

@cabreraam

Copy link
Copy Markdown
Collaborator

Warning

This PR depends on #4976, #5022, #5044, #5058, #5062, and #5066, so it shouldn't be reviewed until each of those PRs has been upstreamed.

Summary

Implementsstructural hardening for phase tracking through quake.apply specialization.

This preserves phase behavior when apply specialization creates controlled, adjoint, and controlled-adjoint variants, including wire-valued kernels.

Changes

  • Preserve operation-result SSA uses when cloning specialized quantum operations before erasing the original operation.

    • This is a no-op for reference-form gates.
    • It is required for !quake.wire, where each gate produces the successor
      wire value consumed by the next gate.
  • Add wire-aware adjoint specialization.

    • Rebuilds straight-line wire dataflow backward from function results to function arguments.
    • Reverses gate order while preserving wire use-def chains.
    • Inverts quake.phase by negating its angle.
    • Inverts non-Hermitian physical gates by toggling is_adj, preserving parameter tuples for gates such as u3 and phased_rx.
    • Preserves controls-then-targets wire-result ordering.
  • Harden controlled specialization around surviving ordinary quantum calls.

    • Diagnose direct and transitive quantum func.call chains that would otherwise bypass the newly added control predicate.
    • This makes the required pipeline ordering explicit: inline quantum calls before apply specialization when control specialization is needed.
  • Cover nested applies, adjoints, multiple controls, existing negative control predicates, structured reference-form control flow, recursion, and wire result threading.

Test coverage

  • apply-phase-wire.qke

    • Forward, controlled, adjoint, and controlled-adjoint wire variants.
    • Wire SSA threading through phase and control/target results.
    • Parameterized physical-gate adjoints and wire-control ordering.
  • apply-phase-structural.qke

    • Nested apply specialization.
    • Multiple outer controls plus an existing negative inner control.
    • Adjoint reversal through cc.if and monotonic loops.
    • Recursive controlled specialization.
    • Aggressive-inlining coverage.
  • apply-phase-call-error.qke

    • Expected diagnostics for unsupported direct and transitive quantum func.call paths.
  • apply_ctrl_veq_type.qke

    • Regression coverage for constant propagation, !quake.veq type specialization, inlining, and controlled specialization.

…e`, an op designed to account for global/controlled phase

Signed-off-by: Anthony Cabrera <antcabrera@nvidia.com>
Signed-off-by: Anthony Cabrera <antcabrera@nvidia.com>
…entries in the negated control boolean array

Signed-off-by: Anthony Cabrera <antcabrera@nvidia.com>
…common file `PhaseUtilities`; rename `hasUnambiguousLinearUse` --> `hasUnambiguousWireUse`

Signed-off-by: Anthony Cabrera <antcabrera@nvidia.com>
Signed-off-by: Anthony Cabrera <antcabrera@nvidia.com>
…rom `quake.apply`

Signed-off-by: Anthony Cabrera <antcabrera@nvidia.com>
… expanding

Signed-off-by: Anthony Cabrera <antcabrera@nvidia.com>
Signed-off-by: Anthony Cabrera <antcabrera@nvidia.com>
Signed-off-by: Anthony Cabrera <antcabrera@nvidia.com>
Signed-off-by: Anthony Cabrera <antcabrera@nvidia.com>
Signed-off-by: Anthony Cabrera <antcabrera@nvidia.com>
Signed-off-by: Anthony Cabrera <antcabrera@nvidia.com>
Signed-off-by: Anthony Cabrera <antcabrera@nvidia.com>
Signed-off-by: Anthony Cabrera <antcabrera@nvidia.com>
…e` pass

Signed-off-by: Anthony Cabrera <antcabrera@nvidia.com>
Lower PhaseOps before OpenQASM, execution-manager, and WireSet
conversion. Reject residual PhaseOps in IQM, add defensive translator
guards, and cover each route with focused regressions.

Signed-off-by: Anthony Cabrera <antcabrera@nvidia.com>
…e both static and dynamic control `veq`s of `PhaseOp`s in `LowerPhase`

Signed-off-by: Anthony Cabrera <antcabrera@nvidia.com>
Signed-off-by: Anthony Cabrera <antcabrera@nvidia.com>
Signed-off-by: Anthony Cabrera <antcabrera@nvidia.com>
Signed-off-by: Anthony Cabrera <antcabrera@nvidia.com>
…cific header

Signed-off-by: Anthony Cabrera <antcabrera@nvidia.com>
…rgets

Signed-off-by: Anthony Cabrera <antcabrera@nvidia.com>
…lar target and use the `verify-no-phase` pass to make sure there are no residual `Phase` ops after lowering phase ops

Signed-off-by: Anthony Cabrera <antcabrera@nvidia.com>
…gets specialized afterward, and then `phase` lowered to an uncontrolled `r1`

Signed-off-by: Anthony Cabrera <antcabrera@nvidia.com>
Signed-off-by: Anthony Cabrera <antcabrera@nvidia.com>
Signed-off-by: Anthony Cabrera <antcabrera@nvidia.com>
Signed-off-by: Anthony Cabrera <antcabrera@nvidia.com>
Signed-off-by: Anthony Cabrera <antcabrera@nvidia.com>
Signed-off-by: Anthony Cabrera <antcabrera@nvidia.com>
Signed-off-by: Anthony Cabrera <antcabrera@nvidia.com>
Signed-off-by: Anthony Cabrera <antcabrera@nvidia.com>
Signed-off-by: Anthony Cabrera <antcabrera@nvidia.com>
…g `func::FuncDialect`, and `link against MLIRTransforms library

Signed-off-by: Anthony Cabrera <antcabrera@nvidia.com>
Signed-off-by: Anthony Cabrera <antcabrera@nvidia.com>
Signed-off-by: Anthony Cabrera <antcabrera@nvidia.com>
Signed-off-by: Anthony Cabrera <antcabrera@nvidia.com>
Signed-off-by: Anthony Cabrera <antcabrera@nvidia.com>
Signed-off-by: Anthony Cabrera <antcabrera@nvidia.com>
Signed-off-by: Anthony Cabrera <antcabrera@nvidia.com>
Signed-off-by: Anthony Cabrera <antcabrera@nvidia.com>
Signed-off-by: Anthony Cabrera <antcabrera@nvidia.com>

DCO Remediation Commit for Anthony Cabrera <antcabrera@nvidia.com>

I, Anthony Cabrera <antcabrera@nvidia.com>, hereby add my Signed-off-by to this commit: 4999766
I, Anthony Cabrera <antcabrera@nvidia.com>, hereby add my Signed-off-by to this commit: 934bfd3
I, Anthony Cabrera <antcabrera@nvidia.com>, hereby add my Signed-off-by to this commit: 37badcb
I, Anthony Cabrera <antcabrera@nvidia.com>, hereby add my Signed-off-by to this commit: 9b98afe
Signed-off-by: Anthony Cabrera <antcabrera@nvidia.com>
Signed-off-by: Anthony Cabrera <antcabrera@nvidia.com>
Signed-off-by: Anthony Cabrera <antcabrera@nvidia.com>
Signed-off-by: Anthony Cabrera <antcabrera@nvidia.com>
Signed-off-by: Anthony Cabrera <antcabrera@nvidia.com>
Signed-off-by: Anthony Cabrera <antcabrera@nvidia.com>
Signed-off-by: Anthony Cabrera <antcabrera@nvidia.com>
Signed-off-by: Anthony Cabrera <antcabrera@nvidia.com>
Signed-off-by: Anthony Cabrera <antcabrera@nvidia.com>
Signed-off-by: Anthony Cabrera <antcabrera@nvidia.com>
Signed-off-by: Anthony Cabrera <antcabrera@nvidia.com>
Signed-off-by: Anthony Cabrera <antcabrera@nvidia.com>
Signed-off-by: Anthony Cabrera <antcabrera@nvidia.com>
Signed-off-by: Anthony Cabrera <antcabrera@nvidia.com>
Signed-off-by: Anthony Cabrera <antcabrera@nvidia.com>
Signed-off-by: Anthony Cabrera <antcabrera@nvidia.com>
Signed-off-by: Anthony Cabrera <antcabrera@nvidia.com>
@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown

CI Summary (push) — ❌ failed

Run #31134987980 · ✅ 5 · ⏩ 7 · ❌ 1 · ⛔ 0

❌ Failed or cancelled
Job Result Link
build_and_test ❌ failure view
Top-level jobs (13)
Job Result
binaries ⏩ skipped
build_and_test ❌ failure
config_devdeps ✅ success
config_source_build ⏩ skipped
config_wheeldeps ✅ success
devdeps ✅ success
docker_image ⏩ skipped
gen_code_coverage ⏩ skipped
metadata ✅ success
python_metapackages ⏩ skipped
python_wheels ⏩ skipped
source_build ⏩ skipped
wheeldeps ✅ success
⏩ Skipped jobs (7) — intentionally skipped on PR builds; run on merge_group / workflow_dispatch
Job
binaries
config_source_build
docker_image
gen_code_coverage
python_metapackages
python_wheels
source_build
All sub-jobs (42) — every matrix leg, with links
Job Status Link
Build and test (amd64, gcc12, openmpi) / Dev environment (Debug) ✅ success view
Build and test (amd64, gcc12, openmpi) / Dev environment (Python) ❌ failure view
Build and test (amd64, llvm, openmpi) / Dev environment (Debug) ✅ success view
Build and test (amd64, llvm, openmpi) / Dev environment (Python) ❌ failure view
Build and test (arm64, llvm, openmpi) / Dev environment (Debug) ✅ success view
Build and test (arm64, llvm, openmpi) / Dev environment (Python) ❌ failure view
CI Summary ❔ in_progress view
Configure build (devdeps) ✅ success view
Configure build (source_build) ⏩ skipped view
Configure build (wheeldeps) ✅ success view
Create CUDA Quantum installer ⏩ skipped view
Create Docker images ⏩ skipped view
Create Python metapackages ⏩ skipped view
Create Python wheels ⏩ skipped view
Gen code coverage ⏩ skipped view
Load dependencies (amd64, gcc12) / Caching ✅ success view
Load dependencies (amd64, gcc12) / Finalize ✅ success view
Load dependencies (amd64, gcc12) / Metadata ✅ success view
Load dependencies (amd64, llvm) / Caching ✅ success view
Load dependencies (amd64, llvm) / Finalize ✅ success view
Load dependencies (amd64, llvm) / Metadata ✅ success view
Load dependencies (arm64, gcc12) / Caching ✅ success view
Load dependencies (arm64, gcc12) / Finalize ✅ success view
Load dependencies (arm64, gcc12) / Metadata ✅ success view
Load dependencies (arm64, llvm) / Caching ✅ success view
Load dependencies (arm64, llvm) / Finalize ✅ success view
Load dependencies (arm64, llvm) / Metadata ✅ success view
Load source build cache ⏩ skipped view
Load wheel dependencies (amd64, 12.6) / Caching ✅ success view
Load wheel dependencies (amd64, 12.6) / Finalize ✅ success view
Load wheel dependencies (amd64, 12.6) / Metadata ✅ success view
Load wheel dependencies (amd64, 13.0) / Caching ✅ success view
Load wheel dependencies (amd64, 13.0) / Finalize ✅ success view
Load wheel dependencies (amd64, 13.0) / Metadata ✅ success view
Load wheel dependencies (arm64, 12.6) / Caching ✅ success view
Load wheel dependencies (arm64, 12.6) / Finalize ✅ success view
Load wheel dependencies (arm64, 12.6) / Metadata ✅ success view
Load wheel dependencies (arm64, 13.0) / Caching ✅ success view
Load wheel dependencies (arm64, 13.0) / Finalize ✅ success view
Load wheel dependencies (arm64, 13.0) / Metadata ✅ success view
Prepare cache clean-up ✅ success view
Retrieve PR info ✅ success view
⚠️ Required checks (3/6) — 3 missing — declared in .github/required-checks.yml for push
Required check Status Link
Build and test (amd64, llvm, openmpi) / Dev environment (Debug) ✅ success view
Build and test (amd64, llvm, openmpi) / Dev environment (Python) ❌ failure view
Build and test (arm64, llvm, openmpi) / Dev environment (Debug) ✅ success view
Build and test (arm64, llvm, openmpi) / Dev environment (Python) ❌ failure view
Build and test (amd64, gcc12, openmpi) / Dev environment (Debug) ✅ success view
Build and test (amd64, gcc12, openmpi) / Dev environment (Python) ❌ failure view

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant