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.
This is sort of a follow-up on #288, I misunderstood the functions, the fix there was wrong (as was the original function).
If I understand correctly, the example in the docstring
means that we measure the expectation value of
X x Y x Z x Itensor product and then ofX x Y x Z x I(i.e. the same state).We expect this to return
[batch_size, len(obs_list)]and not[batch_size, len(obs_list), num_wires], you cannot get anything separated by wires from here, the expectation value of the tensor product is just a real number, thusexpval_joint_analyticalis needed here. I have removed the prod fromMeasureMultiQubitPauliSum.I have added a test in test/measurements/ to make sure that the analytical result is recovered, please check for yourself.
In fact, I don't really see any use case for
expvalas implemented here. IMO it should be renamed toexpval_per_wireand it should be made explicit that the observables are looped over and the i-th return value is the expectation value of the i-th observable w.r.t. to the i-th wire (with the rest traced out). What is the use case for this over just expval_joint_analytical?Further, I have removed MeasureMultiPauliSum, it passes
obs_listtoMeasureMultipleTimesbutMeasureMultipleTimesdoes not take into account thecoefficiententry that is specified inMeasureMultiPauliSum. Thus,MeasureMultiPauliSumwill not fail (since it is a correct dict with too many keys) but also not return the correct value. Since I have no interest in implementing this correctly, I would remove. You can check that the coefficient entry has no effect by changing the coefficients in the pauli_sum_op.py example file. I have changed this file to useMeasureMultiQubitPauliSuminstead (and also removed the empty example in this directory).