Update setBit due to overflow in bit shift#623
Update setBit due to overflow in bit shift#623TysonRayJones merged 3 commits intoQuEST-Kit:develfrom
Conversation
|
I am reasonably confident that this might solve #618, as the issue occurs when the probability of qubit Bit strange that it doesn't happen on ARCHER2, but my best guess is that |
|
Aha, brilliant spot! The destination variable remains a How do you feel about instead using a cast in the body of INLINE qindex setBit(qindex number, int bitIndex, int bitValue) {
// beware that shifting the raw int would overflow
qindex bitInPlace = ((qindex) bitValue) << bitIndex;
qindex oneInPlace = QINDEX_ONE << bitIndex;
return (number & ~oneInPlace) | bitInPlace;
}Any alternative to the C-style cast is of course fine too, like INLINE qindex setBit(qindex number, int bitIndex, int bitValue) {
// beware that shifting the raw int would overflow
qindex bitSafe = bitValue;
qindex bitInPlace = bitSafe << bitIndex;
qindex oneInPlace = QINDEX_ONE << bitIndex;
return (number & ~oneInPlace) | bitInPlace;
}@otbrown That's a brilliant realisation! 🎉 |
|
Any of those works from my point of view! Although Though now that I'm thinking about it, you're unlikely to be able to go above 32 qubits in that scenario anyway... |
|
Thanks I'll test the suggested changes now and update the PR. I'm happy with either. I agree that explicit use of |
|
updated and retested |
|
Fair point about Btw my (albeit very incomplete) integration tests were insufficiently big to detect this bug (max = 14 qubit density matrix = 28 qubit statevector). I suppose it's crucial to test |
|
Btw I tentatively added James as an external-collab to the authorlist, though of course he'll imminently be migrated to "current team" anyhow. We could update it all in a handover version/release. |
Hardware target: Nvidia grace-hopper single node
Compile target: COMPILE_CUDA
Cmake: cmake .. -D ENABLE_CUDA=ON -D CMAKE_CUDA_ARCHITECTURES=90 -D CMAKE_INSTALL_PREFIX=/work/jriching/Quest/prefix -D USER_SOURCE=../../QFT/qft.cpp -D OUTPUT_EXE=qft
code: qft implementation used previous Archer2 benchmarking work updated for quest v4.0
Error:
Compute sanitize output:
Output with additional printing from inside https://github.com/QuEST-Kit/QuEST/blob/53f8f3ad60e5b0171646ee8250c0e6ea65878b44/quest/src/gpu/gpu_thrust.cuh#L789C7-L789C54
With proposed change: