GroenteLepel / qiskit-quantum-knn

A pure quantum knn classifier for a gated quantum computer.
Apache License 2.0
22 stars 8 forks source link

Update qkneighborsclassifier.py #12

Closed knodelgino closed 2 years ago

knodelgino commented 3 years ago

Related to: https://github.com/GroenteLepel/qiskit-quantum-knn/issues/11

When mapping back the computational state to an index, we need to flip the order, since Qiskit uses a somewhat unconvential reverse ordering of tensor product states.

From their documentation:

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⟩.
knodelgino commented 3 years ago

@GroenteLepel do you mind having a look at this?

GroenteLepel commented 2 years ago

Sorry for the delay and thanks for the reminder. It is approved!

GroenteLepel commented 2 years ago

From the fidelity calculation in the tests something went wrong with this adjustment. Either the tests need to be adjusted so that they comply with this change, or something further down the line must be adjusted to work with this change.