mmgp.utils

Attributes

expected_structure

This dictionary defines the expected structure of a YAML configuration file.

Functions

load_backend(backend_module)

validate_configs(configs, v_structure[, depth_accumulator])

Recursively validate the structure and data types of a configuration dictionary.

read_configuration(→ dict[str, str])

Read and process the YAML configuration file specified during class initialization.

read_problem(→ plaid.problem_definition.ProblemDefinition)

Read and process problem definition data from a directory.

reset_folder(→ None)

Reset or create a folder by deleting its contents.

remove_file(→ None)

Remove a file if it exists.

print_setting(→ None)

Return a string representation of the settings in a readable format (pretty print).

Module Contents

mmgp.utils.expected_structure[source]

This dictionary defines the expected structure of a YAML configuration file. It specifies the keys that should be present in the configuration file and their expected data types.

mmgp.utils.load_backend(backend_module: str)[source]
mmgp.utils.validate_configs(configs: dict, v_structure: dict, depth_accumulator: str = '')[source]

Recursively validate the structure and data types of a configuration dictionary.

This function checks whether a given dictionary configs conforms to the expected structure and data types defined in the v_structure dictionary.

Parameters:
  • configs (dict) – The configuration dictionary to be validated.

  • v_structure (dict) – The expected structure.

  • depth_accumulator (str) – The path from the root of the concerned.

Returns:

True if the configs dictionary matches the expected structure

and data types; False otherwise.

Return type:

bool

mmgp.utils.read_configuration(config_file: str) dict[str, str][source]

Read and process the YAML configuration file specified during class initialization. It then defines the configuration details inside the class.

Parameters:

config_file (str) – The path to the YAML configuration file.

Returns:

A dictionary containing configuration information.

Return type:

dict[str,str]

Example

configuration = read_configuration('config.yaml')

Attention

  • Ensure that the configuration file exists at the specified path.

  • The method assumes that the configuration file is in YAML format.

mmgp.utils.read_problem(configuration: dict) plaid.problem_definition.ProblemDefinition[source]

Read and process problem definition data from a directory.

Parameters:

configuration (dict) – A dictionary containing configuration information.

Returns:

An instance of the ProblemDefinition class representing the problem.

Return type:

ProblemDefinition

Note

The fields: “init_dataset_location”, “zone_name” and “base_name” of the configuration file will be used to get and set the ‘problem definition’.

Attention

Ensure that the initial dataset and problem definition files exist at the specified path.

mmgp.utils.reset_folder(path: str) None[source]

Reset or create a folder by deleting its contents.

Parameters:

path (str) – The path to the folder to be reset or created.

Attention

Use this function with caution, as it permanently deletes the contents of the specified folder.

mmgp.utils.remove_file(path: str) None[source]

Remove a file if it exists.

Parameters:

path (str) – The path to the file to be removed.

Attention

Use this function with caution, as it permanently deletes the contents of the specified folder.

mmgp.utils.print_setting(configuration: dict, problem: plaid.problem_definition.ProblemDefinition) None[source]

Return a string representation of the settings in a readable format (pretty print).