Skip to content
This repository has been archived by the owner on Dec 7, 2021. It is now read-only.

CircuitSampler drops is_measurement status when converting StateFns #1339

Closed
dongreenberg opened this issue Oct 13, 2020 · 3 comments · Fixed by #1344
Closed

CircuitSampler drops is_measurement status when converting StateFns #1339

dongreenberg opened this issue Oct 13, 2020 · 3 comments · Fixed by #1344
Assignees

Comments

@dongreenberg
Copy link
Contributor

If you look at the code below, you'll find that the measurements have been replaced with StateFns, making the ComposedOps invalid and unable to eval. The same is true for statevector mode.
image

Code:

import qiskit.aqua.operators as of
from qiskit import BasicAer
data = of.ListOp([of.Plus, of.Zero])
qk = ~data @ data
print(qk)
sampled_qk = of.CircuitSampler(backend=BasicAer.get_backend('qasm_simulator')).convert(qk)
print(sampled_qk)

I believe the issue is that on lines 309, 311, and 314 of the CircuitSampler the resulting StateFn should be given the measurement status of op_c.is_measurement, but I'm not 100% positive.

@molar-volume
Copy link
Contributor

molar-volume commented Oct 13, 2020

After setting is_measurement=op_c.is_measurement, it is possible to eval, and for that particular example we get

print(sampled_qk.eval())  # [[1.0, 0.7022564079451321], [0.6803606580336637, 1.0]]

@jlapeyre If you did not start already, I can make the PR for this issue and #1338 .
But if you think that problem is more tricky, I can leave it up to you.

@jlapeyre
Copy link
Contributor

@molar-volume , I won't start it myself. I'll look at your PR

@dongreenberg
Copy link
Contributor Author

Thanks gang! When's the next release?

# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
None yet
Projects
None yet
3 participants