Skip to content

Commit

Permalink
ENH: Create metadata folder with freezefile, pickle args, and results
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacob-Stevens-Haas committed Dec 10, 2023
1 parent 20bba0f commit 29d698a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
commit-msg
todo
.vscode

# Byte-compiled / optimized / DLL files
__pycache__/
Expand Down
21 changes: 17 additions & 4 deletions mitosis/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
from dataclasses import field
from datetime import datetime
from datetime import timezone
from importlib.metadata import packages_distributions
from importlib.metadata import version
from pathlib import Path
from time import process_time
from types import BuiltinFunctionType
Expand Down Expand Up @@ -321,14 +323,18 @@ def run(
log_msg += ". In debugging mode."
exp_logger.info(log_msg)

exp_metadata_name = datetime.now().astimezone().strftime(r"%Y-%m-%d") + debug_suffix
exp_metadata_folder = trials_folder / exp_metadata_name
exp_metadata_folder.mkdir()
_write_freezefile(exp_metadata_folder)

nb, metrics, exc = _run_in_notebook(
ex,
seed,
group,
params,
trials_folder,
exp_metadata_folder,
addl_mods_and_names,
debug_suffix,
matplotlib_dpi,
)

Expand Down Expand Up @@ -366,7 +372,6 @@ def _run_in_notebook(
params,
trials_folder,
addl_mods_and_names: Collection[ModuleInfo],
results_suffix: str,
matplotlib_dpi=72,
):
run_args = {param.arg_name: param.vals for param in params if not param.modules}
Expand Down Expand Up @@ -425,7 +430,7 @@ def _run_in_notebook(
run_cell = nbformat.v4.new_code_cell(source="results = ex.run(seed, **args)")
final_cell = nbformat.v4.new_code_cell(
source=""
f"with open(r'{trials_folder / ('results'+results_suffix+'.npy')}', 'wb') as f:\n" # noqa E501
f"with open(r'{trials_folder / ('results.dill')}', 'wb') as f:\n" # noqa E501
" dill.dump(results, f)\n"
"print(repr(results))\n"
)
Expand Down Expand Up @@ -546,3 +551,11 @@ def __str__(self):
else:
string = string[:-2] + "]"
return string


def _write_freezefile(folder: Path):
installed = {pkg for pkgs in packages_distributions().values() for pkg in pkgs}
req_str = "# {sys.version}\n"
req_str += "\n".join(f"{pkg}=='{version(pkg)}'" for pkg in installed)
with open(folder / "requirements.txt", "w") as f:
f.write(req_str)

0 comments on commit 29d698a

Please sign in to comment.