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

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

1 participant