Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Q-ctrt expectation values are returned as 1D array unlike runtime which is 0D #25

Open
nonhermitian opened this issue Nov 3, 2024 · 5 comments
Labels
bug Something isn't working

Comments

@nonhermitian
Copy link

Steps to reproduce the problem

Consider the circuit operator pair:

N = 12
qc = QuantumCircuit(N)

qc.x(range(N))
qc.h(range(N))

for kk in range(N // 2, 0, -1):
    qc.ch(kk, kk - 1)
for kk in range(N // 2, N - 1):
    qc.ch(kk, kk + 1)

op = SparsePauliOp('Z'*12)

The Qiskit runtime, IBM circuit function, and TEM function all return the expectation values as 0D arrays, e.g. array(0.39490533). In contrast the Q-ctrl result is a 1D array, array([0.4495]).

What is the current behavior?

see above

What is the expected behavior?

The return objects should have unified shapes.

@nonhermitian nonhermitian added the bug Something isn't working label Nov 3, 2024
@chongyouquan
Copy link

Hi @nonhermitian, our Qiskit Function Estimator output is based on the StatevectorEstimator, as we were advised previously.
It seems to return a 1D array here.

If this is an issue for our Estimator, should the output for StatevectorEstimator be updated as well?

@nonhermitian
Copy link
Author

So I think the source of ground truth in this case should be what the runtime returns. That is to say that given the same input pubs, the output should match the runtime. Executing the examples in the readme of the runtime repo (ignoring the fact that some are not updated properly, Qiskit/qiskit-ibm-runtime#2013) then I see that a 0D array seems to be the correct output. It is also the output of the IBM circuit functions, and others.

I also agree that the StateVectorEstimator output should align with the others as well.

@nonhermitian
Copy link
Author

For the record, I have run the statevector estimator, and it also returns 0D data,

est = StatevectorEstimator()
est.run(pubs=pubs).result()[0].data.evs

gives array(0.44628906) for the circuit here.

@chongyouquan
Copy link

For the record, I have run the statevector estimator, and it also returns 0D data,

est = StatevectorEstimator()
est.run(pubs=pubs).result()[0].data.evs
gives array(0.44628906) for the circuit here.

Gotcha, thanks for the clarification. We're fixing this issue to return the correct shape here.

@johannesgreiner
Copy link

Latest behaviour is that q-ctrl expectation values are returned as floats. @chongyouquan is currently checking to update this to 0D array

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants