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

SCF: Add SCFConvergence Error #1130

Merged
merged 3 commits into from
Sep 6, 2018
Merged

SCF: Add SCFConvergence Error #1130

merged 3 commits into from
Sep 6, 2018

Conversation

obrien951
Copy link
Contributor

Description

SCF: Add SCFConvergence Error such that the error will have the wavefunction as a member.

Checklist

Status

  • Ready for review
  • Ready for merge

@loriab
Copy link
Member

loriab commented Aug 8, 2018

@CDSherrill

This was the v1.2 behavior so print error msg or die, depending on settings.

Previous scfitertopy behavior was always to throw generic ConvergenceError with msg and niter.

Now, throw SCFConvergenceError with msg, niter, and wfn attached.

@@ -85,6 +85,7 @@ class ConvergenceError(PsiException):
def __init__(self, eqn_description, maxit):
msg = "Could not converge %s in %d iterations." % (eqn_description, maxit)
PsiException.__init__(self, msg)
self.maxit = maxit
Copy link
Member

Choose a reason for hiding this comment

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

Maybe self.iteration or self.iter? This could be thrown under < maxit circumstances. In fact, someday there might be MaxiterExceededSCFConvergenceError, OscillationDetectedSCFConvergenceError, etc.

Copy link
Member

Choose a reason for hiding this comment

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

self.iteration would be a huge help. I would also suggest self.e_convergence and self.d_convergence would be a huge future boon so that it allows users to inspect some of the circumstances of the failure and determine if it passes a "good enough" mark.

Copy link
Member

Choose a reason for hiding this comment

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

self.maxit is the iteration number. You're agreeing to rename the exception member data?

I think e_ and d_convergence can be extracted from the wfn. You're suggesting appending current energy and current rms density to error?

Copy link
Member

Choose a reason for hiding this comment

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

Yes to renaming the member data.

Unless I am missing something it does not appear that you can extract these quantities from the Wavefunction. At the same time I would argue iter/e_conv/d_conv data makes up the current "convergence state" of the wavefunction and should be carried around together so either get all of these variables from the wavefunction or get none.

@loriab
Copy link
Member

loriab commented Aug 8, 2018

@CDSherrill

Oh, and if an error's raised but not caught, it just shows the traceback and triggers coffee:

PsiException: Could not converge SCF iterations in 4 iterations.

  Failed to converge.

Traceback (most recent call last):
  File "stage/usr/local/psi4/bin/psi4", line 269, in <module>
    exec(content)
  File "<string>", line 30, in <module>
  File "/home/psilocaluser/gits/hrw-patch/objdir/stage/usr/local/psi4/lib/psi4/driver/driver.py", line 492, in energy
    wfn = procedures['energy'][lowername](lowername, molecule=molecule, **kwargs)
  File "/home/psilocaluser/gits/hrw-patch/objdir/stage/usr/local/psi4/lib/psi4/driver/procrouting/proc.py", line 2008, in run_scf
    scf_wfn = scf_helper(name, post_scf=False, **kwargs)
  File "/home/psilocaluser/gits/hrw-patch/objdir/stage/usr/local/psi4/lib/psi4/driver/procrouting/proc.py", line 1362, in scf_helper
    e_scf = scf_wfn.compute_energy()
  File "/home/psilocaluser/gits/hrw-patch/objdir/stage/usr/local/psi4/lib/psi4/driver/procrouting/scf_proc/scf_iterator.py", line 93, in scf_compute_energy
    raise e
  File "/home/psilocaluser/gits/hrw-patch/objdir/stage/usr/local/psi4/lib/psi4/driver/procrouting/scf_proc/scf_iterator.py", line 86, in scf_compute_energy
    self.iterations()
  File "/home/psilocaluser/gits/hrw-patch/objdir/stage/usr/local/psi4/lib/psi4/driver/procrouting/scf_proc/scf_iterator.py", line 358, in scf_iterate
    raise ConvergenceError("""SCF iterations""", self.iteration_)

ConvergenceError: Could not converge SCF iterations in 4 iterations.

    Psi4 stopped on: Wednesday, 08 August 2018 05:42PM
    Psi4 wall time for execution: 0:00:01.01

*** Psi4 encountered an error. Buy a developer more coffee!
*** Resources and help at github.com/psi4/psi4.

It looks like die_if_not_converged toggled print-error-msg/die+traceback previously for SCF and DETCI, with defaulting toward print-error-msg. I think it's better to default toward die (which this PR now does) and ppl can catch the error if they want print-error-msg.

For a long time we had geometry optimizations exit smoothly even if failed for iterations exceeded. That caused some problems (I think @dsirianni hit them), so we switched toward the die+traceback. Now SCF will behave like optimizations.

@CDSherrill
Copy link
Member

CDSherrill commented Aug 8, 2018 via email

@loriab loriab added this to the Psi4 1.3 milestone Aug 8, 2018
@@ -85,6 +85,7 @@ class ConvergenceError(PsiException):
def __init__(self, eqn_description, maxit):
msg = "Could not converge %s in %d iterations." % (eqn_description, maxit)
PsiException.__init__(self, msg)
self.maxit = maxit
Copy link
Member

Choose a reason for hiding this comment

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

self.iteration would be a huge help. I would also suggest self.e_convergence and self.d_convergence would be a huge future boon so that it allows users to inspect some of the circumstances of the failure and determine if it passes a "good enough" mark.

class SCFConvergenceError(ConvergenceError):
"""Error called for problems with SCF iterations."""

def __init__(self, eqn_description, maxit, wfn):
Copy link
Member

Choose a reason for hiding this comment

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

I would try to put more important args first. So something more like:
def __init__(self, wfn, wfn_name, maxiter, e_conv, d_conv):

@@ -85,6 +85,7 @@ class ConvergenceError(PsiException):
def __init__(self, eqn_description, maxit):
msg = "Could not converge %s in %d iterations." % (eqn_description, maxit)
PsiException.__init__(self, msg)
self.maxit = maxit
Copy link
Member

Choose a reason for hiding this comment

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

Yes to renaming the member data.

Unless I am missing something it does not appear that you can extract these quantities from the Wavefunction. At the same time I would argue iter/e_conv/d_conv data makes up the current "convergence state" of the wavefunction and should be carried around together so either get all of these variables from the wavefunction or get none.

except ConvergenceError:
raise ConvergenceError("""SCF DF preiterations""", self.iteration_)
except SCFConvergenceError:
raise SCFConvergenceError("""SCF DF preiterations""", self.iteration_, self)
Copy link
Member

Choose a reason for hiding this comment

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

Looking through the code we probably need to call scf_finalize_energy here. There are many variables set in the scf_finalize_energy/scf_print_energies functions which we should probably change at some point (or just rename the functions).

@loriab
Copy link
Member

loriab commented Aug 22, 2018

ok, various issues have been addressed during the Sherrill Group programming exercise. Ready for re-review.

Copy link
Member

@dgasmith dgasmith left a comment

Choose a reason for hiding this comment

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

LGTM

@loriab loriab merged commit f7c1a59 into psi4:master Sep 6, 2018
@dgasmith dgasmith mentioned this pull request Dec 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants