mythos.utils.helpers
Helper functions for the mythos package.
Attributes
Functions
|
Batch an iterable into chunks of size n. |
|
Stacks corresponding leaves of PyTrees into arrays along a new axis. |
|
Concatenates corresponding leaves of PyTrees along the first axis. |
|
Return the last n lines of a file as a string. |
|
Run a command in a subprocess, raising RuntimeError on failure. |
Module Contents
- mythos.utils.helpers.ERR_BATCHED_N = 'n must be at least one'
- mythos.utils.helpers.batched(iterable: collections.abc.Iterable[Any], n: int) collections.abc.Iterable[Any][source]
Batch an iterable into chunks of size n.
- Parameters:
iterable (iter[Any]) – iterable to batch
n (int) – batch size
- Returns:
batched iterable
- Return type:
iter[Any]
- mythos.utils.helpers.tree_stack(trees: list[jaxtyping.PyTree]) jaxtyping.PyTree[source]
Stacks corresponding leaves of PyTrees into arrays along a new axis.
- mythos.utils.helpers.tree_concatenate(trees: list[jaxtyping.PyTree]) jaxtyping.PyTree[source]
Concatenates corresponding leaves of PyTrees along the first axis.
- mythos.utils.helpers.tail_file(path: pathlib.Path, n: int = 10) str[source]
Return the last n lines of a file as a string.
- mythos.utils.helpers.run_command(cmd: list[str], cwd: pathlib.Path, log_prefix: str = 'command-output', err_tail_lines: int = 20) None[source]
Run a command in a subprocess, raising RuntimeError on failure.
Stderr and stdout are captured to files in the cwd directory, named with provided prefix. If the process fails with a CalledProcessError, the last tail_lines of each log file are included in the raised RuntimeError.
- Parameters: