qiskit icon indicating copy to clipboard operation
qiskit copied to clipboard

Allow access to UDMA optimizer history information

Open VicentePerezSoloviev opened this issue 1 year ago • 8 comments

Summary

Fixes #8687

Details and comments

The user need to have access to the attribute history that is private in minimize function so it has been made an attribute of the class and implemented a getter to be used by the user.

VicentePerezSoloviev avatar Sep 07 '22 07:09 VicentePerezSoloviev

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:

  • @Qiskit/terra-core
  • @manoelmarques
  • @woodsp-ibm

qiskit-bot avatar Sep 07 '22 07:09 qiskit-bot

I'm not sure this is the right approach, as we try to keep the classes stateless as much as possible (at least to the user). A better solution could be to extend the OptimizerResult object for UMDA and add a history field?

Cryoris avatar Sep 07 '22 08:09 Cryoris

Pull Request Test Coverage Report for Build 3158042120

  • 4 of 5 (80.0%) changed or added relevant lines in 1 file are covered.
  • 1038 unchanged lines in 112 files lost coverage.
  • Overall coverage increased (+0.3%) to 84.585%

Changes Missing Coverage Covered Lines Changed/Added Lines %
qiskit/algorithms/optimizers/umda.py 4 5 80.0%
<!-- Total: 4 5
Files with Coverage Reduction New Missed Lines %
qiskit/algorithms/amplitude_amplifiers/amplitude_amplifier.py 1 95.83%
qiskit/algorithms/eigen_solvers/eigen_solver.py 1 97.67%
qiskit/algorithms/evolvers/real_evolver.py 1 91.67%
qiskit/algorithms/gradients/finite_diff_sampler_gradient.py 1 95.56%
qiskit/algorithms/gradients/lin_comb_estimator_gradient.py 1 96.83%
qiskit/algorithms/gradients/lin_comb_sampler_gradient.py 1 96.72%
qiskit/algorithms/gradients/param_shift_estimator_gradient.py 1 95.74%
qiskit/algorithms/gradients/param_shift_sampler_gradient.py 1 95.83%
qiskit/algorithms/gradients/spsa_estimator_gradient.py 1 95.74%
qiskit/algorithms/gradients/spsa_sampler_gradient.py 1 96.15%
<!-- Total: 1038
Totals Coverage Status
Change from base Build 3004414337: 0.3%
Covered Lines: 61378
Relevant Lines: 72564

💛 - Coveralls

coveralls avatar Sep 07 '22 08:09 coveralls

@Cryoris I do not think this makes the class to be less stateless. Actually, this code was implemented by me a few months ago, and the original implementation had this attribute accesible as public. This is very useful for a correct hyperparameter tunning, and is implemented through a public method. In my opinion this is a correct way of fixing the issue, but if you do not think so, I can look for another option of doing this.

VicentePerezSoloviev avatar Sep 07 '22 08:09 VicentePerezSoloviev

We had a discussion when you first created the optimizer on history - you will see pretty much the same is being said now as then https://github.com/Qiskit/qiskit-terra/pull/8084#discussion_r900439353

Maybe having the history passed across as part of a callback. I don't think UDMA has a callback to monitor the optimizer progress and potentially stop it like the scipy ones have right. That might be another thought.

woodsp-ibm avatar Sep 07 '22 21:09 woodsp-ibm

Regarding to extending the class of Result to a specific one for UMDA, how the user will be able to access this object? As I can see in vqe.py the information of OptimizerResult is moved to VQEResult object. So user will no further have access to OptimizerResult isn`t it? The same will happen if I extend OptimizerResult to a specific class for UMDA. Is there a way the user can access it? Thanks

VicentePerezSoloviev avatar Sep 20 '22 10:09 VicentePerezSoloviev

An option could be having the extension of the OptimizerResult as an attribute of UMDA. Would this be right?

VicentePerezSoloviev avatar Sep 20 '22 11:09 VicentePerezSoloviev

Then maybe as I suggested earlier, as an alternative, defining a callback that the user can provide which allows the values to be monitored as the optimizer is running. A user can do with that information whatever they will eg. just store it for later analysis.

woodsp-ibm avatar Sep 22 '22 18:09 woodsp-ibm

Finally I have decided to implement the callback function that @woodsp-ibm has proposed. The callback function receives the solutions evaluations, the parameters, and the best cost per iteration

VicentePerezSoloviev avatar Sep 30 '22 09:09 VicentePerezSoloviev

The code is ready to be reviewed. Thanks

VicentePerezSoloviev avatar Oct 04 '22 13:10 VicentePerezSoloviev

The code is ready to be reviewed.

Thanks,. I'll try and get to it soon, things have been extremely busy with the imminent release.

woodsp-ibm avatar Oct 04 '22 16:10 woodsp-ibm