Skip to content

Add two quantum embeddings#4667

Open
simsaidan wants to merge 11 commits into
NVIDIA:mainfrom
simsaidan:aidans/embeddings
Open

Add two quantum embeddings#4667
simsaidan wants to merge 11 commits into
NVIDIA:mainfrom
simsaidan:aidans/embeddings

Conversation

@simsaidan

Copy link
Copy Markdown

Resolves #2982

Implements the amplitude encoding and angular encoding. Supports both numpy and cupy ndarrays. For the second encoding, blocks a non-kernel call with an error. Updates the ast bridge, which does some compile time checks.
Used cursor for planning.

@copy-pr-bot

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

@1tnguyen

1tnguyen commented Jun 4, 2026

Copy link
Copy Markdown
Collaborator

/ok to test d3c221b

Command Bot: Processing...

@github-actions

github-actions Bot commented Jun 4, 2026

Copy link
Copy Markdown

CI Summary (push) — ❌ failed

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

@schweitzpgi

Copy link
Copy Markdown
Collaborator

C++ implementation?

@schweitzpgi

Copy link
Copy Markdown
Collaborator

Is this a dup of #4666 ?

@simsaidan

Copy link
Copy Markdown
Author

Hi @schweitzpgi @1tnguyen I extended the implementation over to C++.

@bettinaheim

bettinaheim commented Jun 4, 2026

Copy link
Copy Markdown
Collaborator

@simsaidan Thank you for this contribution!

  • Can you please update the PR to have this go into the contrib module/contrib namespace?
  • I'll re-trigger CI; please keep an eye out and get this into a state where all pipelines pass.
  • We'll help to unify this contribution with Add amplitude and angular quantum embeddings #4666, which contains additional Python tests for builder mode and nice doc comments.
    We appreciate if you are willing to help bring this across the finish line in a collaborative manner.

@bettinaheim

bettinaheim commented Jun 4, 2026

Copy link
Copy Markdown
Collaborator

/ok to test ba96e03

Command Bot: Processing...

@sacpis

sacpis commented Jun 4, 2026

Copy link
Copy Markdown
Collaborator

/ok to test 44e0ef5

Command Bot: Processing...

ans248 added 3 commits June 4, 2026 20:14
Signed-off-by: Aidan Sims <ans248@cornell.edu>
Signed-off-by: Aidan Sims <ans248@cornell.edu>
@simsaidan simsaidan force-pushed the aidans/embeddings branch from deea007 to 76a7a1a Compare June 5, 2026 03:38
@simsaidan

Copy link
Copy Markdown
Author

Hey @bettinaheim ! I updated the PR and moved the embeddings to the contrib namespace. I improved the doc comments and added support for builder mode.

@simsaidan

Copy link
Copy Markdown
Author

Hey @bettinaheim @schweitzpgi ! Could you trigger the CI check again so I can see if it is green or otherwise what I need to fix?

@sacpis

sacpis commented Jun 8, 2026

Copy link
Copy Markdown
Collaborator

@simsaidan Have you built the code and ran the tests locally?

@simsaidan

Copy link
Copy Markdown
Author

@sacpis Yes, I ran CI and tests locally and no fails

@sacpis

sacpis commented Jun 8, 2026

Copy link
Copy Markdown
Collaborator

For the latest spelling fix 7a52c2e, please use backticks around those words as those are not english words to be added to .github/pre-commit/spelling_allowlist.txt.

@sacpis

sacpis commented Jun 8, 2026

Copy link
Copy Markdown
Collaborator

Also, would you please sign your commits?

@sacpis

sacpis commented Jun 8, 2026

Copy link
Copy Markdown
Collaborator

@simsaidan I am seeing the following build failure locally

