vibeqc.ProgressLogger¶
- class vibeqc.ProgressLogger(stream=None, log_path=None, verbose=4, use_logging=False)[source]¶
Bases:
objectPer-stage progress emitter for long-running calculations.
Writes plain-ASCII, line-flushed output to
stream(defaultsys.stdout) and, optionally, tolog_path(truncated on construction, appended-and-flushed thereafter). Every write goes throughflush()immediately sotail -fagainst a redirected stdout shows the run unfolding in real time.- Parameters:
stream (Optional[IO[str]]) – Where to write live progress. Default
sys.stdout. Ignored whenuse_logging=True.log_path (Optional[Union[str, os.PathLike]]) – Optional path. Truncated on construction; appended-to with a flush after each write. Useful when callers want both an interactive stdout view and a persistent on-disk record. Honored regardless of
use_logging.verbose (Union[int, bool, None]) – Integer verbosity level (0..9, default 4). Higher values add more detail; level 0 makes every method a no-op. The level table is in the module docstring.
True/Falseare accepted for back-compat (True→ 4,False→ 0).use_logging (bool) – If
True, route emits throughlogging.getLogger( "vibeqc.run_job")instead of the stream. Composes with stdlib handlers (rotating files, syslog, dictConfig) — no special integration required. Thelog_pathtee still applies if set.
Notes
The current implementation deliberately stays plain ASCII — the goal is the
nohup+tail -fworkflow, where color codes would only inject control bytes that no log viewer asked for. TTY detection is exposed viais_ttyfor downstream tooling that wants to layer color or progress bars on top.Methods
__init__([stream, log_path, verbose, ...])banner(title)Section banner: blank line + indented title + dashed rule.
converged(*, n_iter, energy, converged)Final SCF status line; called once after the iteration loop.
debug(message)Phase-level wall-clock breakdown / debug detail.
info(message)Emit a one-line informational message, indented.
iteration(n, **fields)One SCF iteration line.
memory(label, rss_mib)Inline RSS-memory snapshot.
stage(name, *[, detail])Context manager: emit
[name]on enter,[name] done (X.XXs)on exit — regardless of which branch ran inside.warn(message)Emit a one-line warning, prefixed with
WARN:.write_raw(text)Write
textexactly as given (newlines preserved), with a single flush.Attributes
Trueifflevelis non-zero (i.e. anything emits).Whether the underlying stream is a TTY.
The integer verbosity level this logger was constructed with (0..9).
Whether emits route through
logging(True) or the raw stream (False).- info(message)[source]¶
Emit a one-line informational message, indented.
Visible at verbose level 2 and above.
- Parameters:
message (str)
- Return type:
None
- warn(message)[source]¶
Emit a one-line warning, prefixed with
WARN:.Visible at verbose level 1 and above (warnings should not be hidden by quiet runs short of full silence).
- Parameters:
message (str)
- Return type:
None
- banner(title)[source]¶
Section banner: blank line + indented title + dashed rule.
Visible at verbose level 1 and above. Under
use_loggingthe three lines emit as three INFO records.- Parameters:
title (str)
- Return type:
None
- write_raw(text)[source]¶
Write
textexactly as given (newlines preserved), with a single flush. Used by callers that want to splice in a pre-formatted block (e.g. the geometry table fromvibeqc.scf_log).Visible at verbose level 2 and above.
- Parameters:
text (str)
- Return type:
None
- stage(name, *, detail=None)[source]¶
Context manager: emit
[name]on enter,[name] done (X.XXs)on exit — regardless of which branch ran inside.The start line emits at verbose level 2; the timing
doneline emits at level 3 (soverbose=2shows which stages ran but suppresses per-stage wall-time noise, andverbose>=3adds the timing detail).
- iteration(n, **fields)[source]¶
One SCF iteration line.
Recognized fields:
energy(Ha),dE(Ha),grad(||[F,DS]||),diis(subspace dim). Any other key/value pair is appended at the end. Wall time since logger construction is appended automatically.At
n == 1,dEis rendered as a placeholder--so the column layout matchesvibeqc.scf_log.format_scf_trace().Visible at verbose level 4 and above. Under
use_loggingemits atDEBUG(per-iter detail belongs below INFO sologging.basicConfig(level=INFO)keeps a quiet stream whilelevel=DEBUGexposes the trace).
- converged(*, n_iter, energy, converged)[source]¶
Final SCF status line; called once after the iteration loop.
Visible at verbose level 1 and above (the final summary is almost always wanted — only a fully silent
verbose=0suppresses it).
- memory(label, rss_mib)[source]¶
Inline RSS-memory snapshot.
Visible at verbose level 5 and above. Pairs with the post-mortem
.perflog’sMemory snapshotssection — same data, but live.
- debug(message)[source]¶
Phase-level wall-clock breakdown / debug detail.
Visible at verbose level 6 and above. Overlaps the post-mortem
.perflog on purpose — the perf log shows the same numbers when the run is over;verbose>=6streams them live for users debugging an in-flight job. Underuse_loggingemits atDEBUGso a stdlibRotatingFileHandlerset toDEBUGcaptures the trace without lifting the bar for INFO-only handlers.- Parameters:
message (str)
- Return type:
None