kiwi.lib.utils

Module Contents

Functions

configure_seed(seed: int)

Configure the random seed for all relevant packages.

configure_logging(output_dir: Path = None, verbose: bool = False, quiet: bool = False)

Configure the output logger.

save_config_to_file(config: BaseConfig, file_name: Union[str, Path])

Save a configuration object to file.

setup_output_directory(output_dir, run_uuid=None, experiment_id=None, create=True) → str

Set up the output directory.

file_to_configuration(config_file: Union[str, Path]) → Dict

Utility function to handle converting a configuration file to

arguments_to_configuration(arguments: Dict) → Dict

Processes command line arguments into a dictionary.

_reset_hydra()

Utility function used to handle global hydra state

sort_by_second_value(tuples: List[tuple]) → List[tuple]

Sort a list of tuples by the second value in descending order.

kiwi.lib.utils.configure_seed(seed: int)

Configure the random seed for all relevant packages.

These include: random, numpy, torch, torch.cuda and PYTHONHASHSEED.

Parameters

seed – the random seed to be set.

kiwi.lib.utils.configure_logging(output_dir: Path = None, verbose: bool = False, quiet: bool = False)

Configure the output logger.

Set up the log format, logging level, and output directory of logging.

Parameters
  • output_dir – the directory where log output will be stored; defaults to None.

  • verbose – change logging level to debug.

  • quiet – change logging level to warning to suppress info logs.

kiwi.lib.utils.save_config_to_file(config: BaseConfig, file_name: Union[str, Path])

Save a configuration object to file.

Parameters
  • file_name – where to saved the configuration.

  • config – a pydantic configuration object.

kiwi.lib.utils.setup_output_directory(output_dir, run_uuid=None, experiment_id=None, create=True)str

Set up the output directory.

This means either creating one, or verifying that the provided directory exists. Output directories are created using the run and experiment ids.

Parameters
  • output_dir – the target output directory.

  • run_uuid – the hash of the current run.

  • experiment_id – the id of the current experiment.

  • create – whether to create the directory.

Returns

the path to the resolved output directory.

kiwi.lib.utils.file_to_configuration(config_file: Union[str, Path]) → Dict

Utility function to handle converting a configuration file to a dictionary with the correct hydra composition.

Creates an argument dict and calls arguments_to_configuration

Parameters

config_file – path to a configuration file.

Returns

Dictionary of the configuration imported from config file.

kiwi.lib.utils.arguments_to_configuration(arguments: Dict) → Dict

Processes command line arguments into a dictionary. Handles hydra file composition and parameter overwrites.

Parameters

arguments – dictionary with all the cmd_line arguments passed to kiwi.

Returns

Dictionary of the config imported from the config file.

kiwi.lib.utils._reset_hydra()

Utility function used to handle global hydra state

kiwi.lib.utils.sort_by_second_value(tuples: List[tuple]) → List[tuple]

Sort a list of tuples by the second value in descending order.