pytams.utils

A set of utility functions for TAMS.

Functions

is_windows_os(→ bool)

Indicates Windows platform.

is_mac_os(→ bool)

Indicates MacOS platform.

setup_logger(→ None)

Setup the logger parameters.

get_min_scored(→ tuple[list[int], ...)

Get the nworker lower scored trajectories or more if equal score.

moving_avg(→ numpy.typing.NDArray[Any])

Return the moving average of a 1D numpy array.

get_module_local_import(→ list[str])

Helper function getting local imported mods list.

generate_subclass(→ None)

Generate a subclass skeleton.

Module Contents

is_windows_os() bool[source]

Indicates Windows platform.

is_mac_os() bool[source]

Indicates MacOS platform.

setup_logger(params: dict[Any, Any]) None[source]

Setup the logger parameters.

Parameters:

params – a dictionary of parameters

get_min_scored(maxes: numpy.typing.NDArray[Any], nworkers: int) tuple[list[int], numpy.typing.NDArray[Any]][source]

Get the nworker lower scored trajectories or more if equal score.

Parameters:
  • maxes – array of maximas across all trajectories

  • nworkers – number of workers

Returns:

list of indices of the nworker lower scored trajectories array of minimas

moving_avg(arr_in: numpy.typing.NDArray[Any], window_l: int) numpy.typing.NDArray[Any][source]

Return the moving average of a 1D numpy array.

Parameters:
  • arr_in – 1D numpy array

  • window_l – length of the moving average window

Returns:

1D numpy array

get_module_local_import(module_name: str) list[str][source]

Helper function getting local imported mods list.

When pickling the forward model code, the model itself can import from several other local files. We also want to pickle those by value so let’s get the list.

Parameters:

module_name – a module name we want the locally imported modules

Returns:

A list of local modules names imported within the provide module

generate_subclass(abc_cls: abc.ABCMeta, class_name: str, file_path: str) None[source]

Generate a subclass skeleton.

Implementing all abstract methods from abc_cls, written to file_path.

Parameters:
  • abc_cls – an ABC

  • class_name – the new subclass name

  • file_path – where to write the subclass