Skip to content

propSAPT logs through Python's logging; one handler writes into Psi4's output file - #13

Merged
btyrcha merged 7 commits into
mainfrom
feature/logging
Nov 22, 2026
Merged

btyrcha merged 7 commits into
mainfrom
feature/logging

Conversation

@btyrcha

@btyrcha btyrcha commented Nov 19, 2026

Copy link
Copy Markdown
Owner
  • Logging. New prop_sapt/log.py: the prop_sapt logger, at INFO by default, and Psi4OutputHandler, which writes its records into Psi4's output file, putting the level before warnings and errors ("Warning: ..."). It is the only code left that calls psi4.core.print_out. Every module logs through logging.getLogger(__name__), so the standard logging calls quiet or redirect all of propSAPT's output or one module's, e.g. the CPSCF iteration tables (prop_sapt.cpscf_solver).
  • Messages. Messages no longer start or end with newlines, so the output file has fewer blank lines. Tables (CPSCF, SAPT summary, finite-field banners, cube timings) are one record each; the SAPT summary keeps its layout through a new format_energy helper, and energy_printer keeps its API.
  • Warnings. The warnings of the checks, the CPSCF solver and the deprecations, and a missing GRAC shift, are WARNING records next to their Python warnings.
  • Cube progress. The progress of make_cube over the x-slices, a line rewritten with \r in the output file, is a DEBUG record per slice.
  • Scratch cleanup. The 36 psi4.core.clean() calls just before a raise are removed: Psi4 cleans its scratch files at exit, and calc_sapt_energy, calc_property and the runner still clean at the end of a job.
  • Docs. An "Output and logging" section in the usage guide, prop_sapt.log in the API reference, and a changelog entry.

Out of scope: Psi4's own tstart/tstop, BasisSet.print_out(), Molecule.print_out_in_angstrom(), be_quiet in the CLI and the 3 end-of-job clean() calls. These are Psi4 calls that a backend will make.

Tested: new tests of the logger and handler (records in Psi4's output file, levels, a reload keeping one handler, caplog capturing the CPSCF table and an unconverged-solve warning), and source scans that only prop_sapt.log writes to Psi4's output and that clean() is called only at the ends of jobs. The finite-field banner test reads the log record. The full suite passes locally, and the docs build with -W. A He–H2 run (aug-cc-pVDZ) covering the SAPT energy, dipole, densities, a cube, finite field and an RKS dimer gives the same results as main within run-to-run round-off. Its output differs only in the dropped blank lines, the GRAC warning and the cube progress line.

🤖 Generated with Claude Code

https://claude.ai/code/session_019ZeFQEY3P12DGTNcvWEyhT

btyrcha and others added 7 commits November 19, 2026 18:08
…s output file

prop_sapt.log sets up the `prop_sapt` logger: INFO and above, written into Psi4's output
file by Psi4OutputHandler, warnings and errors after their level. Module loggers are its
children, so the standard logging calls quiet or redirect propSAPT's output. The package
imports it first, and a reload keeps one handler.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019ZeFQEY3P12DGTNcvWEyhT
…_out

Dimer and helper_SAPT, the SAPT driver, the densities, the CPSCF solver and batching,
S^inf, the checks, the basis overrides and the timers log through
logging.getLogger(__name__). Messages have no blank lines around them, and multi-line
tables are one record. The warnings of the checks, the CPSCF solver, the deprecations
and a missing GRAC shift are WARNING records next to their Python warnings. Modules that
no longer use Psi4 stop importing it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019ZeFQEY3P12DGTNcvWEyhT
The cube setup, timings and isocontours and the finite-field banners and steps are
INFO records. The progress of make_cube over the x-slices, a line rewritten with \r in
Psi4's output file, is a DEBUG record per slice. A test checks that only prop_sapt.log
writes into Psi4's output file.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019ZeFQEY3P12DGTNcvWEyhT
The 36 psi4.core.clean() calls before a raise go: Psi4 cleans its scratch files at
exit and between jobs, which calc_sapt_energy, calc_property and the runner still do.
calc_property checks the response without a try/except, and the densities module no
longer imports Psi4. A test checks that clean is called only at the ends of jobs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019ZeFQEY3P12DGTNcvWEyhT
…n sections

print_sapt_summary builds the table from format_energy, the line energy_printer
writes, and logs it at once, so the table keeps the layout it had in Psi4's output file.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019ZeFQEY3P12DGTNcvWEyhT
The usage guide's Output and logging section shows how to quiet or redirect propSAPT's
output, the API reference lists prop_sapt.log, and the changelog says the output goes
through logging, still into Psi4's output file.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019ZeFQEY3P12DGTNcvWEyhT
The banner is one INFO record now, so the test reads it with caplog: its logger, level,
title and formatted details.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019ZeFQEY3P12DGTNcvWEyhT
@btyrcha
btyrcha merged commit 91c3973 into main Nov 22, 2026
4 checks passed
@btyrcha
btyrcha deleted the feature/logging branch November 22, 2026 17:36
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.

1 participant