NVIDIA / cuda-quantum

C++ and Python support for the CUDA Quantum programming model for heterogeneous quantum-classical workflows
https://nvidia.github.io/cuda-quantum/
Other
427 stars 149 forks source link

from_state prepares incorrect state #819

Open poojarao8 opened 8 months ago

poojarao8 commented 8 months ago

Required prerequisites

Describe the bug

The from_state seems to work as expected for up to 2 qubits, but for the 3 and 4 qubit examples I tested, several discrepancies show up. For e.g., the statevector (0,0,0,0,0,0,0,1) should correspond to state |111>, but the sampling result is |110> instead.

Steps to reproduce the bug

import numpy as np

N = 3
state = np.zeros(2**N, dtype=complex)
state[7] = 1. `
print(state)

kernel = cudaq.from_state(state)
#extracted_state = cudaq.get_state(kernel) 
#print(extracted_state)
result = cudaq.sample(kernel)
print(result) # you get |110> instead of |111>

Expected behavior

from_state on (0,0,0,0,0,0,0,1) should lead to |111> upon sampling

Is this a regression? If it is, put the last known working version (or commit) here.

Not a regression

Environment

Suggestions

No response

poojarao8 commented 8 months ago

This might be my lack of understanding, but I am also confused about what convention we are following here - the little endian or the big endian. When initializing from statevector (0,1,0,0,0,0,0,0), you get |001>. Shouldn't it be |100> as per the cudaq convention? Thank you!

bettinaheim commented 5 months ago

To be tackled as part of https://github.com/NVIDIA/cuda-quantum/issues/1086.