imitation.util.sacred#

Helper methods for the sacred experimental configuration and logging framework.

Functions

build_sacred_symlink(log_dir, run)

Constructs a symlink "{log_dir}/sacred" => "${SACRED_PATH}".

dict_get_nested(d, nested_key, *[, sep, default])

rtype

Any

dir_contains_sacred_jsons(dir_path)

rtype

bool

filter_subdirs(root_dir[, filter_fn, nested_ok])

Walks through a directory tree, returning paths to filtered subdirectories.

get_sacred_dir_from_run(run)

Returns path to the sacred directory, or None if not found.

Classes

SacredDicts(sacred_dir, config, run)

Each dict foo is loaded from f"{sacred_dir}/foo.json".

class imitation.util.sacred.SacredDicts(sacred_dir: Path, config: dict, run: dict)[source]#

Bases: tuple

Each dict foo is loaded from f”{sacred_dir}/foo.json”.

config: dict#
classmethod load_from_dir(sacred_dir)[source]#
run: dict#
sacred_dir: Path#

Constructs a symlink “{log_dir}/sacred” => “${SACRED_PATH}”.

Return type

None

imitation.util.sacred.dict_get_nested(d, nested_key, *, sep='.', default=None)[source]#
Return type

Any

imitation.util.sacred.dir_contains_sacred_jsons(dir_path)[source]#
Return type

bool

imitation.util.sacred.filter_subdirs(root_dir, filter_fn=<function dir_contains_sacred_jsons>, *, nested_ok=False)[source]#

Walks through a directory tree, returning paths to filtered subdirectories.

Does not follow symlinks.

Parameters
  • root_dir (Path) – The start of the directory tree walk.

  • filter_fn (Callable[[Path], bool]) – A function with takes a directory path and returns True if we should include the directory path in this function’s return value.

  • nested_ok (bool) – Allow returning “nested” directories, i.e. a return value where some elements are subdirectories of other elements.

Return type

Sequence[Path]

Returns

A list of all subdirectory paths where filter_fn(path) == True.

Raises

ValueError – If nested_ok is False and one of the filtered directory paths is a subdirecotry of another.

imitation.util.sacred.get_sacred_dir_from_run(run)[source]#

Returns path to the sacred directory, or None if not found.

Return type

Optional[Path]