callbacks

This module provides an abstract base class for a callback and a default implementation.

If you want to store the data in a way that is different from the functionality provided by the default callback, you can write your own extension of callback. For example, you can easily implement a callback that stores the data in e.g. a NoSQL file.

The only method to implement is the __call__ magic method. To use logging of progress, always call super.

class ema_workbench.em_framework.callbacks.AbstractCallback(uncertainties, levers, outcomes, nr_experiments, reporting_interval=None, reporting_frequency=10, log_progress=False)

Abstract base class from which different call back classes can be derived. Callback is responsible for storing the results of the runs.

Parameters:
  • uncertainties (list) – list of uncertain parameters

  • levers (list) – list of lever parameters

  • outcomes (list) – a list of outcomes

  • nr_experiments (int) – the total number of experiments to be executed

  • reporting_interval (int, optional) – the interval between progress logs

  • reporting_frequency (int, optional) – the total number of progress logs

  • log_progress (bool, optional) – if true, progress is logged, if false, use tqdm progress bar.

i

a counter that keeps track of how many experiments have been saved

Type:

int

nr_experiments
Type:

int

outcomes
Type:

list

parameters

combined list of uncertain parameters and lever parameters

Type:

list

reporting_interval

the interval between progress logs

Type:

int,

abstract get_results()

method for retrieving the results. Called after all experiments have been completed. Any extension of AbstractCallback needs to implement this method.

class ema_workbench.em_framework.callbacks.DefaultCallback(uncertainties, levers, outcomes, nr_experiments, reporting_interval=100, reporting_frequency=10, log_progress=False)

Default callback class

Parameters:
  • uncertainties (list) – list of uncertain parameters

  • levers (list) – list of lever parameters

  • outcomes (list) – a list of outcomes

  • nr_experiments (int) – the total number of experiments to be executed

  • reporting_interval (int, optional) – the interval between progress logs

  • reporting_frequency (int, optional) – the total number of progress logs

  • log_progress (bool, optional) – if true, progress is logged, if false, use tqdm progress bar.

Callback can be used in perform_experiments as a means for specifying the way in which the results should be handled. If no callback is specified, this default implementation is used. This one can be overwritten or replaced with a callback of your own design. For example if you prefer to store the result in a database or write them to a text file.

get_results()

method for retrieving the results. Called after all experiments have been completed. Any extension of AbstractCallback needs to implement this method.

class ema_workbench.em_framework.callbacks.FileBasedCallback(uncertainties, levers, outcomes, nr_experiments, reporting_interval=100, reporting_frequency=10)

Callback that stores data in csv files while running th model

Parameters:
  • uncertainties (list) – list of uncertain parameters

  • levers (list) – list of lever parameters

  • outcomes (list) – a list of outcomes

  • nr_experiments (int) – the total number of experiments to be executed

  • reporting_interval (int, optional) – the interval between progress logs

  • reporting_frequency (int, optional) – the total number of progress logs

  • log_progress (bool, optional) – if true, progress is logged, if false, use tqdm progress bar.

Warning

This class is still in beta. the data is stored in ./temp, relative to the current working directory. If this directory already exists, it will be overwritten.

get_results()

method for retrieving the results. Called after all experiments have been completed. Any extension of AbstractCallback needs to implement this method.