Psi4 Optking logging to chosen output files

Hi all,

I am using psi4 with the separate optking conda package on my universities HPC which uses the slurm scheduler. Essentially I am running multiple geometry optimisations as part of a larger project which uses the python logging module with multiple log_level INFO calls. This was not an issue when I was using the in-built psi4 optking optimiser as I had it set to output to an output file for each individual optimisation calculation using psi4.core.set_output_file but having switched to the optking module it now has multiple additional log.INFO calls including one that prints the Hessian matrix. This results in my slurm output files becoming quite unreadable for the debugging and development I am currently doing for the project.

Is there a way to either suppress all Logging from Optking or preferably have it behave the same way as the psi4 version and have the information write to the chosen individual output files instead of the slurm main output?

Psi4 version = 1.6
Optking version = 0.2.0

We’re working on integrating psi4 and optking right now so some behaviors are a little off right now.

It sounds to me like the issue is just that you don’t want optking’s logs to propagate. I would recommend changing optking/ (starting on line 12) from

        logger = logging.getLogger()
        logger = logging.getLogger(__name__)
        log_name = ""


        logger = logging.getLogger()
        logger = logging.getLogger(__name__)
        logger.propagate = False
        log_name = ""

This should allow optking to keep logging while not cluttering your pre-existing logger.


If you just want to silence the logger altogether you would want to edit and change the optking logger’s level to CRITICAL For future readers: with psi4 1.7 optking’s logging level is inherited from psi4’s logger and so running with --log-level 30 would be recommended. This won’t eliminate all logging but should remove almost everything.

Manual output capture

Note: psi4 will take care out capturing output from optking in 1.7
If you want optking write to psi4’s output file. This can be done, as of right now, by printing a string summary from the CustomHelper with psi4.core.print_out(). You would want to run your optimizations like.

def test_stepwise_export():
    import psi4
    h2o = psi4.geometry(
        H 1 1.0
        H 1 1.0 2 104.5
    psi4_options = { 
        "diis": False,
        "basis": "sto-3g",
        "e_convergence": 10, 
        "d_convergence": 10, 
        "scf_type": "pk",
    opt = optking.CustomHelper(h2o)
    for _ in range(10):
        grad, wfn = psi4.gradient("hf", return_wfn=True)
        opt.gX =
        opt.E =
        conv = opt.test_convergence()
        if conv is True:
            print("Optimization SUCCESS:")
            optSaved = opt.to_dict()
          geom = psi4.core.Matrix.from_array(opt.molsys.geom)
          print("Optimization FAILURE:\n")
      # print(opt.history.summary_string())
      json_output = opt.close()
      E = json_output["energies"][-1]  # TEST

This is from tests/ with some edits.

Please lemme know if one of these solutions works for your use case or if you have further questions.

Thank you for the reply, adding the logger.propagate = False line has worked nicely for the time being. If you can comment is there a timeline for 1.7 release as from what you’ve said that looks to be the ideal solution for me.

1.7 is a target for early December '22 (next month).