Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Checking vector size for a power of 2 #2491

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

sacpis
Copy link
Collaborator

@sacpis sacpis commented Dec 31, 2024

Fixes #2490

Before

root@0a258c0dfa5e:/workspaces/cuda-quantum# python3 docs/sphinx/examples/python/test.py 
psi: 

x: [ 0.02885535 -0.22501647  0.73514494 -0.49309571 -0.11248261 -0.38993626
  0.01583871]
Segmentation fault (core dumped)

After

root@0a258c0dfa5e:/workspaces/cuda-quantum# python3 docs/sphinx/examples/python/test.py 
ValueError: Invalid vector size: 7. Vector size must be a power of 2.

Test result

100% tests passed, 0 tests failed out of 810

Label Time Summary:
gpu_required    = 242.09 sec*proc (381 tests)

Total Test time (real) = 1156.59 sec

@sacpis sacpis requested review from 1tnguyen and bmhowe23 December 31, 2024 19:56
github-actions bot pushed a commit that referenced this pull request Dec 31, 2024
Copy link

CUDA Quantum Docs Bot: A preview of the documentation can be found here.

1 similar comment
Copy link

github-actions bot commented Jan 1, 2025

CUDA Quantum Docs Bot: A preview of the documentation can be found here.

github-actions bot pushed a commit that referenced this pull request Jan 1, 2025
@sacpis sacpis marked this pull request as ready for review January 1, 2025 01:12
@@ -99,6 +99,14 @@ inline py::args simplifiedValidateInputArguments(py::args &args) {
if (shape.size() != 1)
throw std::runtime_error("Cannot pass ndarray with shape != (N,).");

// Vector size validation
size_t size = shape[0].cast<size_t>();
if (size == 0 || (size & (size - 1)) != 0) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This check is only valid if the argument is used as an initializer (state) for a register of qubits. That is, we are allowed to pass a vector of any length of floats to a kernel in general.

@sacpis sacpis force-pushed the check_vector_size_for_the_power_of_2 branch from 4257988 to a1dda5a Compare January 3, 2025 21:13
@sacpis sacpis marked this pull request as draft January 3, 2025 22:37
github-actions bot pushed a commit that referenced this pull request Jan 3, 2025
Copy link

github-actions bot commented Jan 3, 2025

CUDA Quantum Docs Bot: A preview of the documentation can be found here.

Copy link

github-actions bot commented Jan 6, 2025

CUDA Quantum Docs Bot: A preview of the documentation can be found here.

github-actions bot pushed a commit that referenced this pull request Jan 6, 2025
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.

Segmentation fault in cudaq.observe() when the state/ket is not a power of 2
2 participants