Skip to content

Preserve native negated gate controls through full QIR - #5516

Open
khalatepradnya wants to merge 2 commits into
NVIDIA:mainfrom
khalatepradnya:feature/native-negated-gate-controls
Open

khalatepradnya wants to merge 2 commits into
NVIDIA:mainfrom
khalatepradnya:feature/native-negated-gate-controls

Conversation

@khalatepradnya

@khalatepradnya khalatepradnya commented Sep 30, 2026 •

Copy link
Copy Markdown
Collaborator
  • Preserve negated controls through full-QIR lowering for ordinary gates, custom unitaries, and exp_pauli, using the existing NVQIR control-value interfaces.
  • Enable native cuStateVec execution while retaining runtime X-conjugation fallback for other simulators. Other QIR profile targets continue to expand negated controls.
  • In a representative 30-qubit QROM circuit, eliminate 64 explicit X gates, reducing the raw gate count from 110 to 46.
Carry ordered control values to NVQIR so simulators can avoid
compiler-inserted X conjugation. Support ordinary gates, custom
unitaries, and exp-Pauli through the runtime control-value interface.

Retain control-negation expansion for hardware/profile pipelines.

Resolves NVIDIA#4230

Co-authored-by: Codex <codex@openai.com>
Signed-off-by: Pradnya Khalate <pkhalate@nvidia.com>
@github-actions github-actions Bot added python-lang Anything related to the Python CUDA Quantum language implementation core compiler labels Sep 30, 2026
@khalatepradnya khalatepradnya changed the title [compiler] Preserve native negated gate controls through full QIR Sep 30, 2026
@khalatepradnya khalatepradnya linked an issue Sep 30, 2026 that may be closed by this pull request
1 task done
@github-actions

github-actions Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

CI Summary (push) — ✅ passed

Run #36944345287 · ✅ 8 · ⏩ 8 · ❌ 0 · ⛔ 0

Top-level jobs (16)
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
gen_code_coverage ⏩ skipped
metadata ✅ success
python_devel_wheel ⏩ skipped
python_metapackages ⏩ skipped
python_wheels ⏩ skipped
source_build ⏩ skipped
wheeldeps ✅ success
⏩ Skipped jobs (8) — intentionally skipped on PR builds; run on merge_group / workflow_dispatch
Job
binaries
config_source_build
docker_image
gen_code_coverage
python_devel_wheel
python_metapackages
python_wheels
source_build
All sub-jobs (45) — 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 Quantum installer ⏩ skipped view
Create Docker images ⏩ skipped view
Create Python metapackages ⏩ skipped view
Create Python wheels ⏩ 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
✅ 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

@sacpis sacpis 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. Thanks @khalatepradnya. Let's wait for @schweitzpgi feedback here.

"invokeWithControlRegisterOrQubits";
static constexpr const char NVQIRGeneralizedInvokeAny[] =
"generalizedInvokeWithRotationsControlsTargets";
static constexpr const char NVQIRInvokeControlValues[] =

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.

Do we really need a second "most generalized" way of applying a gate? It reads like an oxymoron.

Comment thread cudaq/lib/Optimizer/CodeGen/ConvertToQIRAPI.cpp Outdated
Comment thread cudaq/lib/Optimizer/CodeGen/ConvertToQIRAPI.cpp Outdated
Comment thread cudaq/lib/Optimizer/CodeGen/ConvertToQIRAPI.cpp
//===----------------------------------------------------------------------===//

// The runtime copies control values before returning. Scope the temporary
// buffer so repeated gate calls do not accumulate dynamic stack allocations.

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.

This should be folded into a common wrapper function like the original general invoker does rather than generate special handling code on the fly.

Comment thread cudaq/lib/Optimizer/CodeGen/ConvertToQIRAPI.cpp
Signed-off-by: Pradnya Khalate <pkhalate@nvidia.com>

This branch has not been deployed

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

Labels

core compiler python-lang Anything related to the Python CUDA Quantum language implementation

3 participants