diff --git a/curifactory/notebook.py b/curifactory/notebook.py index 6e95572..a188533 100644 --- a/curifactory/notebook.py +++ b/curifactory/notebook.py @@ -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( diff --git a/test/test_notebook.py b/test/test_notebook.py index 0ac21c4..f7096cf 100644 --- a/test/test_notebook.py +++ b/test/test_notebook.py @@ -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