experiment.utils module

General utilities.

experiment.utils.createResultFolder(results_folder: str = None, base_path: str = None, params: list = None, diff_file: bool = True, use_timestamp: bool = True, use_jobid: bool = True, postfix: str = None, strict_git: bool = False)[source]

Create Results Folder

This function creates a unique hierarchical results folder name. It is made of the git version and time stamp. It can also dump a diff log between the git version and the working copy at the time of run.

Parameters:
  • results_folder (Optional[str]) – Results folder. Useful when results folder exists and only storing of params is needed.
  • base_path (optional[str]) – Root name of the results folder.
  • params (optional[list]) – List of parameters of the run. Will be saved
  • txt file. (as) –
  • diff_file (optional[bool]) – Whether to save the diff log.
  • use_timestamp (optional[bool]) – Whether to add a timestamp to the path.
  • use_jobid (optional[bool]) – Whether to add a the jobid to the path.
  • postfix (optional[str]) – Last subfolder.
  • strict_git (optional[bool]) –
Returns:

Full path of results folder.

experiment.utils.getGitInfo(strict: bool = False) → Tuple[str, str][source]

Get version and diff information.

Parameters:
  • strict (bool, optional) – If True (default) will raise an exception when
  • are modified or un-tracked python files in the repository. (there) –
experiment.utils.getJOBID()[source]

Get the lsf job id.

experiment.utils.safe_mkdirs(path)[source]

Safely create path, warn in case of race.

Parameters:path (string) – Path to create.

Note

Race condition can happen when several instantiations of the same code run in parallel, e.g. mpi.

experiment.utils.setupLogging(log_path=None, file_name='script_log', log_level=20, logging_format='%(asctime)s [%(threadName)-12.12s] [%(levelname)-5.5s] %(message)s', custom_handlers=())[source]

Initialize the logger. Single process version. Logs both to file and stderr.