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

How to get accurate expectation value of a circuit with conditional gates #52

Closed
royess opened this issue Jul 24, 2022 · 2 comments
Closed

Comments

@royess
Copy link
Contributor

royess commented Jul 24, 2022

I found that conditional_gate now is designed to work in a probabilistic way. I think a batched evaluation can work. But I want to know if there is a way to get the accurate expectation value, which is averaged over conditional measurement outcomes.

An example:

c = tc.Circuit(nqubits)
c.h(0)
z = c.cond_measure(0)
c.conditional_gate(z, [tc.gates.i(), tc.gates.x()], 2)
print(c.expectation_ps(z=[2]))

Now it gives -1 and +1 each with a 0.5 possibilities. But I want to get 0 as an expectation instead. And I suppose in principle this is implementable in the tensor contraction manner.

And this is also related to #46 , where the expectation value of circuits with conditional gates is needed.

@refraction-ray
Copy link
Contributor

refraction-ray commented Jul 24, 2022

I wonder whether the thing you really want is like a multi control gate:

c = tc.Circuit(3)
c.h(0)
c.multicontrol(0, 2, unitary=tc.gates.x(), ctrl=[1])
c.expectation_ps(z=[2])

Or somehow, multicontrol and cond_measure are the same thing based on the philosophy of deferred measurement

@royess
Copy link
Contributor Author

royess commented Jul 25, 2022

Thanks for your reply! I think you are right that multicontrol is the correct choice for my example codes. And I realize that this works for QCNN as well.

Or somehow, multicontrol and cond_measure are the same thing based on the philosophy of deferred measurement

That makes sense in the cases above and in most cases I can think about.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants