Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove printing that's specific to gradient-based VQE #262

Merged

Conversation

JonathonMisiewicz
Copy link
Contributor

Description

Previously, UCCVQE would print out gradient diagnostics even for computations without a gradient. This is silly, so I removed them.

To clean up the printing, I also tried to unify the to-screen printing and to-file printing. For some reason I don't understand, to-file printing had more digits but not more space for them. There were also some inconsistencies with the amount of whitespace between the two versions. In both cases, I changed them to be more like the to-screen version. The initial # for to-file printing is retained.

User Notes

  • There have been minor changes to output printing for UCCVQE.

Checklist

  • Ready to go!

Copy link
Contributor

@imagoulas imagoulas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have only one suggestion to improve the accuracy of the printing. Other than that, everything looks good to me.

"--------------------------------------------------------------------------------------------------"
)
header = "\n k iteration Energy dE"
if self._use_analytic_grad:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a suggestion for future consideration. The decision to print gradient diagnostics should ideally depend on the type of optimizer being used, whether it is gradient-based or gradient-free. Even when numerical gradients are employed, gradient diagnostics should still be printed. However, scipy.optimize.minimize does not directly expose numerical gradients to the callback function. Therefore, the current decision to report gradient diagnostics for numerical gradients is based on self._use_analytic_grad.

"--------------------------------------------------------------------------------------------------"
)
header = "\n k iteration Energy dE"
if self._use_analytic_grad:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at uccnvqe.py, it appears that a user could potentially request optimizer = "Nelder-Mead" and use_analytic_grad = True. More or less the same applies to adaptvqe.py. To ensure accurate printing of diagnostics, I suggest internally setting self._use_analytic_grad to False if a gradient-free optimizer is selected. Additionally, a warning message could be printed to inform the user of this change.

@JonathonMisiewicz JonathonMisiewicz merged commit 2035e07 into evangelistalab:master May 23, 2024
1 check passed
@JonathonMisiewicz JonathonMisiewicz deleted the print_cleanup branch May 23, 2024 19:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants