foxes_opt.callbacks.write_optimization_history

Classes

WriteOptimizationHistoryCallback

Write objective and constraint-violation counts to a CSV file.

Module Contents

class foxes_opt.callbacks.write_optimization_history.WriteOptimizationHistoryCallback(file_path: str | pathlib.Path, objective: int = 0, iteration_offset: int = 0, append: bool = False, write_initial: bool = False)[source]

Bases: iwopy.core.OptimizerCallback

Write objective and constraint-violation counts to a CSV file.

Population states report the individual with the best finite configured objective. Iterations without cached values retain their row with empty objective and constraint fields. By default initialization replaces an existing file. Append mode preserves rows only when the existing CSV header matches this callback’s schema. Enable write_initial to evaluate the starting variables and record their objective and constraint-violation count before optimizer iterations.

Initialize the optimization history callback.

Parameters:
file_path

Path of the CSV history file.

objective

Objective component used to select and report an individual.

iteration_offset

Non-negative offset added to reported iteration numbers.

append

Whether to preserve and append to a non-empty existing history file. Missing and empty files receive a new header.

write_initial

Evaluate the initial variables during initialization and write their objective and constraint-violation count at iteration_offset. Leave disabled when appending a restart whose starting row already exists.

Raises:
TypeError

If iteration_offset is not an integer or append or write_initial is not a boolean.

ValueError

If objective is not a non-negative integer or iteration_offset is negative.

finalize(results: iwopy.core.opt_results.SingleObjOptResults | iwopy.core.opt_results.MultiObjOptResults) → None

Process the completed optimization results.

Parameters:
results

The completed iwopy optimization results.

initialize(optimizer: iwopy.core.Optimizer) → None[source]

Prepare the history file and optionally record the starting values.

Parameters:
optimizer

Optimizer whose problem defines objective direction and constraint feasibility.

Raises:
IndexError

If the selected objective component does not exist.

ValueError

If append mode encounters a non-empty file with another CSV header, or initial output is enabled and required initial variables are undefined.

notify(data: iwopy.core.OptimizerCallbackData) → None[source]

Append the current objective and violation count to the CSV file.

Parameters:
data

Normalized optimizer callback snapshot for one iteration.

Raises:
ValueError

If the snapshot has no iteration number or lacks the configured objective component.

RuntimeError

If the callback has not been initialized.

append = False
file_path
iteration_offset = 0
objective = 0
optimizer : iwopy.core.optimizer.Optimizer | None = None
write_initial = False