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

Possible error in mapping states to integers #11

Open
knodelgino opened this issue Jul 29, 2021 · 4 comments
Open

Possible error in mapping states to integers #11

knodelgino opened this issue Jul 29, 2021 · 4 comments

Comments

@knodelgino
Copy link
Contributor

knodelgino commented Jul 29, 2021

When computing fidelities/contrasts, there is a step where we map the states of the computational basis (e.g. '10010101') back to integers using

index_state = int(comp_state, 2)

However, I read in the documentation of Qiskit that the ordering they use for tensor product states is the opposite of most physics textbooks:

When representing the state of a multi-qubit system, the tensor order used in Qiskit is different than that used in most physics textbooks. Suppose there are 𝑛 qubits, and qubit 𝑗 is labeled as 𝑄𝑗. Qiskit uses an ordering in which the 𝑛th qubit is on the left side of the tensor product, so that the basis vectors are labeled as 𝑄𝑛−1⊗⋯⊗𝑄1⊗𝑄0.

For example, if qubit zero is in state 0, qubit 1 is in state 0, and qubit 2 is in state 1, Qiskit would represent this state as |100⟩, whereas many physics textbooks would represent it as |001⟩.

I think this means we might have to change the code to

index_state = int(comp_state[::-1], 2)

I played around with this a little bit in a juptyer notebook, where I tried to explicitly compute the fidelities of some sample states, and found that without this change, a lot of them get swapped around. Reversing the order as above seems to fix the issue.

If what I'm saying is correct, we'd have to make 2 changes:

@knodelgino
Copy link
Contributor Author

@GroenteLepel

@GroenteLepel
Copy link
Owner

Thank you very much for this contribution. I must admit: it has been a while since I have taken a look at this code. I do remember however Qiskit’s reversed order of qubits and having to fiddle around with that.

I appreciate your thoughts on this, and I would suggest you create a merge request of your solution so that I can merge it!

@knodelgino
Copy link
Contributor Author

awesome, I will look into it.

knodelgino added a commit to knodelgino/qiskit-quantum-knn that referenced this issue Sep 11, 2021
@knodelgino
Copy link
Contributor Author

@GroenteLepel created a PR here: #12

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