foxes_opt.callbacks.write_layout¶
Classes¶
Write intermediate optimization layouts to CSV and image files. |
Module Contents¶
-
class foxes_opt.callbacks.write_layout.WriteLayoutCallback(out_dir: str | pathlib.Path, base_name: str, n_step: int =
1, figsize: tuple[float, float] | None =None, verbosity: int =0, write_csv: bool =True, write_image: bool =True, image_format: str ='jpg', valid_color: str ='tab:blue', invalid_color: str ='red', write_initial: bool =True, step_offset: int =0)[source]¶ Bases:
iwopy.core.OptimizerCallbackWrite intermediate optimization layouts to CSV and image files.
By default, the initial layout is written as step zero before optimizer iterations begin. Its objective and constraints are evaluated so the title and turbine validity colors represent the initial layout. This can be disabled with
write_initial=False. For population snapshots, the member with the best finite first objective is written. Iteration-based optimizers use their iteration number in file names; evaluation-based optimizers use their cumulative evaluation count.step_offsetis added to that count so a restarted run can continue an existing sequence. A snapshot overwrites files with the same resulting path; callers continuing a sequence must choose a collision-free offset.Initialize the layout snapshot callback.
- Parameters:¶
- out_dir
The output directory for CSV layouts. Images are written to a child directory named after their file format.
- base_name
The base name for the layout files.
- n_step
The number of iterations or evaluations between writing layouts.
- figsize
The figure size for layout plots.
- verbosity
The verbosity level, 0 = silent.
- write_csv
Whether to write CSV layout files.
- write_image
Whether to write layout plot files.
- image_format
The image file extension used for layout plots.
- valid_color
The Matplotlib color for valid turbines.
- invalid_color
The Matplotlib color for turbines associated with violated constraints.
- write_initial
Whether to evaluate and write the initial layout as step zero.
- step_offset
Non-negative offset added to snapshot iteration or evaluation numbers, including the optional initial snapshot.
- Raises:¶
- TypeError
If
step_offsetis not an integer.- ValueError
If
n_stepis less than one,step_offsetis negative, orimage_formatis not a file extension.
- 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 a separate farm for writing layouts.
- Parameters:¶
- optimizer
The optimizer starting the run.
- notify(data: iwopy.core.OptimizerCallbackData) None[source]¶
Write a layout for an intermediate optimizer state.
- Parameters:¶
- data
The current normalized optimizer state.
- base_name¶
-
figsize =
None¶
- image_format¶
-
invalid_color =
'red'¶
-
n_step =
1¶
- out_dir¶
-
step_offset =
0¶
-
valid_color =
'tab:blue'¶
-
verbosity =
0¶
-
write_csv =
True¶
-
write_image =
True¶
-
write_initial =
True¶