mythos.utils.helpers ==================== .. py:module:: mythos.utils.helpers .. autoapi-nested-parse:: Helper functions for the mythos package. Attributes ---------- .. autoapisummary:: mythos.utils.helpers.ERR_BATCHED_N Functions --------- .. autoapisummary:: mythos.utils.helpers.batched mythos.utils.helpers.tree_stack mythos.utils.helpers.tree_concatenate mythos.utils.helpers.tail_file mythos.utils.helpers.run_command Module Contents --------------- .. py:data:: ERR_BATCHED_N :value: 'n must be at least one' .. py:function:: batched(iterable: collections.abc.Iterable[Any], n: int) -> collections.abc.Iterable[Any] Batch an iterable into chunks of size n. :param iterable: iterable to batch :type iterable: iter[Any] :param n: batch size :type n: int :returns: batched iterable :rtype: iter[Any] .. py:function:: tree_stack(trees: list[jaxtyping.PyTree]) -> jaxtyping.PyTree Stacks corresponding leaves of PyTrees into arrays along a new axis. .. py:function:: tree_concatenate(trees: list[jaxtyping.PyTree]) -> jaxtyping.PyTree Concatenates corresponding leaves of PyTrees along the first axis. .. py:function:: tail_file(path: pathlib.Path, n: int = 10) -> str Return the last n lines of a file as a string. .. py:function:: run_command(cmd: list[str], cwd: pathlib.Path, log_prefix: str = 'command-output', err_tail_lines: int = 20) -> None 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. :param cmd: command and arguments to run :type cmd: list[str] :param cwd: working directory to run the command in :type cwd: Path :param log_prefix: prefix for the output log files, within the `cwd` directory :type log_prefix: str :param err_tail_lines: number of lines from the end of each log file to include in the error message on failure :type err_tail_lines: int