Skip to content

Handling global phase in Quake to P0 conversion - #5860

Merged
sacpis merged 7 commits into
NVIDIA:mainfrom
sacpis:fix_logical_quake_phase
Nov 7, 2026
Merged

sacpis merged 7 commits into
NVIDIA:mainfrom
sacpis:fix_logical_quake_phase

Conversation

@sacpis

@sacpis sacpis commented Nov 6, 2026 •

Copy link
Copy Markdown
Collaborator

Since #5839 made optimization level 2 the default, the T-count optimizer can emit an uncontrolled quake.phase, causing Quake-to-P0 import to fail with

'quake.phase' op is outside the typed Quake-to-P0 conversion contract

Here we have handled global phases directly in the converter, emitting no P0 operation while forwarding wire ownership, measurement state, and reference provenance. Controlled phases remain explicitly rejected because they affect relative phase.

Signed-off-by: Sachin Pisal <spisal@nvidia.com>
@sacpis
sacpis requested a review from taalexander November 6, 2026 17:57
@github-actions github-actions Bot added the cuda-q logical Related to CUDA-Q Logical. label Nov 6, 2026
Signed-off-by: Sachin Pisal <spisal@nvidia.com>
@sacpis sacpis changed the title Dropping global quake.phase before Quake to P0 import Handling global phase in Quake to P0 conversion Nov 6, 2026
@github-actions

github-actions Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

CI Summary (push) — ✅ passed

Run #42322800556 · ✅ 8 · ⏩ 11 · ❌ 0 · ⛔ 0

Top-level jobs (19)
Job Result
binaries ⏩ skipped
build_and_test ✅ success
changes ✅ success
config_devdeps ✅ success
config_source_build ⏩ skipped
config_wheeldeps ✅ success
devdeps ✅ success
docker_image ⏩ skipped
documentation ✅ success
edem_wheels ⏩ skipped
gen_code_coverage ⏩ skipped
metadata ✅ success
python_devel_wheel ⏩ skipped
python_metapackages ⏩ skipped
python_wheels ⏩ skipped
python_wheels_cu12_validation ⏩ skipped
python_wheels_cu13 ⏩ skipped
source_build ⏩ skipped
wheeldeps ✅ success
⏩ Skipped jobs (11) — intentionally skipped on PR builds; run on merge_group / workflow_dispatch
Job
binaries
config_source_build
docker_image
edem_wheels
gen_code_coverage
python_devel_wheel
python_metapackages
python_wheels_cu12_validation
python_wheels_cu13
python_wheels
source_build
All sub-jobs (48) — 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) ✅ success view
Build and test (amd64, llvm, openmpi) / Dev environment (Debug) ✅ success view
Build and test (amd64, llvm, openmpi) / Dev environment (Python) ✅ success view
Build and test (arm64, llvm, openmpi) / Dev environment (Debug) ✅ success view
Build and test (arm64, llvm, openmpi) / Dev environment (Python) ✅ success view
CI Summary ❔ in_progress view
Check for stable CUDA-Q changes ✅ success view
Configure build (devdeps) ✅ success view
Configure build (source_build) ⏩ skipped view
Configure build (wheeldeps) ✅ success view
Create CUDA 12 Python wheels ⏩ skipped view
Create CUDA 13 Python wheels ⏩ skipped view
Create CUDA Quantum installer ⏩ skipped view
Create Docker images ⏩ skipped view
Create Python metapackages ⏩ skipped view
Create cudaq-edem wheels (${{ matrix.platform }}) ⏩ skipped view
Create shared Python development wheel ⏩ skipped view
Documentation / Build and check docs ✅ success 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 ❔ in_progress view
Retrieve PR info ✅ success view
Validate CUDA 12 Python wheels ⏩ skipped view
✅ Required checks (7/7) — 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) ✅ success view
Build and test (arm64, llvm, openmpi) / Dev environment (Debug) ✅ success view
Build and test (arm64, llvm, openmpi) / Dev environment (Python) ✅ success view
Build and test (amd64, gcc12, openmpi) / Dev environment (Debug) ✅ success view
Build and test (amd64, gcc12, openmpi) / Dev environment (Python) ✅ success view
Documentation / Build and check docs ✅ success view

@cabreraam
cabreraam self-requested a review November 6, 2026 19:09
@sacpis
sacpis requested a review from cabreraam November 6, 2026 21:56

@cabreraam cabreraam left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Mostly LGTM! Just have the one comment about hydrateReferenceWires.

Thanks @sacpis

@atgeller atgeller left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM 👍

Signed-off-by: Sachin Pisal <spisal@nvidia.com>
@sacpis
sacpis requested a review from schweitzpgi November 6, 2026 23:52
@sacpis
sacpis added this pull request to the merge queue Nov 7, 2026
@github-actions

github-actions Bot commented Nov 7, 2026

Copy link
Copy Markdown

CI Summary (merge_group) — ✅ passed

Run #42389830765 · ✅ 5 · ⏩ 14 · ❌ 0 · ⛔ 0

⚡ Fast merge queue — only the llvm dev-environment build+test legs ran.
Wheels, metapackages, installers, Docker images, and the gcc12 legs were skipped.
Set the repository variable MERGE_QUEUE_FAST to false to restore the full matrix.

