Logging

POMMES writes nothing and configures nothing on import. Warnings and errors reach the standard error as they are, with no setup. To follow a run, add one line at the top of a script or a notebook:

import pommes

pommes.configure_logging()

A Benders run then reads as follows. The iteration table is the progress of the run, so it stays readable in a file or in the log of a Slurm job:

Inputs    27 files, 90 parameters, 2 area x 4 year_op x 10 hour        0.8 s
Checks    111 parameters after the defaults                            0.0 s
Analysis  0 infeasible, 0 warning, 1 info                              0.3 s
Benders   highs, n_jobs=2, level-interior, tol=1e-04, max_iter=30
Build     master and 4 subproblems                                    15.2 s
  iter      lower      upper      gap infeas  master   level    subs    cuts   total
     0          0        inf        -      4     0.0     0.0     0.1     0.0     0.1
     1       4680        inf        -      4     0.0     0.0     0.1     0.0     0.1
     2  1.073e+04  3.586e+09     100%      0     0.0     0.0     0.1     0.1     0.2
WARNING   Stopped at max_iter=30 with gap 8.688e-02 above tol=1.000e-04: the
          result is the best plan found, not an optimum. Raise max_iter.
Benders   max_iter after 30 iterations                                17.9 s
          master 9 % | level 10 % | subproblems 45 % | cuts 35 %
          2 negligible cut coefficients cleaned, 22 cuts of range above 1e+09

Options

pommes.configure_logging(
    "debug",                        # or "info", "warning", "error"
    file="results/run.jsonl",       # events, as JSON Lines
    solver_logs="results/solver/",  # logs of the solvers
    console=True,
)

A later call replaces the previous one. The environment variable POMMES_LOG_LEVEL gives the level when the code does not. When set, it also turns the display on at import pommes, for a job whose script should not change:

POMMES_LOG_LEVEL=info sbatch job.sh

The usual tools of logging still work. For instance, to see the detail of the solver module only:

import logging

logging.getLogger("pommes.solver").setLevel(logging.DEBUG)

What each level means

ERROR

A result is missing or does not hold, for instance a certain infeasibility found by pommes.pre_analysis().

WARNING

The reading of a result changes, or something is expected of you, for instance a Benders run that stopped before closing its gap. Each cause is reported once, not at every iteration.

INFO

A stage of the computation, in one line with its size and duration, and one line per Benders iteration.

DEBUG

The detail of a stage: a file, a parameter, a subproblem, a recovery of a solver. The end of a Benders run counts the recoveries at INFO, also when the run raises.

Events

The file of pommes.configure_logging() receives one JSON object per record, written as soon as it is logged. The file of a job killed by a time limit therefore keeps every iteration up to the one in progress, which BendersResult.history would not. A run that raises still ends with benders.done, its status being failed or no_incumbent. To follow a job:

tail -f results/run.jsonl | jq -c 'select(.event == "benders.iteration") | .data.gap'

Every line carries ts, level, logger, run_id, event, message and data. In data, an infinite value is written "inf" or "-inf" and a NaN null, as strict JSON has neither. Event names and their data are an interface; the wording of the messages is not, and may change.

Event

Data

run.start

Versions of pommes and Python

inputs.built, model.built

Sizes, and seconds

inputs.checked, results.saved

seconds

pre_analysis.finding, pre_analysis.done

A finding; the count of findings by severity

benders.start

Solver and its version, options of the run

benders.built

Number of subproblems, seconds

benders.iteration

A row of BendersResult.history

benders.done

Status, bounds, time per step, and what was counted during the run

solver.start, solver.presolve, solver.progress, solver.done

The report on a solve, see below: every field of pommes.solver.progress.SolverProgress

Logs of the solvers

Solvers have their own logs, which stay out of the log of POMMES. With solver_logs, the directory receives master.log for the Benders master, and one file for each subproblem that needed the robust solve of its recovery ladder. A run appends to them. This covers the persistent backends: with persistent=False, or a solver without one, there is no solver log. A log that cannot be written is a warning, and the solve goes on.

