lumopt2.utils.file_logger#

Callbacks that record per-run numerical results of an optimization.

The callbacks defined here are deliberately separate from – and orthogonal to – the lumopt2 module logger. The module logger is for human-readable progress messages (“Starting optimization”, “Iteration 3: FOM = …”) and is the right place to track what is happening. The callbacks here record the numerical artefacts of a run – the parameter vectors used at each evaluation, the gradients computed, the FOM trajectory, the elapsed wall time per eval – so a user can plot, replay, or debug the run after the fact. This data is typically dense, machine-readable, and not something you want flooding the console or your general lumopt2 log file.

In short:

  • logging.getLogger("lumopt2")what is happening (progress).

  • FileLogger / JSONLoggerwhat numbers came out (data record).

The two streams can be enabled, disabled, and consumed independently.

This module provides two BaseCallback implementations:

FileLogger

Writes a plain-text record of one optimization run, with one line per evaluation and per iteration containing the FOM, parameter values, and optionally the gradient. Designed to be diff’d, grep’d, or loaded into a quick plotting script. By default the file is dropped into the project folder as optimization.log.

JSONLogger

Writes a structured JSON history of the run – the same data FileLogger records, but in a format that is straightforward to load programmatically for benchmarking, comparison, or post-hoc analysis. Also produces a _eexit_history.json sidecar when the run terminates early so partial results survive crashes.

Both callbacks tolerate being constructed before the project folder is known – the actual output path is resolved during on_optimization_start.

Classes#

FileLogger([log_file, log_params, ...])

Record the numerical history of one optimization run to a text file.

JSONLogger([problem_name, optimizer_name, ...])

Record the structured numerical history of an optimization run as JSON.