Top-level jobs (19)
Job Result
binaries ⏩ skipped
build_and_test ✅ success
changes ✅ success
config_devdeps ✅ success
config_source_build ⏩ skipped
config_wheeldeps ⏩ skipped
devdeps ✅ success
docker_image ⏩ skipped
documentation ⏩ skipped
edem_wheels ⏩ skipped
gen_code_coverage ⏩ skipped
metadata ✅ success
python_devel_wheel ⏩ skipped
python_metapackages ⏩ skipped
python_wheels ⏩ skipped
python_wheels_cu12_validation ⏩ skipped
python_wheels_cu13 ⏩ skipped
source_build ⏩ skipped
wheeldeps ⏩ skipped
⏩ Skipped jobs (14) — intentionally skipped on PR builds; run on merge_group / workflow_dispatch
Job
binaries
config_source_build
config_wheeldeps
docker_image
documentation
edem_wheels
gen_code_coverage
python_devel_wheel
python_metapackages
python_wheels_cu12_validation
python_wheels_cu13
python_wheels
source_build
wheeldeps
All sub-jobs (29) — every matrix leg, with links
Job Status Link
Build and test (amd64, llvm, openmpi) / Dev environment (Debug) ✅ success view
Build and test (amd64, llvm, openmpi) / Dev environment (Python) ✅ success view
Build and test (arm64, llvm, openmpi) / Dev environment (Debug) ✅ success view
Build and test (arm64, llvm, openmpi) / Dev environment (Python) ✅ success view
CI Summary ❔ in_progress view
Check for stable CUDA-Q changes ✅ success view
Configure build (devdeps) ✅ success view
Configure build (source_build) ⏩ skipped view
Configure build (wheeldeps) ⏩ skipped view
Create CUDA 12 Python wheels ⏩ skipped view
Create CUDA 13 Python wheels ⏩ skipped view
Create CUDA Quantum installer ⏩ skipped view
Create Docker images ⏩ skipped view
Create Python metapackages ⏩ skipped view
Create cudaq-edem wheels (${{ matrix.platform }}) ⏩ skipped view
Create shared Python development wheel ⏩ skipped view
Documentation ⏩ skipped view
Gen code coverage ⏩ skipped 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, 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 ⏩ skipped view
Prepare cache clean-up ❔ in_progress view
Retrieve PR info ✅ success view
Validate CUDA 12 Python wheels ⏩ skipped view
✅ Required checks (4/4) — declared in .github/required-checks.yml for merge_group_fast
Required check Status Link
Build and test (amd64, llvm, openmpi) / Dev environment (Debug) ✅ success view
Build and test (amd64, llvm, openmpi) / Dev environment (Python) ✅ success view
Build and test (arm64, llvm, openmpi) / Dev environment (Debug) ✅ success view
Build and test (arm64, llvm, openmpi) / Dev environment (Python) ✅ success view

Merged via the queue into NVIDIA:main with commit 40c8e5e Nov 7, 2026
257 checks passed
@sacpis
sacpis deleted the fix_logical_quake_phase branch November 7, 2026 17:17
github-actions Bot pushed a commit that referenced this pull request Nov 7, 2026
bettinaheim pushed a commit that referenced this pull request Nov 10, 2026
Since #5839 made optimization level 2 the default, the T-count optimizer
can emit an uncontrolled quake.phase, causing Quake-to-P0 import to fail
with

```
'quake.phase' op is outside the typed Quake-to-P0 conversion contract
```

Here we have handled global phases directly in the converter, emitting
no P0 operation while forwarding wire ownership, measurement state, and
reference provenance. Controlled phases remain explicitly rejected
because they affect relative phase.

---------

Signed-off-by: Sachin Pisal <spisal@nvidia.com>
@schweitzpgi

Copy link
Copy Markdown
Collaborator

Shouldn't P0 have global phase? That seems like a pretty major omission, eh?

sacpis added a commit to sacpis/cuda-quantum that referenced this pull request Nov 10, 2026
…VIDIA#5881)

Closes NVIDIA#5880. Follow-up to the [review
discussion](NVIDIA#5860 (comment))
on NVIDIA#5860.

The Quake-to-QLX converter tracked several live wires per reference, but
valid Quake never produces that. `convert-to-linear-values` unwraps each
`!quake.ref` once and wraps it back once, and it merges duplicate
`extract_ref`s of the same element.

### What we changed here
- Removing the alias tracking (`hydrateReference*`,
`refreshReferenceAliases`, `commitReferenceWireResults`, and the slot
maps). In a helper, `unwrap` reads the reference's slot and `wrap`
writes it back.
- Adding `erase-quake-global-phase`, the first pass in
`prepare-quake-for-qlx`. It erases uncontrolled `quake.phase`. The
converter still rejects controlled phase.
- Deleting checks that guard only the converter's own state, or rules
the Quake verifier already enforces.

---------

Signed-off-by: Sachin Pisal <spisal@nvidia.com>
lmondada pushed a commit to lmondada/cuda-quantum that referenced this pull request Nov 12, 2026
…VIDIA#5881)

Closes NVIDIA#5880. Follow-up to the [review
discussion](NVIDIA#5860 (comment))
on NVIDIA#5860.

The Quake-to-QLX converter tracked several live wires per reference, but
valid Quake never produces that. `convert-to-linear-values` unwraps each
`!quake.ref` once and wraps it back once, and it merges duplicate
`extract_ref`s of the same element.

### What we changed here
- Removing the alias tracking (`hydrateReference*`,
`refreshReferenceAliases`, `commitReferenceWireResults`, and the slot
maps). In a helper, `unwrap` reads the reference's slot and `wrap`
writes it back.
- Adding `erase-quake-global-phase`, the first pass in
`prepare-quake-for-qlx`. It erases uncontrolled `quake.phase`. The
converter still rejects controlled phase.
- Deleting checks that guard only the converter's own state, or rules
the Quake verifier already enforces.

---------

Signed-off-by: Sachin Pisal <spisal@nvidia.com>
@bettinaheim bettinaheim added the no release notes Don't list this PR in the release notes label Nov 12, 2026
@bettinaheim bettinaheim added this to the release 0.17.0 milestone Nov 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cuda-q logical Related to CUDA-Q Logical. no release notes Don't list this PR in the release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants