Skip to content

Conversation

@MySweetEden
Copy link

Summary

Adds setTracefile() method for structured, machine-readable optimization progress logging.

Closes #1147

Motivation

As discussed in #1147, structured progress logging is useful for:

  • Visualization of optimization progress
  • Fair comparison of solver runs
  • Analysis of primal/dual bound evolution

This provides a simpler alternative to implementing custom event handlers.

Design Decisions

  • JSONL format: Allows streaming writes and partial reads even if optimization crashes
  • Separate from setLogfile(): Human-readable log and machine-readable trace serve different purposes
  • Append mode by default: Multiple optimize() calls can accumulate in one file
  • Automatic close: Trace file is managed internally, no explicit close needed
  • Field names match SCIP log: primalbound, dualbound, time, nodes for consistency

Changes

  • Added setTracefile(path, mode="a") method to Model
  • Internal _write_trace_event() for centralized trace writing
  • Event handler for BESTSOLFOUND events

Events Recorded

  • solution_update: when a new best solution is found
  • solve_finish: when optimization terminates

Fields

type, time, primalbound, dualbound, gap, nodes, nsol

Usage

model.setTracefile("trace.jsonl")
model.optimize()

trace.jsonl contains JSONL records

Future Work

  • Recipe/tutorial documentation will be added in a follow-up PR if this implementation is accepted

Open Questions

  • Should a solve_start event be added to distinguish multiple optimize() calls in append mode?
  • Output format: JSONL is chosen for streaming/crash-safety, but CSV/TSV could be discussed

@Joao-Dionisio
Copy link
Member

Joao-Dionisio commented Jan 17, 2026

Hey @MySweetEden , thank you for the contribution! However, can you please make it as a recipe, rather than a part of scip.pxi? We reserve the latter for things that are a part of core-SCIP, and we separate the helpers. So, the flow would be something like

from pyscipopt import Model
from pyscipopt.recipes.traceback import attach_traceback_eventhdlr

m = Model()
attach_traceback_eventhdlr(m)

A bit like the primal_dual_evolution recipe.

How do you feel about this approach? Everything could be implemented in Python, as well.

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.

Proposal: Structured MIP progress logging using event callbacks

2 participants