Two limits with COPT 8.0.7: it writes to the console as well as to its file when solver_logs is set, and a solve through linopy, such as the final report of a Benders run, shows COPT’s banner.

Report on a running solver

Every solver has a log format of its own. POMMES reads it while the solver runs and says where the solve stands, in the same words for every solver:

Solver    HiGHS 1.15.1, interior point, 720408 rows, 660330 cols
Presolve  rows -42%, cols -45%, nonzeros -34%
     time phase                     iter  objective primal inf   dual inf        gap
     2:03 interior point              13   1.08e+05   6.50e-07   1.27e-05   1.18e+00
     4:03 interior point              27   8.00e+04   4.39e-08   2.75e-06   7.90e-01
     6:03 interior point              49   5.03e+04   1.07e-11   9.85e-10   3.10e-02
Solved    optimal, 7:47

The console shows a table, with - where the log gives no value. A file, or a handler of the application, gets the same values as a labelled sentence.

A monolithic solve gets it through pommes.solve_model(), which takes the arguments of linopy.Model.solve:

pommes.configure_logging(solver_progress_interval=2)  # minutes, 5 by default
status, condition = pommes.solve_model(model, "highs")

The log of the solver goes to log_fn, to model.log in solver_logs, or to a temporary file, and stays off the console. The file holds the last solve only. A Benders master gets the same report when one of its solves lasts longer than the interval, and nothing otherwise. The subproblems have no report: the iteration table speaks for them.

solver_progress_interval=None turns the report off. An application that configures logging itself asks for it with pommes.logs.set_solver_progress_interval().

A row comes every interval even if the log says nothing, which is when it matters most: no log line for 12:30, after its last column, is a presolve, a factorization or a crossover at work. The report never stops a solve: a line that is not recognized is skipped, a field that the log does not give stays empty rather than estimated, and a report that cannot start, for want of a thread or of a temporary file, leaves the solve to run without it. When a solver works on the dual, the presolve says dualized instead of a count of rows, as those of the dual do not compare with those of the model.

What the logs give, on the versions tried

Solver

Limits

HiGHS 1.15

The simplex has no gap

CPLEX 22.2

No size of the model received, so the presolve says what is left. No time per iteration and no final status, so a solve ends on finished. A long stretch without any line is common: 251 s of 291 on a 720 000-row model

MOSEK 11.2

No number of nonzeros, and no columns after the presolve, as its count has the slacks. No final status for a Benders master, which ends on finished

COPT 8.0

The simplex counts infeasibilities instead of measuring them, so these fields stay empty. A Benders master is reported on only with solver_logs, and pommes.solve_model() leaves the log on the console as well, as the solver offers no way out of it

Gurobi 13.0

Time per iteration in whole seconds

Infeasibilities and gaps are the numbers of the solver, whose measures differ: compare them along a solve, not from one solver to another.

Solves without report

Case

What happens

A solve through model.solve

Its progress is the log of the solver, which linopy shows. To send it to a file, pass progress=False, log_fn="results/solver.log" and the option of the solver, such as log_to_console=False for HiGHS

persistent=False, or a solver without persistent backend

The master has no solver log, hence no report

In an application

An application that configures logging should not call pommes.configure_logging(): every record reaches its root logger, as a one-line message in its own format, and the extra fields of an event are on the record (record.event, record.data). Only that call stops the records at the pommes logger, to avoid showing them twice.

Conventions for contributors

Modules log through logging.getLogger(__name__), with lazy % formatting. print and the root logger are refused by a test and by ruff. Handlers and formats live in pommes/logs.py and nowhere else. A stage of the computation uses pommes.logs.stage(), and a stage inside another is logged at DEBUG, so a loop over stages does not fill the INFO level.