You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Consult the security policy. If reporting a security vulnerability, do not report the bug using this form. Use the process described in the policy to report the issue.
Make sure you've read the documentation. Your issue may be addressed there.
Search the issue tracker to verify that this hasn't already been reported. +1 or comment there if it has.
If possible, make a PR with a failing test to give us a starting point to work on!
Describe the bug
When a vector of size N is passed to cudaq.observe() and N is not a power of 2, the software segfaults rather that give a descriptive error message.
Steps to reproduce the bug
import numpy as np
import cudaq
from cudaq import spin
cudaq.set_target('qpp-cpu')
n_size = 7
@cudaq.kernel
def initial_state(vec: list[float]):
q = cudaq.qvector(vec)
x = np.random.randn(n_size)
x = x / np.linalg.norm(x)
psi = cudaq.get_state(initial_state, x)
print(f'psi: {psi}')
print(f'x: {x}')
H = -5.0 + 2.5 * spin.x(0) * spin.y(1) + 0.23 * spin.z(1) + 0.11 * spin.z(0)
result = cudaq.observe(initial_state, H, x).expectation()
print(f'result: {result}')
Expected behavior
Should give a meaningful error message to alert the user of the power of 2 requirement
Is this a regression? If it is, put the last known working version (or commit) here.
Not a regression
Environment
CUDA-Q version:
Python version:
C++ compiler:
Operating system:
Suggestions
No response
The text was updated successfully, but these errors were encountered:
It would be advantageous if the error check could also handle a mismatch in data length vs the number of qubits. I.e. throw an error if the user provides a vector of length 4 to initialize 4 qubits. If possible, this may need to be done in the simulators themselves (like in the addQubitsToState calls where state is non-null.
The exact number to compare against would need to be simulator-dependent. I.e. 2^n for state-vector-based simulators and 2^(2*n) for density matrix based simulators.
Required prerequisites
Describe the bug
When a vector of size N is passed to cudaq.observe() and N is not a power of 2, the software segfaults rather that give a descriptive error message.
Steps to reproduce the bug
Expected behavior
Should give a meaningful error message to alert the user of the power of 2 requirement
Is this a regression? If it is, put the last known working version (or commit) here.
Not a regression
Environment
Suggestions
No response
The text was updated successfully, but these errors were encountered: