-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add client side ExperimentDefinition #9
Conversation
5286856
to
e3f82a8
Compare
return _c | ||
|
||
|
||
def get_results_path(self) -> str: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We will want some single source-of-truth for this function. Most of it can be refactored out into a utility, I think:
def get_experiment_name():
import __main__
return __main__.__file__.split('/')[-2]
def get_results_path(base_path: str, name: str):
return os.path.join(
base_path,
name,
get_experiment_name(),
)
Then both sides can reference this (the def'n creator side and the client side).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed! But this change breaks stubbed_DefinitionPart
in tests/test_ExperimentDefinition.py
as this class stubs the get_results_path
method. For now I added a property that points to the 'single source of truth` function that we can override in tests.
from ml_experiment._utils.path import get_results_path
class ExperimentDefinition:
def __init__(self, ...):
self.get_results_path = get_results_path
...
with sqlite3.connect(db_path) as con: | ||
cur = con.cursor() | ||
# ensure config_ids exist | ||
assert all( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be worth pushing the assertion down into the:
self.table.get_configuration(cur, config_id)
code instead. This way, we can be more specific with our error message:
raise ValueError(f"config_id <{config_id}> is not in table <{self.get_table_name()}>")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense!
tests/test_ExperimentDefinition.py
Outdated
from ml_experiment.ExperimentDefinition import ExperimentDefinition | ||
|
||
|
||
def test_ExperimentDefinition(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a great spot for the tmp_path
fixture, which produces (and cleans up) a temporary file path for storing test results and guaranteeing there is no overlapping global state.
def test_ExperimentDefinition(tmp_path):
...
part = stubbed_DefinitionPart(exp_name, part_name, base=str(tmp_path))
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorcery!
assert config == {'alpha': 0.125, 'beta': 0.5, 'id': 0} | ||
|
||
configs = exp.get_configs(config_ids) | ||
assert configs == [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does make me wonder if we should consider making some guarantees about ordering. I'm leaning towards "yes", since that's also what PyExpUtils does.
We can make that an issue, then do the guaranteed ordering in another PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Created #11 for this feature!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! I would go ahead and do the dict(zip)
change and whatever git cleanup you'd like, then it's good to merge!
This is needed for pytest to import this package.
After clean up this pr has 5 commits and resolves issue #7 by adding an Commit 1 and 2 implement the |
Addresses #7