Skip to content

Commit

Permalink
Add docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
opcode81 committed Aug 3, 2023
1 parent 1b727ad commit 55ef738
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/sensai/tracking/mlflow_tracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@ class MLFlowExperiment(TrackedExperiment[MLFlowTrackingContext]):
def __init__(self, experiment_name: str, tracking_uri: str, additional_logging_values_dict=None,
context_prefix: str = ""):
"""
:param experiment_name:
:param tracking_uri:
:param experiment_name: the name of the experiment, which should be the same for all models of the same kind (i.e. all models evaluated
under the same conditions)
:param tracking_uri: the URI of the server (if any); use "" to track in the local file system
:param additional_logging_values_dict:
:param context_prefix:
:param context_prefix: a prefix to add to all contexts that are created within the experiment. This can be used to add
an identifier of a certain execution/run, such that the actual context name passed to `begin_context` can be concise (e.g. just model name).
"""
mlflow.set_tracking_uri(tracking_uri)
mlflow.set_experiment(experiment_name=experiment_name)
Expand Down
16 changes: 16 additions & 0 deletions src/sensai/tracking/tracking_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,27 @@ def _create_tracking_context(self, name: str, description: str) -> TContext:
pass

def begin_context(self, name: str, description: str = "") -> TContext:
"""
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.
:param name: the name of the context (e.g. model name)
:param description: a description (e.g. full model parameters/specification)
:return: the context, which can subsequently be used to track information
"""
instance = self._create_tracking_context(self.instancePrefix + name, description)
self._contexts.append(instance)
return instance

def begin_context_for_model(self, model: VectorModelBase):
"""
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.
:param model: the model
:return: the context, which can subsequently be used to track information
"""
return self.begin_context(model.get_name(), str(model))

def end_context(self, instance: TContext):
Expand Down

0 comments on commit 55ef738

Please sign in to comment.