-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
## 📥 Pull Request Description This pull request implements the experiment manager feature. This feature was requested to be able to filter experiments based on their properties. The AppState has also been added. ## 👀 Affected Areas Experiments Co-authored-by: Nils Uhrberg <[email protected]>
- Loading branch information
Showing
18 changed files
with
471 additions
and
270 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
# niceml-dashboard | ||
- Welcome on board. | ||
|
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
""" | ||
This module provides a class for the buttons on the sidebar. | ||
""" | ||
from nicegui import ui | ||
from nicemldashboard.experiment.type import ExperimentType | ||
|
||
from nicemldashboard.state.appstate import ( | ||
get_event_manager, | ||
ExperimentStateKeys, | ||
ExperimentEvents, | ||
) | ||
|
||
|
||
class SidebarButton(ui.button): | ||
""" | ||
This class describes a sidebarbutton and has methods to handle on click events. | ||
""" | ||
|
||
def __init__( | ||
self, | ||
*args, | ||
experiment_type: ExperimentType, | ||
**kwargs, | ||
) -> None: | ||
""" | ||
Inits SidebarButton class with the provided experiment type | ||
Args: | ||
*args: | ||
experiment_type: | ||
**kwargs: | ||
""" | ||
super().__init__(*args, **kwargs) | ||
self.experiment_type = experiment_type | ||
self.on("click", self._change_experiment_type) | ||
|
||
def _change_experiment_type(self): | ||
experiment_state_data = get_event_manager().get_dict( | ||
ExperimentStateKeys.EXPERIMENT_DICT | ||
) | ||
experiment_state_data[ | ||
ExperimentEvents.ON_EXPERIMENT_PREFIX_CHANGE | ||
] = self.experiment_type |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
""" | ||
This module provides custom exception implementations for the app | ||
""" | ||
|
||
|
||
class ExperimentFilterError(TypeError): | ||
"""There is a filtering error.""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
""" | ||
This module provides an experiment manager. Currently, experiment manager | ||
supports filtering experiments by their properties. | ||
""" | ||
import logging | ||
from typing import List | ||
|
||
from nicemldashboard.exceptions import ExperimentFilterError | ||
from nicemldashboard.experiment.experiment import Experiment | ||
|
||
|
||
class ExperimentManager: | ||
""" | ||
Allows filtering experiments by making the filter_by method available | ||
""" | ||
|
||
def __init__(self, experiments: List[Experiment]): | ||
""" | ||
Initializes an ExperimentManager with the provided list of experiments. | ||
""" | ||
self.experiments = experiments | ||
|
||
def filter_by(self, **filters) -> List[Experiment]: | ||
""" | ||
Filters the experiment list after filtering with the provided filters | ||
Args: | ||
**filters: A dictionary of filters to filter by | ||
Returns: | ||
List of filtered experiments | ||
""" | ||
filtered_experiments = [] | ||
for experiment_attribute, field_value in filters.items(): | ||
try: | ||
filtered_experiments = [ | ||
exp | ||
for exp in self.experiments | ||
if getattr(exp, experiment_attribute, None) == field_value | ||
] | ||
except ExperimentFilterError as e: | ||
# Log the error message with details of which experiment and filter caused it. | ||
logging.warning( | ||
f"Incomparable types between attribute '{experiment_attribute}' " | ||
f"with field_value '{field_value}' " | ||
f"and filter field_value '{field_value}': {e}" | ||
) | ||
return filtered_experiments |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.