[896/1343] Building CXX object unittests/CMakeFiles/test_runtime_qpp.dir/integration/kernels_tester.cpp.o
FAILED: unittests/CMakeFiles/test_runtime_qpp.dir/integration/kernels_tester.cpp.o 
ccache /usr/local/toolchain/bin/c++ -DCUDAQ_LIBRARY_MODE -DCUDAQ_SIMULATION_SCALAR_FP64 -DFMT_HEADER_ONLY=1 -DHAS_OPENMP -DNVQIR_BACKEND_NAME=qpp -DQPP_VERSION_NUM=3.1 -DQPP_VERSION_STR=\"3.1\" -D__MATH_LONG_DOUBLE_CONSTANTS -Dtest_runtime_qpp_EXPORTS -I/workspaces/cuda-quantum/build/cudaq/include -I/workspaces/cuda-quantum/cudaq/include -I/workspaces/cuda-quantum/unittests/. -I/workspaces/cuda-quantum/runtime/nvqir/qpp -I/workspaces/cuda-quantum/runtime -I/workspaces/cuda-quantum/tpls/eigen -I/workspaces/cuda-quantum/tpls/fmt/include -I/workspaces/cuda-quantum/runtime/include -I/usr/local/cuda-12.6/targets/x86_64-linux/include -I/workspaces/cuda-quantum/runtime/internal/compiler/include -isystem /usr/local/llvm/include -isystem /workspaces/cuda-quantum/tpls/json/single_include -isystem /workspaces/cuda-quantum/tpls/json/single_include_fwd -isystem /workspaces/cuda-quantum/tpls/qpp/include -isystem /workspaces/cuda-quantum/tpls/qpp/qasmtools/include -isystem /workspaces/cuda-quantum/tpls/googletest-src/googletest/include -isystem /workspaces/cuda-quantum/tpls/googletest-src/googletest -Wno-attributes -Wno-ctad-maybe-unsupported -O3 -DNDEBUG -std=gnu++20 -fPIE   -D_GNU_SOURCE -D_DEBUG -D_GLIBCXX_ASSERTIONS -D_GLIBCXX_USE_CXX11_ABI=1 -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -Wno-error=deprecated-declarations -Wno-uninitialized-const-pointer -Wno-restrict -Wno-stringop-overflow -Wno-stringop-overread --param=evrp-mode=legacy -Wno-character-conversion -Werror -MD -MT unittests/CMakeFiles/test_runtime_qpp.dir/integration/kernels_tester.cpp.o -MF unittests/CMakeFiles/test_runtime_qpp.dir/integration/kernels_tester.cpp.o.d -o unittests/CMakeFiles/test_runtime_qpp.dir/integration/kernels_tester.cpp.o -c /workspaces/cuda-quantum/unittests/integration/kernels_tester.cpp
In file included from ../unittests/integration/kernels_tester.cpp:10:
../runtime/cudaq/builder/kernels.h: In instantiation of ‘void cudaq::contrib::angular_encode(Kernel&&, cudaq::QuakeValue&, cudaq::QuakeValue&, RotationAxis) [with Kernel = cudaq::kernel_builder<std::vector<double, std::allocator<double> > >&]’:
../unittests/integration/kernels_tester.cpp:250:33:   required from here
../runtime/cudaq/builder/kernels.h:238:30: error: no matching function for call to ‘applyAxisRotation(cudaq::kernel_builder<std::vector<double, std::allocator<double> > >&, cudaq::contrib::RotationAxis&, cudaq::QuakeValue, cudaq::QuakeValue)’
  238 |     detail::applyAxisRotation(kernel, rotation, angles[i], q[i]);
      |     ~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../runtime/cudaq/builder/kernels.h:163:6: note: candidate: ‘template<class Kernel> void cudaq::contrib::detail::applyAxisRotation(Kernel&, cudaq::contrib::RotationAxis, cudaq::QuakeValue&, cudaq::QuakeValue&)’
  163 | void applyAxisRotation(Kernel &kernel, RotationAxis axis, QuakeValue &theta,
      |      ^~~~~~~~~~~~~~~~~
../runtime/cudaq/builder/kernels.h:163:6: note:   template argument deduction/substitution failed:
../runtime/cudaq/builder/kernels.h:238:30: note:   cannot convert ‘cudaq::QuakeValue::operator[](const cudaq::QuakeValue&)((*(const cudaq::QuakeValue*)(& i)))’ (type ‘cudaq::QuakeValue’) to type ‘cudaq::QuakeValue&’
  238 |     detail::applyAxisRotation(kernel, rotation, angles[i], q[i]);
      |     ~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../runtime/cudaq/builder/kernels.h:179:6: note: candidate: ‘template<class Kernel> void cudaq::contrib::detail::applyAxisRotation(Kernel&, cudaq::contrib::RotationAxis, double, cudaq::QuakeValue&)’
  179 | void applyAxisRotation(Kernel &kernel, RotationAxis axis, double theta,
      |      ^~~~~~~~~~~~~~~~~
../runtime/cudaq/builder/kernels.h:179:6: note:   template argument deduction/substitution failed:
../runtime/cudaq/builder/kernels.h:238:30: note:   cannot convert ‘cudaq::QuakeValue::operator[](const cudaq::QuakeValue&)((*(const cudaq::QuakeValue*)(& i)))’ (type ‘cudaq::QuakeValue’) to type ‘double’
  238 |     detail::applyAxisRotation(kernel, rotation, angles[i], q[i]);
      |     ~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../runtime/cudaq/builder/kernels.h: In instantiation of ‘void cudaq::contrib::angular_encode(Kernel&&, cudaq::QuakeValue&, std::span<const double>, RotationAxis) [with Kernel = cudaq::kernel_builder<>&]’:
../runtime/cudaq/builder/kernels.h:262:17:   required from ‘void cudaq::contrib::angular_encode(Kernel&&, cudaq::QuakeValue&, const std::vector<double>&, RotationAxis) [with Kernel = cudaq::kernel_builder<>&]’
../unittests/integration/kernels_tester.cpp:228:33:   required from here
../runtime/cudaq/builder/kernels.h:254:30: error: no matching function for call to ‘applyAxisRotation(cudaq::kernel_builder<>&, cudaq::contrib::RotationAxis&, std::span<const double>::element_type&, cudaq::QuakeValue)’
  254 |     detail::applyAxisRotation(kernel, rotation, angles[i], q[i]);
      |     ~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../runtime/cudaq/builder/kernels.h:163:6: note: candidate: ‘template<class Kernel> void cudaq::contrib::detail::applyAxisRotation(Kernel&, cudaq::contrib::RotationAxis, cudaq::QuakeValue&, cudaq::QuakeValue&)’
  163 | void applyAxisRotation(Kernel &kernel, RotationAxis axis, QuakeValue &theta,
      |      ^~~~~~~~~~~~~~~~~
../runtime/cudaq/builder/kernels.h:163:6: note:   template argument deduction/substitution failed:
../runtime/cudaq/builder/kernels.h:254:30: note:   cannot convert ‘angles.std::span<const double>::operator[](i)’ (type ‘std::span<const double>::element_type’ {aka ‘const double’}) to type ‘cudaq::QuakeValue&’
  254 |     detail::applyAxisRotation(kernel, rotation, angles[i], q[i]);
      |     ~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../runtime/cudaq/builder/kernels.h:179:6: note: candidate: ‘template<class Kernel> void cudaq::contrib::detail::applyAxisRotation(Kernel&, cudaq::contrib::RotationAxis, double, cudaq::QuakeValue&)’
  179 | void applyAxisRotation(Kernel &kernel, RotationAxis axis, double theta,
      |      ^~~~~~~~~~~~~~~~~
../runtime/cudaq/builder/kernels.h:179:6: note:   template argument deduction/substitution failed:
../runtime/cudaq/builder/kernels.h:254:30: note:   cannot convert ‘cudaq::QuakeValue::operator[](std::size_t)(i)’ (type ‘cudaq::QuakeValue’) to type ‘cudaq::QuakeValue&’
  254 |     detail::applyAxisRotation(kernel, rotation, angles[i], q[i]);
      |     ~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1plus: note: unrecognized command-line option ‘-Wno-character-conversion’ may have been intended to silence earlier diagnostics
cc1plus: note: unrecognized command-line option ‘-Wno-uninitialized-const-pointer’ may have been intended to silence earlier diagnostics
[929/1343] Building CXX object unittests/CMakeFiles/test_runtime_qpp.dir/backends/QPPTester.cpp.o
ninja: build stopped: subcommand failed.

Signed-off-by: Aidan Sims <ans248@cornell.edu>
@simsaidan

Copy link
Copy Markdown
Author

@sacpis I added backticks and removed those words from the allowlist. I also made a change to address that build failure. I signed the latest commit. Do I need to anything retroactively to the commits before or does signing the latest one cover me?

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

Thanks @simsaidan. Have put some comments. Let's run the CI now.

Comment thread python/cudaq/contrib/encoding.py Outdated
*,
pad: complex | float = 0,
) -> State:
"""

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.

Let's make these docstrings raw in order to avoid \r escape.
Would you please run scripts/build_docs.sh and see if these are rendered as expected?

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.

Please check all symbols followed by \.

Comment on lines +1 to +7
/*******************************************************************************
* Copyright (c) 2026 NVIDIA Corporation & Affiliates. * All rights reserved.
* *
* *
* This source code and the accompanying materials are made available under *
* the terms of the Apache License 2.0 which accompanies this distribution. *
******************************************************************************/

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.

Let's fix the header here.

* *
* This source code and the accompanying materials are made available under *
* the terms of the Apache License 2.0 which accompanies this distribution. *
******************************************************************************/

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.

Let's fix the header here.

Comment on lines +1 to +7
/*******************************************************************************
* Copyright (c) 2026 NVIDIA Corporation & Affiliates. * All rights reserved.
* *
* *
* This source code and the accompanying materials are made available under *
* the terms of the Apache License 2.0 which accompanies this distribution. *
******************************************************************************/

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.

Let's fix the header here.

@sacpis

sacpis commented Jun 8, 2026

Copy link
Copy Markdown
Collaborator

Would you please add the following text in an empty commit? It will sign the commits which does not contain your signature.

DCO Remediation Commit for Aidan Sims <ans248@cornell.edu>

I, Aidan Sims <ans248@cornell.edu>, hereby add my Signed-off-by to this commit: 76a7a1a8a6b33c549e1df8f37bf9c64a0ebf96c5
I, Aidan Sims <ans248@cornell.edu>, hereby add my Signed-off-by to this commit: 7a52c2e2d31fefd3b368ab09bf8229fa22b544f8

Signed-off-by: Aidan Sims <ans248@cornell.edu>

Please do run this command to commit it

git commit -s --allow-empty

ans248 added 2 commits June 8, 2026 17:27
Use raw docstrings for LaTeX in cudaq.contrib.encoding, align copyright
headers in encoding sources/tests, and relax sized veq to unsized veq at
kernel call sites.

Signed-off-by: Aidan Sims <ans248@cornell.edu>
I, Aidan Sims <ans248@cornell.edu>, hereby add my Signed-off-by to this commit: 76a7a1a
I, Aidan Sims <ans248@cornell.edu>, hereby add my Signed-off-by to this commit: 7a52c2e

Signed-off-by: Aidan Sims <ans248@cornell.edu>
@simsaidan

Copy link
Copy Markdown
Author

@sacpis @bettinaheim Added the empty commit and fixed the headers and docstrings. I also made an edit which I hope will address the latest CI failures

Comment thread python/cudaq/contrib/encoding.py Outdated
a 1D vector.
TypeError: If ``data`` has an unsupported type.

# Example:

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.

I think we can put examples under examples/ as these are not rendered properly in the API section.

Image

@sacpis

sacpis commented Jun 9, 2026

Copy link
Copy Markdown
Collaborator

/ok to test 95c8527

Command Bot: Processing...

@sacpis

sacpis commented Jun 9, 2026

Copy link
Copy Markdown
Collaborator

Please run bash scripts/run_all_spelling.sh before pushing the fix for spellings.

@sacpis

sacpis commented Jun 9, 2026

Copy link
Copy Markdown
Collaborator

Seems like a regression caused with the latest changes.
https://github.com/NVIDIA/cuda-quantum/actions/runs/27234942193/job/80431397976?pr=4667#step:13:2914

ans248 added 2 commits June 10, 2026 10:21
Signed-off-by: Aidan Sims <ans248@cornell.edu>
Signed-off-by: Aidan Sims <ans248@cornell.edu>
@simsaidan

Copy link
Copy Markdown
Author

@sacpis Spelling should be good now and I moved the examples. For the regression, the fix for the last error, I added a conversion step between sized and unsized registers. That change makes the past errors pass but makes this new test fail. Should I try to find some other workaround that would make both pass?

@sacpis

sacpis commented Jun 10, 2026

Copy link
Copy Markdown
Collaborator

@sacpis Spelling should be good now and I moved the examples. For the regression, the fix for the last error, I added a conversion step between sized and unsized registers. That change makes the past errors pass but makes this new test fail. Should I try to find some other workaround that would make both pass?

Thanks @simsaidan. We would like to see everything passing with this PR.

@sacpis

sacpis commented Jun 10, 2026

Copy link
Copy Markdown
Collaborator

Also, would you please collaborate with @ssmswapnil as per @bettinaheim's comment here to unify with PR #4666?

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.

Add common quantum embeddings

6 participants