Skip to content

Add angle-producing math functions to kernels with docs and tests#4697

Open
LakshikkaNathan wants to merge 7 commits into
NVIDIA:mainfrom
LakshikkaNathan:math-functions-2942
Open

Add angle-producing math functions to kernels with docs and tests#4697
LakshikkaNathan wants to merge 7 commits into
NVIDIA:mainfrom
LakshikkaNathan:math-functions-2942

Conversation

@LakshikkaNathan

Copy link
Copy Markdown

Closes #2942

Summary

Completes the continuous, angle-producing math functions from the acceptance plan in #2942 (sin, cos, tan, asin, acos, atan, sqrt, exp, log) for C++ and Python: it adds the functions that were not yet supported, and documents and tests the full set.

  • C++ (lib/Frontend/nvqpp/ConvertExpr.cpp): lowering for std::asin, std::acos, std::atan. The other angle functions were already supported.
  • Python (python/cudaq/kernel/ast_bridge.py): adds np.tan, np.asin, np.acos, np.atan, np.log to the supported NumPy functions and lowers them to the matching math dialect ops (real-valued; complex inputs raise).

Against the acceptance plan

  1. C++ supported functions documented in the kernel specification (docs/sphinx/specification/cudaq/kernels.rst).
  2. Python supported functions documented in the same place.
  3. Per-function simulator value tests for all nine functions (test_kernel_float.py), plus a FileCheck lowering test (test/AST-Quake/math_functions.cpp) covering double and float.
  4. An executed gate-parameter test: ry(2*asin(sqrt(p))) prepares a state with P(|1>) = p, verified by sampling.
  5. Continuous angle functions kept separate from discrete control functions.

Testing

Built from source in the cuda-quantum-dev container. The new tests pass, the existing test_kernel_float.py suite still passes, and the FileCheck test passes via cudaq-quake | cudaq-opt | FileCheck.

Note

I'm aware of #4680, which addresses the same issue. This PR takes a similar core approach and additionally includes the documentation and the executed gate-parameter test from the acceptance plan.

AI usage

I used Claude as a coding assistant to help draft this change. I built CUDA-Q from source, ran and verified the tests, and reviewed the full patch before submitting.

Adds C++ lowering for std::asin/acos/atan and Python lowering for
np.tan/asin/acos/atan/log, documents the supported functions for both
languages in the kernel spec, and adds per-function simulator tests plus a
gate-parameter test. Addresses NVIDIA#2942.

Signed-off-by: Lakshikka Sithamparanathan <2922185@vikes.csuohio.edu>
@copy-pr-bot

copy-pr-bot Bot commented Jun 8, 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.

# Conflicts:
#	cudaq/test/AST-Quake/math_functions.cpp
@sacpis

sacpis commented Jun 8, 2026

Copy link
Copy Markdown
Collaborator

/ok to test 43a36fb

Command Bot: Processing...

@github-actions

github-actions Bot commented Jun 8, 2026

Copy link
Copy Markdown

CI Summary (push) — ❌ failed

Run #27305798550 · ✅ 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) ✅ 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
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 (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) ✅ success view
Build and test (amd64, gcc12, openmpi) / Dev environment (Debug) ✅ success view
Build and test (amd64, gcc12, openmpi) / Dev environment (Python) ❌ failure view

Signed-off-by: Lakshikka Sithamparanathan <2922185@vikes.csuohio.edu>
@LakshikkaNathan

Copy link
Copy Markdown
Author

Thanks @sacpis. Pushed a yapf formatting fix in the latest commit (3ffd148). Could you re-run on the latest commit when you get a chance? Thanks

@sacpis

sacpis commented Jun 8, 2026

Copy link
Copy Markdown
Collaborator

/ok to test 845b40b

Command Bot: Processing...

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

Overall LGTM. Thanks @LakshikkaNathan. Left a few comments. Once we have those changes, will take a look at it again before approving.

Comment thread cudaq/lib/Frontend/nvqpp/ConvertExpr.cpp
Comment thread python/tests/kernel/test_kernel_float.py Outdated
Comment thread python/tests/kernel/test_kernel_float.py Outdated
Comment thread python/tests/kernel/test_kernel_float.py Outdated
Signed-off-by: Lakshikka Sithamparanathan <2922185@vikes.csuohio.edu>
@LakshikkaNathan

Copy link
Copy Markdown
Author

Thanks for the review, @sacpis! Addressed all the comments in 41c15fd5, added arcsin/arccos/arctan support in ast_bridge.py and switched the test kernels to match. Ready for another look whenever you have time.

@sacpis

sacpis commented Jun 10, 2026

Copy link
Copy Markdown
Collaborator

/ok to test a53ca21

Command Bot: Processing...

Comment thread python/tests/kernel/test_kernel_float.py Outdated
Signed-off-by: Lakshikka Sithamparanathan <2922185@vikes.csuohio.edu>
@LakshikkaNathan

Copy link
Copy Markdown
Author

Added the np.float32 tests in 84e441c. Ready for another look, thanks @sacpis!

@sacpis

sacpis commented Jun 10, 2026

Copy link
Copy Markdown
Collaborator

/ok to test 84e441c

Command Bot: Processing...

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

2 participants