-
Notifications
You must be signed in to change notification settings - Fork 19
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -312,34 +312,29 @@ def report_iteration(self, x): | |
self._k_counter += 1 | ||
|
||
if self._k_counter == 1: | ||
print( | ||
"\n k iteration Energy dE Ngvec ev Ngm ev* ||g||" | ||
) | ||
print( | ||
"--------------------------------------------------------------------------------------------------" | ||
) | ||
header = "\n k iteration Energy dE" | ||
if self._use_analytic_grad: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looking at |
||
header += " Ngvec ev Ngm ev* ||g||" | ||
header += "\n------------------------------------------------------" | ||
if self._use_analytic_grad: | ||
header += "--------------------------------------------" | ||
print(header) | ||
if self._print_summary_file: | ||
f = open("summary.dat", "w+", buffering=1) | ||
f.write( | ||
"\n# k iteration Energy dE Ngvec ev Ngm ev* ||g||" | ||
) | ||
f.write( | ||
"\n#--------------------------------------------------------------------------------------------------" | ||
) | ||
f.close() | ||
header.replace("\n ", "\n# ").replace("\n-", "\n#--") | ||
with open("summary.dat", "w+", buffering=1) as f: | ||
f.write(header) | ||
|
||
# else: | ||
dE = self._curr_energy - self._prev_energy | ||
print( | ||
f" {self._k_counter:7} {self._curr_energy:+12.10f} {dE:+12.10f} {self._res_vec_evals:4} {self._res_m_evals:6} {self._curr_grad_norm:+12.10f}" | ||
) | ||
update = f" {self._k_counter:7} {self._curr_energy:+12.10f} {dE:+12.10f}" | ||
if self._use_analytic_grad: | ||
update += f" {self._res_vec_evals:4} {self._res_m_evals:6} {self._curr_grad_norm:+12.10f}" | ||
print(update) | ||
|
||
if self._print_summary_file: | ||
f = open("summary.dat", "a", buffering=1) | ||
f.write( | ||
f"\n {self._k_counter:7} {self._curr_energy:+12.12f} {dE:+12.12f} {self._res_vec_evals:4} {self._res_m_evals:6} {self._curr_grad_norm:+12.12f}" | ||
) | ||
f.close() | ||
with open("summary.dat", "a", buffering=1) as f: | ||
update = "\n " + update | ||
f.write(header) | ||
|
||
self._prev_energy = self._curr_energy | ||
|
||
|
There was a problem hiding this comment.
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 onself._use_analytic_grad
.