GloMPO Scope

GloMPO provides a dynamic plotting object to track optimizer progress. This can be viewed in real-time, or saved into a movie file. This is useful for debugging and finding the right manager configurations. It provides insight into how the optimization behaved, and how the manager managed it.

The class details below are for reference only. The user need not initialise or control the scope directly; this is all done by GloMPO internals. To dynamically plot an optimization, see GloMPOManager.visualisation.

Please see Checkpointing & Visualisation if you are planning to make use of both simultaneously.

class glompo.core.scope.GloMPOScope(x_range: Union[Tuple[float, float], int, None] = 300, y_range: Optional[Tuple[float, float]] = None, log_scale: bool = False, record_movie: bool = False, interactive_mode: bool = False, events_per_flush: int = 10, elitism: bool = False, writer_kwargs: Optional[Dict[str, Any]] = None, movie_kwargs: Optional[Dict[str, Any]] = None)[source]

Constructs and records the dynamic plotting of optimizers run in parallel.

Parameters:
  • x_range – If None is provided the x-axis will automatically and continuously rescale from zero as the number of function evaluations increases. If a tuple of the form (min, max) is provided then the x-axis will be fixed to this range. If an integer is provided then the plot will only show the last x_range evaluations and discard earlier points. This is useful to make differences between optimizers visible in the late stage and also keep the scope operating at an adequate speed.
  • y_range – Sets the y-axis limits of the plot, by default the plot to automatically and constantly rescales the axis.
  • log_scale – See log_scale. This can be used in conjunction with the y_range option which will be interpreted in the log-scale.
  • record_movie – If True then a FFMpegWriter instance is created to record the plot.
  • interactive_mode – If True the plot is visible on screen during the optimization.
  • events_per_flush – See events_per_flush.
  • elitism – See elitism.
  • writer_kwargs – Optional dictionary of arguments to be sent matplotlib.animation.FFMpegWriter.
  • movie_kwargs – Optional dictionary of arguments to be sent to matplotlib.animation.FFMpegWriter.setup ().
ax

Axes object onto which the data is plotted.

Type:matplotlib.axes.Axes
color_map

List which represents the GloMPO color sequence.

Type:matplotlib.colors.ListedColormap
elitism

If True an optimizer’s best function value over time will be plotted instead of its current function value. This greatly simplifies the plot, making it easier to see certain behaviour but also masks a lot of detail.

Type:bool
events_per_flush

The number of ‘events’ or updates and changes to the scope before the changes are flushed and the plot is redrawn. A lower number provides a smoother visualisation but is expensive and, if recorded, takes a larger amount of space.

Type:int
fig

Figure object into which the ax is embedded.

Type:matplotlib.figure.Figure
gen_streams

Collection of ‘annotation’ plots used to indicate optimizer terminations, convergences, checkpoints etc.

Type:Dict[str, matplotlib.lines.Line2D]
interactive_mode

If True the plot will be displayed in real-time with the optimization. Otherwise it will be constructed in memory only; record_movie would need to be True to see the results.

Type:bool
leg_elements

Holds the plot legend.

Type:List[matplotlib.lines.Line2D]
log_scale

If True, function values will be plotted on logarithmic scale.

Type:bool
logger

logging.Logger instance into which status messages may be added.

Type:logging.Logger
n_streams

Number of optimizers in the plot.

Type:int
opt_streams

Collection of data plots representing the actual optimizer trajectories.

Type:Dict[str, matplotlib.lines.Line2D]
record_movie

If True, the dynamic plot will be saved to an MPEG-4 file.

Type:bool
truncated

If a value is given, the plot will only retain data for the last truncated function evaluations.

Type:Optional[int]
x_max

The furthest point ever plotted by the scope.

Type:int
is_setup

If True, setup_moviemaker() has been properly called and the movie can be recorded.

add_stream(opt_id: int, opt_type: Optional[str] = None)[source]

Registers and sets up a new optimizer in the scope.

Parameters:
  • opt_id – Unique, GloMPO assigned, optimizer identification key.
  • opt_type – String name of the optimizer type/configuration. Used only in the plot legend.
update_optimizer(opt_id: int, pt: tuple)[source]

Given pt is used to update the opt_id optimizer plot.

update_kill(opt_id: int)[source]

The opt_id optimizer plot is updated to show a manager termination at its final point.

update_norm_terminate(opt_id: int)[source]

The opt_id optimizer plot is updated to show normal convergence at its final point.

update_crash_terminate(opt_id: int)[source]

The opt_id optimizer plot is updated to show a crash termination at its final point.

update_pause(opt_id: int)[source]

The opt_id optimizer plot is updated to show a pause event at its final point.

update_checkpoint(opt_id: int)[source]

The opt_id optimizer plot is updated to show a checkpoint at its final point.

setup_moviemaker(path: Union[pathlib.Path, str, None] = None)[source]

Setups up the movie recording framework. Must be called before the scope begins to be filled in order to begin generating movies correctly.

Parameters:path – An optional directory into which the movie file will be directed. Will overwrite any ‘outfile’ argument sent during scope initialisation.
generate_movie()[source]

Final call to write the saved frames into a single movie.

get_farthest_pt(opt_id: int) → Optional[Tuple[float, float]][source]

Returns the furthest evaluated point of the opt_id optimizer.

close_fig()[source]

Closes the matplotlib.figure.Figure when the scope is closed. Matplotlib will keep a figure alive in its memory for the duration a process is alive. This can lead to many figures being open if GloMPO is looped in some way. The manager will explicitly call this method to close the matplotlib figure at the end of the optimization routine to stop figures building up in this way.

checkpoint_save(path: Union[pathlib.Path, str] = '')[source]

Saves the state of the scope, suitable for resumption, during a checkpoint. path is a directory in which to dump the generated files.

load_state(path: Union[pathlib.Path, str])[source]

Loads a saved scope state. path is a directory containing the checkpoint files.