Bug fix in the C++ simulator: density matrix and probabilities are sometimes erroneous#518
Merged
Conversation
Member
There was a problem hiding this comment.
Could you add a second comment line here: // We need to subtract the additional shots added by BaseEngine class
chriseclectic
previously approved these changes
May 29, 2018
Member
chriseclectic
left a comment
There was a problem hiding this comment.
@yaelbh thanks for catching and fixing this! It looks like you need to rebase against the master before this can be merged, but the fix looks good to me.
…vector in the presence of optimization, which applies to no-noise circuits where all measurements are located at the end.
Contributor
Author
|
I added a comment requested by Chris and rebased against the master. |
atilag
approved these changes
May 30, 2018
lia-approves
pushed a commit
to edasgupta/qiskit-terra
that referenced
this pull request
Jul 30, 2019
…metimes erroneous (Qiskit#518) * Bug fix in the C++ simulator: wrong density matrix and probabilities vector in the presence of optimization, which applies to no-noise circuits where all measurements are located at the end.
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.
Thanks to Guy Szweigman and Mohammad Heeb, who noticed that the C++ simulator does not always display correct density matrix and probabilities vector.
This happens in the presence of an optimization, which applies to no-noise circuits where all measurements are located at the end. The optimization replaces the shots by a single shot + sampling. However in the calculation of the density matrix and probabilities vector there is a normalization by the number of shots. This results in a density matrix whose trace is 1/(number of shots), and a probabilities vector whose sum is 1/(number of shots).
Description
I fixed the number of shots when the optimization is applied.
Independently of this pull request, it should be revised whether it is correct to normalize by total_shots. Looks like there is an infrastructure to allow, in the future, that total_shots will be the accumulation of number of shots in executions on different engines. What happens if one of the engines does not support density_matrix?
Motivation and Context
How Has This Been Tested?
I updated test_qasm_simulator_cpp.py
Note: test__simulator_online_size in test_quantumprogram fails in the system.
Screenshots (if appropriate):
Types of changes
Checklist:
test__simulator_online_size in test_quantumprogram fails in the system.