Skip to content

Commit

Permalink
Fix output notebooks missing cache path of the manager
Browse files Browse the repository at this point in the history
Fixes #106
  • Loading branch information
WarmCyan committed Nov 6, 2023
1 parent 3c87860 commit 43b793e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
7 changes: 5 additions & 2 deletions curifactory/notebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,13 @@ def write_experiment_notebook(

# pathing for whether full run or not
directory_change_back = "/".join([".."] * directory_change_back_depth)
cache_dir_arg = f"manager_cache_path='{manager.get_run_output_path()}', cache_path='{manager.get_run_output_path()}/artifacts', "

if manager.store_full:
cache_dir_arg = f"manager_cache_path='{manager.get_run_output_path()}', cache_path='{manager.get_run_output_path()}/artifacts', "

# warn if data is potentially wrong
if use_global_cache:
cache_dir_arg = ""
cache_dir_arg = f"cache_path='{manager.cache_path}',"
dry_warning = ""
if not suppress_global_warning:
output_lines.extend(
Expand Down
28 changes: 27 additions & 1 deletion test/test_notebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,32 @@ def test_experiment_notebook_is_runnable(configured_test_manager):
assert thelocals["state1"]["my_output"] == 15


# TODO: test that cache_path is provided to manager
def test_notebook_uses_correct_cache_path(configured_test_manager):
"""A notebook for a run that used a non-default cache path (e.g. reproducing
from full store) should set the new manager to use that non-default cache path."""
results, mngr = run_experiment(
"simple_cache",
["simple_cache"],
param_set_names=["thing1", "thing2"],
build_notebook=True,
cache_dir_override="test/examples/data/extraspecial_cache",
)

assert os.path.exists(mngr.artifacts[-1].file)
assert "extraspecial_cache" in mngr.artifacts[-1].file

write_experiment_notebook(
mngr, "test/examples/notebooks/experiment", leave_script=True
)

with open("test/examples/notebooks/experiment.py") as infile:
code = infile.read()

code = code.replace("%cd ../..", "")
thelocals = {}
exec(code, None, thelocals)
assert mngr.cache_path == "test/examples/data/extraspecial_cache"
assert thelocals["manager"].cache_path == "test/examples/data/extraspecial_cache"


# TODO: test can run new stages after experiment run in notebook

0 comments on commit 43b793e

Please sign in to comment.