Bug fix in the C++ simulator: density matrix and probabilities are sometimes erroneous #518
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.