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

Is there a simple example for inner/outer product of single qubit states? #169

Closed
Penghmed opened this issue Sep 7, 2022 · 5 comments
Closed

Comments

@Penghmed
Copy link

Penghmed commented Sep 7, 2022

No description provided.

@CalMacCQ
Copy link
Collaborator

CalMacCQ commented Sep 7, 2022

Hi,

thank you for your question.

I currently don't think we have a documented example on calculating inner and outer products specifically. This would be a good thing for us to add.

A simple method to calculate the inner product between two states $|\psi>$ and $|\phi>$ is the SWAP test. Here we encode the value of the inner product in the probability of measuring the first qubit to be in the $|1> state. The theory is explained here -> https://en.wikipedia.org/wiki/Swap_test

I have included a screenshot of the circuit below

You can implement this test circuit using the following pytket code

swap_circ = Circuit(3,1) # Create a Circuit with three qubits and one classical bit
swap_circ.H(0)
swap_circ.add_gate(OpType.CSWAP, [0,1,2]) # add controlled swap opeartion
swap_circ.H(0)
swap_circ.Measure(0,0) # Meaure the first qubit to the first classical register

If then append this swap_circ onto the circuit where you prepare your states then you can calculate the inner product bases on the measurement results. If any of this is unclear I'm happy to add more detail.

I can also prepare a small example for the docs

Screenshot 2022-09-07 at 11 44 32

@CalMacCQ
Copy link
Collaborator

CalMacCQ commented Sep 7, 2022

Are there particular examples on the outer product that you would find helpful? It would be good to know more detail about what you are looking for.

@Penghmed
Copy link
Author

Penghmed commented Sep 8, 2022

Yes, I am interested: Φ1=(|00> − i|11>), Φ2=(|01> −|11>) and calculate <Φ1|Φ2> and |Φ1>|Φ2>

Thanks.

@CalMacCQ
Copy link
Collaborator

CalMacCQ commented Sep 13, 2022

Okay the inner product you mentioned can be worked out by hand to be equal to 1*i. This value will change if you normalise the states.

If you want to calculate inner products using circuits then the SWAP test I mentioned generalises for states with more qubits... You just add some extra CSWAP gates between the two registers. In this case the registers q[1] and q[2] will correspond to multi-qubit states.

the |phi1;> |phi2;> term you mentioned is a tensor product. There is some explanation of tensor products here https://www.quantiki.org/wiki/tensor-product.

The outer product of two statevectors is usually written |phi_1><phi_2| and the answer corresponds to a matrix rather than a scalar or a vector. I've included a screenshot of the outer product of your two states below.

Screenshot 2022-09-13 at 11 17 35

I hope this helps - let me know if there is more I can help with.

@CalMacCQ
Copy link
Collaborator

I will close this issue for now - if you have further questions feel free to get in touch again.

You can also ask questions on our public slack channel -> https://tketusers.slack.com/join/shared_invite/zt-18qmsamj9-UqQFVdkRzxnXCcKtcarLRA#/shared-invite/email

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