Skip to content

Nest Ingredient Observers Inside Main Experiment Directory #1

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions sacred/experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def __init__(
interactive: bool = False,
base_dir: Optional[PathType] = None,
additional_host_info: List[HostInfoGetter] = None,
nest_ingredients: bool = False,
):
"""
Create a new experiment with the given name and optional ingredients.
Expand Down Expand Up @@ -117,6 +118,7 @@ def __init__(
self.observers = []
self.current_run = None
self.captured_out_filter = None
self.nest_ingredients = nest_ingredients
"""Filter function to be applied to captured output of a run"""
self.option_hooks = []

Expand Down
2 changes: 2 additions & 0 deletions sacred/initialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,8 @@ def create_run(
pre_runs,
post_runs,
experiment.captured_out_filter,
sorted_ingredients,
experiment.nest_ingredients,
)

if hasattr(main_function, "unobserved"):
Expand Down
18 changes: 18 additions & 0 deletions sacred/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from sacred.randomness import set_global_seed
from sacred.utils import SacredInterrupt, join_paths, IntervalTimer
from sacred.stdout_capturing import get_stdcapturer
from sacred.observers import FileStorageObserver


class Run:
Expand All @@ -29,6 +30,8 @@ def __init__(
pre_run_hooks,
post_run_hooks,
captured_out_filter=None,
sorted_ingredients=None,
nest_ingredients=False,
):

self._id = None
Expand Down Expand Up @@ -112,6 +115,10 @@ def __init__(
self.capture_mode = None
"""Determines the way the stdout/stderr are captured"""

self.sorted_ingredients = sorted_ingredients

self.nest_ingredients = nest_ingredients

self._heartbeat = None
self._failed_observers = []
self._output_file = None
Expand Down Expand Up @@ -334,8 +341,19 @@ def _emit_started(self):
)
if self._id is None:
self._id = _id
if (
observer.__class__.__name__ == "FileStorageObserver"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More Pythonic: isinstance(observer, FileStorageObserver). That will also match subclasses, which is probably desirable, but if not can do observer.__class__ ==FileStorageObserver.

and self.nest_ingredients
):
for ingredient in self.sorted_ingredients:
ingredient_observer_dir = os.path.join(
observer.dir, ingredient.path
)
new_observer = FileStorageObserver.create(ingredient_observer_dir)
ingredient.observers.append(new_observer)
# do not catch any exceptions on startup:
# the experiment SHOULD fail if any of the observers fails

if self._id is None:
self.run_logger.info("Started")
else:
Expand Down