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
1 change: 1 addition & 0 deletions autoconf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from .json_prior.config import JSONPriorConfig

from .setup_colab import for_autolens
from .setup_notebook import setup_notebook
from .test_mode import test_mode_level, is_test_mode


Expand Down
2 changes: 0 additions & 2 deletions autoconf/setup_colab.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ def for_autogalaxy(raise_error_if_not_gpu: bool = True) -> None:
"pyvis==0.3.2",
"dill==0.4.0",
"jaxnnls",
"pyprojroot==0.2.0",
"nautilus-sampler==1.0.4",
"timeout_decorator==0.5.0",
"anesthetic==2.8.14",
Expand Down Expand Up @@ -183,7 +182,6 @@ def for_autolens(raise_error_if_not_gpu: bool = True) -> None:
"pyvis==0.3.2",
"dill==0.4.0",
"jaxnnls",
"pyprojroot==0.2.0",
"nautilus-sampler==1.0.4",
"timeout_decorator==0.5.0",
"anesthetic==2.8.14",
Expand Down
41 changes: 41 additions & 0 deletions autoconf/setup_notebook.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import os
from pathlib import Path


def setup_notebook():
"""
Set up a Jupyter notebook to run from the workspace root.

Finds the workspace root by walking up from the current directory
looking for a ``config`` directory (the marker for a PyAuto workspace),
changes to it, reconfigures autoconf paths, and enables inline plotting.
"""
root = _find_workspace_root()
os.chdir(root)

from autoconf import conf

conf.instance.push(
new_path=root / "config",
output_path=root / "output",
)

try:
ipy = get_ipython()
ipy.run_line_magic("matplotlib", "inline")
except NameError:
pass

print(f"Working Directory has been set to `{root}`")


def _find_workspace_root(start=None):
"""Walk up from *start* (default: cwd) looking for a ``config/`` dir."""
current = Path(start or os.getcwd()).resolve()
for parent in [current, *current.parents]:
if (parent / "config").is_dir():
return parent
raise FileNotFoundError(
"Could not find workspace root (no 'config/' directory found "
f"in {current} or any parent)."
)
Loading