Psi4.optimize() do not finished properly when the calculation is ended by geom_maxiter

Hello, I try to make automated script for geometry optimization.
And I found that if some calculation is not converged and reach the geom_maxiter, then following calculation is ‘continued’ from failed calculation.
And ‘continued’ calculation is also fail to optimize structure.

Here is the sample code of my problem.

import psi4
import sys

with open(sys.argv[1]) as fil:
    xyz = fil.read()

for i in range(3):
    psi4.set_memory('4 GB')
    psi4.core.set_num_threads(16)
    psi4.set_options({
        'basis': '6-31gs',
        'geom_maxiter': 2,
    })

    mymol = psi4.core.Molecule.from_string(xyz, dtype='xyz')

    psi4.core.set_output_file(f'res_{i+1}.dat', False)

    try:
        psi4.optimize('b3lyp', molecule=mymol)
    except:
        pass

    mymol.save_xyz_file(f'res_{i+1}.xyz', False)

    psi4.core.clean()
    psi4.core.clean_variables()
    psi4.core.clean_options()
    psi4.core.clean_timers()
    psi4.core.opt_clean()

Then, the result of res_2.dat and res_3.dat is like below

# res_2.dat
# $ grep 'Convergence Criteria' res_2.dat -A 2 --no-group-separator | awk 'NR % 3 ==0'
      3   -1560.20297072    3.21e-02      4.03e-02      6.96e-03 o    1.65e-01      2.97e-02 o  ~
      4   -1560.23588741   -3.29e-02      1.09e-02      2.14e-03 o    2.06e-01      3.70e-02 o  ~

# res_3.dat
# $ grep 'Convergence Criteria' res_3.dat -A 2 --no-group-separator | awk 'NR % 3 ==0'
      5   -1560.20297072    3.29e-02      4.03e-02      6.96e-03 o    1.64e-01      2.97e-02 o  ~
      6   -1560.23600632   -3.30e-02      1.08e-02      2.11e-03 o    1.96e-01      3.66e-02 o  ~

I’'ve tested clean functions like the sample code above but nothing is work.
Since the optimize function in psi4 sometimes fail to find optimized structure, this problem is critical for automated script.
Does anyone have a solution for this problem?

Either switch to the soon-to-be-default GitHub - psi-rking/optking: optking: A Python version of the PSI4 geometry optimization program by R.A. King
or try optimize(..., engine='geometric') Geometry Optimization

Not sure I understand the issue about the next optimization being ‘continued’. Could you expand?
Or what is the loop trying to solve?

What I expect is like below

# calculation 1 (failed)
iteration 1
iteration 2
...
iteration geom_max

# calculation 2
iteration 1
iteration 2
...

But in current version of psi4, the result is…

# calculation 1 (failed)
iteration 1
iteration 2
...
iteration geom_max

# calculation 2
iteration geom_max+1
iteration geom_max+2
...

In the code block above, ‘calculation’ means psi4.optimize() in the loop (in the code block of first mention)
Intuitively, I think individual call of psi4.optimize() should be individual calculation.
But in psi4, there are some remaining information (or file) for failed optimization and automatically continue the failed calculation when I call next psi4.optimize().

I’m pinging the optimization experts (@Rollin_King and @AlexanderH) just in case, but I suspect this is a bug in Optking. As we are almost finished rewriting this part of the code, I don’t think it’s worth development time to fix this.