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
For inspecting a state obtained via state = cudaq.get_state(...), there are basically 3 options.
print(state)
print(state[i])
print(state.amplitude(bit_string))
Given the ususal cudaq-convention of using big-endian bitstrings, the previous option 2 provides a contradicting result as I guess it uses a little-endian ordering of the states. (example big-endian bit string: |q_0 q_1> --> 'q_0 q_1')
In option 2 the bitstring needs to be converted to a single integer index. Following big-endian convention I would expect this to be done via (example 2 qubit case):
q_0*2^0 + q_1*2^1 --> index
00 --> 0
10 --> 1
01 --> 2
11 --> 3
Options 1 and 3 seem to stick to this definition, however option 2 does not. In my opinion especially the mismatch between option 1 and 2 are confusing, and I suggest sticking to big-endian throughout.
samples: { 10:1000 }
state: SV: [(0,0), (1,0), (0,0), (0,0)] <-- big-endian bit order as second entry of SV holds non-zero amplitude
i | bs_le: | bs_be: | state[i]: | state.amplitude(bs_be):
0 00 00 0j 0j
1 01 10 0j (1+0j)
2 10 01 (1+0j) 0j <-- little-endian bit order as only third entry of state (`state[2]`) holds non-zero amplitude
3 11 11 0j 0j
While I expected:
samples: { 10:1000 }
state: SV: [(0,0), (1,0), (0,0), (0,0)]
i | bs_le: | bs_be: | state[i]: | state.amplitude(bs_be):
0 00 00 0j 0j
1 01 10 (1+0j) (1+0j) <-- big-endian bit order also for state[i]
2 10 01 0j 0j
3 11 11 0j 0j
For inspecting a state obtained via
state = cudaq.get_state(...)
, there are basically 3 options.print(state)
print(state[i])
print(state.amplitude(bit_string))
Given the ususal cudaq-convention of using big-endian bitstrings, the previous option 2 provides a contradicting result as I guess it uses a little-endian ordering of the states. (example big-endian bit string: |q_0 q_1> --> 'q_0 q_1')
In option 2 the bitstring needs to be converted to a single integer index. Following big-endian convention I would expect this to be done via (example 2 qubit case):
Options 1 and 3 seem to stick to this definition, however option 2 does not. In my opinion especially the mismatch between option 1 and 2 are confusing, and I suggest sticking to big-endian throughout.
MWE:
Produces:
While I expected:
Related issues:
cudaq::sample
when using different modes (library mode vs non-library mode) #978Environment
The text was updated successfully, but these errors were encountered: