[Hardware path] cudaq.observe()
incorrectly returns 0.0 when there is only a single spin op term
#2382
Open
3 of 4 tasks
Required prerequisites
Describe the bug
When using a single spin-op term, running
cudaq::observe()
from C++ (orcudaq.observe()
from Python) returns incorrect results when running with--emulate
for C++ (oremulate=True
for Python). It returns0.0
instead of a true expectation calculation.Steps to reproduce the bug
Starting with the targettests/execution/cudaq_observe.cpp test already in the repo, if one were to modify
h
to a single term (e.g.cudaq::spin_op h = i(0) * z(1);
), the resulting energy is 0.0 when running with--emulate
and it is non-zero when running without--emulate
.For example, generate this test file (test.cpp):
And then run the following two tests, you will see different answers. The answers should be the same.
Expected behavior
The answers should match.
Note that the example provided in this bug report only deals with the
--emulate
path, but based on partner feedback, I believe the bug exists when using real hardware as well.Is this a regression? If it is, put the last known working version (or commit) here.
Not a regression
Environment
Suggestions
I have tracked down at least one of the problems to this section of code:
cuda-quantum/runtime/common/BaseRemoteRESTQPU.h
Line 692 in 3300b12
That section of code is assuming that if there is a single circuit that was run (like for a single spin op), that it was not actually an observe calculation. This needs to be updated to be correctly ascertain whether the parent request originated from an observe call rather than just inferring it.
The text was updated successfully, but these errors were encountered: