fdtdx.Logger#

class fdtdx.Logger(experiment_name, name=None, save_source=False, save_script=True)[source]#

Bases: object

Logger for managing experiment outputs and visualization.

Handles experiment logging, metrics tracking, and visualization of simulation results. Creates a working directory structure, initializes logging, and provides methods for saving figures, metrics, and device parameters.

Parameters:
  • experiment_name (str) – Name of the experiment. This is the naming of the parent directory where the experiment will be saved.

  • name (str | None, optional) – Optional specific name for the working directory. If None, uses timestamp.

Quick Reference#

Attributes

Methods

Attributes#

Logger.params_dir#

Directory for storing parameter files.

Returns:

Directory for parameter file outputs

Return type:

Path

Logger.stl_dir#

Directory for storing STL files.

Returns:

Directory for STL file outputs

Return type:

Path

Methods#

Logger.log_detectors(iter_idx, objects, detector_states, exclude=())[source]#

Log detector states and generate visualization plots.

Creates plots for each detector’s state and saves them to the detector’s output directory. Handles both figure outputs and other detector-specific file formats.

Parameters:
  • iter_idx (int) – Current iteration index

  • objects (ObjectContainer) – Container with simulation objects

  • detector_states (dict[str, DetectorState]) – Dictionary mapping detector names to their states

  • exclude (Sequence[str], optional) – List of detector names to exclude from logging

Logger.log_params(iter_idx, params, objects, export_figure=False, export_stl=False, export_background_stl=False, **transformation_kwargs)[source]#

Log parameter states and export device visualizations.

Saves device parameters and optionally exports visualizations as figures or STL files. Tracks changes in device voxels between iterations.

Parameters:
  • iter_idx (int) – Current iteration index

  • params (ParameterContainer) – Container with device parameters

  • objects (ObjectContainer) – Container with simulation objects

  • export_figure (bool, optional) – Whether to export index matrix figures

  • export_stl (bool, optional) – Whether to export device geometry as STL

  • export_background_stl (bool, optional) – Whether to export air regions as STL

  • **transformation_kwargs – keyword arguments passed to the parameter transformation

Returns:

Number of voxels that changed since last iteration

Return type:

int

Logger.savefig(directory, filename, fig, dpi=300)[source]#

Save a matplotlib figure to file.

Creates a figures subdirectory if needed and saves the figure with specified settings.

Parameters:
  • directory (Path) – Base directory to save in

  • filename (str) – Name for the figure file

  • fig (Figure) – Matplotlib figure to save

  • dpi (int, optional) – Resolution in dots per inch. Defaults to 300.

Logger.write(stats, do_print=True)[source]#

Write statistics to CSV file and optionally print them.

Records metrics in a CSV file and optionally displays them in a formatted table. Automatically initializes CSV headers on first write.

Parameters:
  • stats (dict) – Dictionary of statistics to record

  • do_print (bool, optional) – Whether to print stats to console. Defaults to true.

If you find any errors in the documentation, please report them in the Github Issues!