Adds observable evaluator with primitives.#8683
Conversation
|
Thank you for opening a new pull request. Before your PR can be merged it will first need to pass continuous integration tests and be reviewed. Sometimes the review process can be slow, so please be patient. While you're waiting, please feel free to review other open PRs. While only a subset of people are authorized to approve pull requests for merging, everyone is encouraged to review open pull requests. Doing reviews helps reduce the burden on the core team and helps make the project's code better for everyone. One or more of the the following people are requested to review this:
|
Pull Request Test Coverage Report for Build 3062532045
💛 - Coveralls |
Cryoris
left a comment
There was a problem hiding this comment.
Some comments below otherwise LGTM 👍🏼 now we just need to convince @woodsp-ibm that we need this 😉
It seems fine - the Dict and List processing to handle None is beyond what the Estimator can handle to the data needs to be mapped in/out and this does that as a common function the algos can use. Since the Estimator reports variance back, I am wondering whether we should just pass variance on back from here too, when its available. I am not sure about shots being present always to do the conversion and if using Estimator directly I get variance why not also when running an algo that uses it...
From the main description. While None was used in the lists to preserve order if an operator became invalid as part of transformation down through the stack, 0 is not a valid value. What you might mean by that is empty/zero operator i.e. a valid instance, a zero operator. I would hope Estimator handles that - I know with opflow additional work was done to select these out - which we did back in Aqua days too since the expectation is 0. I do not know what Estimator does. |
|
Any thought on this aspect from above
|
ElePT
left a comment
There was a problem hiding this comment.
I found these small details while reviewing the PVQD PR, and thought it would make more sense to suggest here the changes. Otherwise, I'm using this code on my PR and it looks good to me :)
7b75638 to
2bcf07b
Compare
Hello, I have been wondering about it myself. The primitive natively records a variance. I was thinking that if variance is present, shots should always be present, too. Any thoughts on that @t-imamichi? I am fine either way. |
I was not aware of algorithms using it as such, VQE/VQD/QAOAetc. They did return it as part of their result for anyone to use should they wish, that's the extent of the use I knew, where the aux ops evaluation was a value, std_dev tuple for each. |
Yes, none of these 3 algorithms does actually use these stdevs, they just return them as part of the aux_ops evaluation result. So I think that variance and shots could be returned without much hassle. We would only have to change one type hint in the base class, and the docstring of the |
|
As for std_dev, there is a PR #8105 to extend |
|
Do we want to handle cases where users pass in an empty list or dict for |
Good point! I just fixed 1 line to handle empty inputs such that empty outputs are returned with no error! Added unit tests for that. |
… observable-eval-primitives
* Added observables_evaluator.py with primitives. * Added ListOrDict support to observables_evaluator.py. * Included CR suggestions. * Applied some CR comments. * Added reno. * Support for 0 operator. * Add pending deprecation * Code refactoring. * Code refactoring. * Improved reno. * Returning variances and shots. * Unit test fix. * Reduced use of opflow. * Handle empty inputs gracefully. * Applied CR comments. * Applied CR comments. * Eliminated cyclic import. Co-authored-by: Manoel Marques <manoel.marques@ibm.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
* Added observables_evaluator.py with primitives. * Added ListOrDict support to observables_evaluator.py. * Included CR suggestions. * Applied some CR comments. * Added reno. * Support for 0 operator. * Add pending deprecation * Code refactoring. * Code refactoring. * Improved reno. * Returning variances and shots. * Unit test fix. * Reduced use of opflow. * Handle empty inputs gracefully. * Applied CR comments. * Applied CR comments. * Eliminated cyclic import. Co-authored-by: Manoel Marques <manoel.marques@ibm.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Summary
This PR adds an observable evaluator that uses the Estimator primitive. It will be used by several primitives-enabled algorithms. It replaces the aux_ops_evaulator.py.
0passed in as operators.Closes: #8505
Details and comments