Skip to content

Add kernel math function support#4680

Open
LubuSeb wants to merge 7 commits into
NVIDIA:mainfrom
LubuSeb:codex/unitaryhack-cudaq-2942-math-functions
Open

Add kernel math function support#4680
LubuSeb wants to merge 7 commits into
NVIDIA:mainfrom
LubuSeb:codex/unitaryhack-cudaq-2942-math-functions

Conversation

@LubuSeb

@LubuSeb LubuSeb commented Jun 5, 2026

Copy link
Copy Markdown

Closes #2942.

Summary

  • add C++ AST lowering for asin, acos, and atan, including float overloads
  • add Python AST bridge lowering for real-valued NumPy tan, asin, acos, atan, and log
  • add focused C++ FileCheck and Python kernel tests for the newly covered math functions

Reproduction / scope

The bounty issue asks for continuous mathematical function support in CUDA-Q kernels. Existing C++ lowering already handled several functions through visitMathLibFunc; this change extends that same path for inverse trig functions. Python lowering already mapped selected NumPy calls through the AST bridge; this change adds the missing real-valued operations there while leaving untested complex inverse trig/log/tan support out of scope.

Minimality

This is limited to the existing lowering tables/switches and targeted tests. It does not refactor the frontend, broaden discrete-control support, or add backend-specific behavior.

Validation

  • python -m py_compile python/cudaq/kernel/ast_bridge.py python/tests/kernel/test_kernel_float.py
  • git diff --cached --check
  • Local standalone <cmath> syntax smoke check for the float overload names used by the new C++ test

Not run locally: CUDA-Q native lit/runtime tests, because the local environment does not have the CUDA-Q compiler/test toolchain installed.

AI assistance disclosure

I used AI assistance to inspect the codebase and draft parts of this change; I reviewed the final patch and validation results before submission.

@copy-pr-bot

copy-pr-bot Bot commented Jun 5, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

Signed-off-by: LubuSeb <187313664+LubuSeb@users.noreply.github.com>
@sacpis

sacpis commented Jun 10, 2026

Copy link
Copy Markdown
Collaborator

/ok to test 157f60f

Command Bot: Processing...

@github-actions

github-actions Bot commented Jun 10, 2026

Copy link
Copy Markdown

CI Summary (push) — ❌ failed

Run #27433361011 · ✅ 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) ✅ 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) ❌ 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 ❔ in_progress view
Retrieve PR info ✅ success view
⚠️ Required checks (5/6) — 1 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) ✅ success 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) ✅ success view

Signed-off-by: LubuSeb <187313664+LubuSeb@users.noreply.github.com>
@LubuSeb

LubuSeb commented Jun 11, 2026

Copy link
Copy Markdown
Author

Pushed 5f79e6a to address the Python CI failure from the previous tested head: the tests now use NumPy's current inverse-trig spellings (arcsin, arccos, arctan) while the bridge still accepts the existing asin/acos/atan aliases.

Local validation on the latest head:

python -m py_compile python/cudaq/kernel/ast_bridge.py python/tests/kernel/test_kernel_float.py

The latest head currently only has DCO, so it should be ready for another /ok to test when you have a chance.

@sacpis

sacpis commented Jun 11, 2026

Copy link
Copy Markdown
Collaborator

/ok to test 5cc9d4a

Command Bot: Processing...

Comment thread cudaq/test/AST-Quake/math_functions.cpp Outdated
Signed-off-by: Eric Schweitz <eschweitz@nvidia.com>

@schweitzpgi schweitzpgi 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

@schweitzpgi

schweitzpgi commented Jun 12, 2026

Copy link
Copy Markdown
Collaborator

/ok to test a4daeb0

Command Bot: Processing...

@schweitzpgi schweitzpgi enabled auto-merge June 12, 2026 17:55
Signed-off-by: LubuSeb <187313664+LubuSeb@users.noreply.github.com>
auto-merge was automatically disabled June 14, 2026 00:58

Head branch was pushed to by a user without write access

@LubuSeb

LubuSeb commented Jun 14, 2026

Copy link
Copy Markdown
Author

Pushed f8cc1de3c to address the remaining ARM Python CI failure on the latest tested head.

Root cause from the failed job: test_cudaq_uccsd1 now allows either 5 or 6 sampled states, but still asserted all six specific states were present. The failed ARM run hit the valid 5-state case and missed 00000011, so the membership assertion was stricter than the preceding len(counts) == 6 or len(counts) == 5 guard.

The follow-up keeps the test scoped to the known UCCSD output support: observed states must still be a 5-or-6-sized subset of the six expected bitstrings. No math lowering code changed in this commit.

Local validation available in this Windows checkout:

python -m py_compile python/tests/kernel/test_kernel_uccsd.py python/cudaq/kernel/ast_bridge.py python/tests/kernel/test_kernel_float.py
git diff --check

I could not run the CUDA-Q runtime pytest locally because this checkout does not have a built cudaq.kernel runtime installed.

The latest head only has DCO again, so it should need another /ok to test for NVIDIA runners.

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.

Mathematical functions support

3 participants