ConvergenceLogger#

class esis.optics.ConvergenceLogger(directory, offset_energy=1000.0)[source]#

Bases: Printable

A callback which logs the convergence of an optimization to disk.

Intended for scipy.optimize.differential_evolution(). On every iteration, the best objective value and the standard deviation of the population energies are appended to a CSV file, the best parameter vector is appended to a text log, and a convergence plot is saved, so that long-running fits can be monitored and post-mortemed.

Attributes

offset_energy

An offset added to the objective values before plotting on a logarithmic scale, chosen to keep the (typically negative) correlation objective of DistortionObjective positive.

path_data

The path of the CSV file containing the convergence history.

path_log

The path of the text file mirroring the console output.

path_plot

The path of the convergence plot.

directory

The directory where the log files are saved.

Methods

__init__(directory[, offset_energy])

log(message)

Print a message to the console and append it to path_log.

save_plot()

Save a plot of the convergence history to path_plot.

to_string([prefix])

Public-facing version of the __repr__ method that allows for defining a prefix string, which can be used to calculate how much whitespace to add to the beginning of each line of the result.

Inheritance Diagram

Inheritance diagram of esis.optics.ConvergenceLogger
Parameters:
log(message)[source]#

Print a message to the console and append it to path_log.

Parameters:

message (str) – The message to log.

Return type:

None

save_plot()[source]#

Save a plot of the convergence history to path_plot.

Return type:

None

to_string(prefix=None)#

Public-facing version of the __repr__ method that allows for defining a prefix string, which can be used to calculate how much whitespace to add to the beginning of each line of the result.

Parameters:

prefix (None | str) – an optional string, the length of which is used to calculate how much whitespace to add to the result.

Return type:

str

directory: Path#

The directory where the log files are saved.

offset_energy: float = 1000.0#

An offset added to the objective values before plotting on a logarithmic scale, chosen to keep the (typically negative) correlation objective of DistortionObjective positive.

property path_data: Path#

The path of the CSV file containing the convergence history.

property path_log: Path#

The path of the text file mirroring the console output.

property path_plot: Path#

The path of the convergence plot.