tracking_base#


class TrackingContext(name: str, experiment: Optional[TrackedExperiment])[source]#

Bases: ABC

static from_optional_experiment(experiment: Optional[TrackedExperiment], model: Optional[VectorModelBase] = None, name: Optional[str] = None, description: str = '')[source]#
is_enabled()[source]#
Returns:

True if tracking is enabled, i.e. whether results can be saved via this context

track_metrics(metrics: Dict[str, float], predicted_var_name: Optional[str] = None)[source]#
Parameters:
  • metrics – the metrics to be logged

  • predicted_var_name – the name of the predicted variable for the case where there is more than one. If it is provided, the variable name will be prepended to every metric name.

abstract track_figure(name: str, fig: Figure)[source]#
Parameters:
  • name – the name of the figure (not a filename, should not include file extension)

  • fig – the figure

abstract track_text(name: str, content: str)[source]#
Parameters:
  • name – the name of the text (not a filename, should not include file extension)

  • content – the content (arbitrarily long text, e.g. a log)

end()[source]#
class DummyTrackingContext(name)[source]#

Bases: TrackingContext

A dummy tracking context which performs no actual tracking. It is useful to avoid having to write conditional tracking code for the case where there isn’t a tracked experiment.

is_enabled()[source]#
Returns:

True if tracking is enabled, i.e. whether results can be saved via this context

track_figure(name: str, fig: Figure)[source]#
Parameters:
  • name – the name of the figure (not a filename, should not include file extension)

  • fig – the figure

track_text(name: str, content: str)[source]#
Parameters:
  • name – the name of the text (not a filename, should not include file extension)

  • content – the content (arbitrarily long text, e.g. a log)

class TrackedExperiment(context_prefix: str = '', additional_logging_values_dict=None)[source]#

Bases: Generic[TContext], ABC

Base class for tracking :param additional_logging_values_dict: additional values to be logged for each run

track_values(values_dict: Dict[str, Any], add_values_dict: Dict[str, Any] = None)[source]#
begin_context(name: str, description: str = '') TContext[source]#

Begins a context in which actual information will be tracked. The returned object is a context manager, which can be used in a with-statement.

Parameters:
  • name – the name of the context (e.g. model name)

  • description – a description (e.g. full model parameters/specification)

Returns:

the context, which can subsequently be used to track information

begin_context_for_model(model: VectorModelBase)[source]#

Begins a tracking context for the case where we want to track information about a model (wrapper around begin_context for convenience). The model name is used as the context name, and the model’s string representation is used as the description. The returned object is a context manager, which can be used in a with-statement.

Parameters:

model – the model

Returns:

the context, which can subsequently be used to track information

end_context(instance: TContext)[source]#
class TrackingMixin[source]#

Bases: ABC

set_tracked_experiment(tracked_experiment: Optional[TrackedExperiment])[source]#
unset_tracked_experiment()[source]#
property tracked_experiment: Optional[TrackedExperiment]#
begin_optional_tracking_context_for_model(model: VectorModelBase, track: bool = True) TrackingContext[source]#

Begins a tracking context for the given model; the returned object is a context manager and therefore method should preferably be used in a with statement. This method can be called regardless of whether there actually is a tracked experiment (hence the term ‘optional’). If there is no tracked experiment, calling methods on the returned object has no effect. Furthermore, tracking can be disabled by passing track=False even if a tracked experiment is present.

Parameters:

model – the model for which to begin tracking

Paraqm track:

whether tracking shall be enabled; if False, force use of a dummy context which performs no actual tracking even if a tracked experiment is present

Returns:

a context manager that can be used to track results for the given model