Skip to content
Merged
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
8 changes: 8 additions & 0 deletions src/experimaestro/core/objects/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,14 @@ def seal(self, context: ConfigWalkContext):
Arguments:
- context: the generation context
"""
subconfigs = [
v.__xpm__
for v in self.values.values()
if isinstance(v, Config) and v.__xpm__.task is None
]

if any(v._has_generated_value for v in subconfigs):
raise AttributeError("Cannot seal a configuration with generated values")

class Sealer(ConfigWalk):
def preprocess(self, config: ConfigMixin):
Expand Down
30 changes: 29 additions & 1 deletion src/experimaestro/tests/test_generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Learner(Task):
x: Param[int]


def test_generators_reuse():
def test_generators_reuse_on_submit():
# We have one way to select the best model
validation = Validation.C()

Expand All @@ -31,3 +31,31 @@ def test_generators_reuse():
# Here we have a problem...
# the path is still the previous one
Learner.C(x=2, validation=validation).submit(workspace=workspace)


def test_generators_delayed_submit():
workspace = Workspace(
Settings(),
WorkspaceSettings("test_generators_simple", path=Path("/tmp")),
run_mode=RunMode.DRY_RUN,
)
validation = Validation.C()
task1 = Learner.C(x=1, validation=validation)
task2 = Learner.C(x=2, validation=validation)
task1.submit(workspace=workspace)
with pytest.raises((AttributeError)):
task2.submit(workspace=workspace)


def test_generators_reuse_on_set():
workspace = Workspace(
Settings(),
WorkspaceSettings("test_generators_simple", path=Path("/tmp")),
run_mode=RunMode.DRY_RUN,
)
validation = Validation.C()
Learner.C(x=1, validation=validation).submit(workspace=workspace)
with pytest.raises((AttributeError)):
# We should not be able to *create* a second task with the same validation,
# even without submitting it
Learner.C(x=2, validation=validation)