Fix bit ordering and probabilities of samples in optimization_algorithm.py#97
Merged
t-imamichi merged 71 commits intoqiskit-community:mainfrom May 13, 2021
Merged
Conversation
t-imamichi
reviewed
Apr 22, 2021
Collaborator
|
We don't need to wait for #96 because CI builds Aer on Ubuntu. |
t-imamichi
reviewed
Apr 23, 2021
t-imamichi
reviewed
Apr 24, 2021
t-imamichi
reviewed
May 7, 2021
Collaborator
|
Could you add bit ordering test of QAOA just in case? |
t-imamichi
reviewed
May 7, 2021
Member
|
Does this in anyway depend on Qiskit/qiskit#6365 ? Since all the unit tests pass here I am guessing not, but that is another reversal of order right? |
Contributor
Author
That's another reversal of order, but actually this does not depend on Qiskit/qiskit#6365. It's simply a bug caused by inconsistency. Currently, |
t-imamichi
previously approved these changes
May 12, 2021
t-imamichi
approved these changes
May 13, 2021
mergify Bot
pushed a commit
that referenced
this pull request
May 13, 2021
…hm.py (#97) * Fix bit ordering of `MinimumEigenOptimizer` with qasm_simulator. * Fix probabilities of solution samples with qasm_simulator. Co-authored-by: Takashi Imamichi <31178928+t-imamichi@users.noreply.github.com> Co-authored-by: Takashi Imamichi <t.imamichi@gmail.com> Co-authored-by: Manoel Marques <manoel.marques@ibm.com> Co-authored-by: Takashi Imamichi <imamichi@jp.ibm.com> (cherry picked from commit 4bce259) # Conflicts: # qiskit_optimization/algorithms/grover_optimizer.py # qiskit_optimization/algorithms/optimization_algorithm.py # test/algorithms/test_grover_optimizer.py # test/algorithms/test_min_eigen_optimizer.py
This was referenced May 13, 2021
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #92
Details and comments
This PR should be merged after #96
Bit ordering
We need to reverse bit ordering from qiskit bit ordering to conventional bit ordering for the actual outputs.
Probabilities of samples
This PR fixes the following lines that calculate the probabilities of solutions.
When
eigenvectoris a dict, we need to square the values since the values are normalized.https://github.com/Qiskit/qiskit-optimization/blob/724158ba42f4b75758edc1de42f6f665660ec27e/qiskit_optimization/algorithms/optimization_algorithm.py#L554-L557
I will explain it in details for the record.
Originally, when we were using Qiskit Aqua, this
eigenvectorwas supposed to be the resultantcountsof a qasm simulator. Thus, the above code was working correctly.https://github.com/Qiskit/qiskit-aqua/blob/aa8bc0c8011405d382fc05d6ab576dd926bdd2a7/qiskit/aqua/algorithms/minimum_eigen_solvers/vqe.py#L578
However, after the code was moved into Qiskit terra, there was some bug and it was fixed in Qiskit/qiskit#5496 .
As a result, this
eigenvectorbecame the square root of the normalized counts, i.e. from{bitstr: counts}to{bitstr: np.sqrt(counts / shots)}.https://github.com/Qiskit/qiskit-terra/blob/3c979ebdacecbbd213757a8149bddc309bfa58c0/qiskit/algorithms/minimum_eigen_solvers/vqe.py#L520
If we change the value of this
eigenvectorin Qiskit terra in the future, we need to change the above code inMinimumEigenSolversas well.