Run args from yaml
neps.utils.run_args_from_yaml
#
check_arg_defaults
#
Checks if provided arguments deviate from default values defined in the function's signature.
Parameters: - func (Callable): The function to check arguments against. - provided_arguments: A dictionary containing the provided arguments and their values.
Raises: - ValueError: If any provided argument differs from its default value in the function signature.
Source code in neps/utils/run_args_from_yaml.py
check_essential_arguments
#
check_essential_arguments(
run_pipeline: Optional[Callable],
root_directory: Optional[str],
pipeline_space: Optional[dict],
max_cost_total: Optional[int],
max_evaluation_total: Optional[int],
searcher: Optional[BaseOptimizer],
run_args: Optional[str],
) -> None
Validates essential NEPS configuration arguments.
Ensures 'run_pipeline', 'root_directory', 'pipeline_space', and either 'max_cost_total' or 'max_evaluation_total' are provided for NePS execution. Raises ValueError with missing argument details. Additionally, checks 'searcher' is a BaseOptimizer if 'pipeline_space' is absent.
PARAMETER | DESCRIPTION |
---|---|
run_pipeline |
Function for the pipeline execution. |
root_directory |
Directory path for data storage.
TYPE:
|
pipeline_space |
search space for this run. |
max_cost_total |
Max allowed total cost for experiments. |
max_evaluation_total |
Max allowed evaluations. |
searcher |
Optimizer for the configuration space.
TYPE:
|
run_args |
A YAML file containing the configuration settings. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
Missing or invalid essential arguments. |
Source code in neps/utils/run_args_from_yaml.py
check_run_args
#
check_run_args(settings: Dict) -> None
Validates the types of NePS configuration settings.
Checks that each setting's value type matches its expected type. Raises TypeError for type mismatches.
PARAMETER | DESCRIPTION |
---|---|
settings |
NEPS configuration settings.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
TypeError
|
For mismatched setting value types. |
Source code in neps/utils/run_args_from_yaml.py
config_loader
#
Loads a YAML file and returns the contents under the 'run_args' key.
Validates the existence and format of the YAML file and checks for the presence of the 'run_args' as the only top level key. If any conditions are not met, raises an exception with a helpful message.
PARAMETER | DESCRIPTION |
---|---|
path |
Path to the YAML file.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
dict
|
Contents under the 'run_args' key.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
FileNotFoundError
|
If the file at 'path' does not exist. |
ValueError
|
If the file is not a valid YAML. |
KeyError
|
If 'run_args' key is missing. |
KeyError
|
If 'run_args' is not the only top level key |
Source code in neps/utils/run_args_from_yaml.py
extract_leaf_keys
#
Recursive function to extract leaf keys and their values from a nested dictionary. Special keys (e.g. 'searcher_kwargs', 'run_pipeline') are also extracted if present and their corresponding values (dict) at any level in the nested structure.
:param d: The dictionary to extract values from. :param special_keys: A dictionary to store values of special keys. :return: A tuple containing the leaf keys dictionary and the dictionary for special keys.
Source code in neps/utils/run_args_from_yaml.py
get_run_args_from_yaml
#
Load and validate NEPS run arguments from a specified YAML configuration file provided via run_args.
This function reads a YAML file, extracts the arguments required by NEPS, validates these arguments, and then returns them in a dictionary. It checks for the presence and validity of expected parameters, and distinctively handles more complex configurations, specifically those that are dictionaries(e.g. pipeline_space) or objects(e.g. run_pipeline) requiring loading.
PARAMETER | DESCRIPTION |
---|---|
path |
The file path to the YAML configuration file.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
dict
|
A dictionary of validated run arguments. |
RAISES | DESCRIPTION |
---|---|
KeyError
|
If any parameter name is invalid. |
Source code in neps/utils/run_args_from_yaml.py
handle_special_argument_cases
#
Process and integrate special configuration cases into the 'settings' dictionary.
This function updates 'settings' with values from 'special_configs'. It handles specific keys that require more complex processing, such as 'pipeline_space' and 'searcher', which may need to load a function/dict from paths. It also manages nested configurations like 'searcher_kwargs' and 'pre_load_hooks' which need individual processing or function loading.
Parameters: - settings (dict): The dictionary to be updated with processed configurations. - special_configs (dict): A dictionary containing configuration keys and values that require special processing.
Returns: - None: The function modifies 'settings' in place.
Source code in neps/utils/run_args_from_yaml.py
load_and_return_object
#
Dynamically loads an object from a given module file path.
This function attempts to dynamically import an object by its name from a specified module path. If the initial import fails, it retries with a '.py' extension appended to the path.
PARAMETER | DESCRIPTION |
---|---|
module_path |
File system path to the Python module.
TYPE:
|
object_name |
Name of the object to import from the module.
TYPE:
|
key |
Identifier for the argument causing the error, for enhanced error
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
object
|
The imported object from the module.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
ImportError
|
If the module or object cannot be found, with a message detailing |
Source code in neps/utils/run_args_from_yaml.py
load_hooks_from_config
#
Loads hook functions from configurations.
Iterates through a dictionary of pre-load hooks, dynamically imports each specified function by its 'path' and 'name', and accumulates the loaded functions into a list.
PARAMETER | DESCRIPTION |
---|---|
pre_load_hooks_dict |
Dictionary of hook configurations, each
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
list
|
List of loaded hook functions.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
KeyError
|
If any hook configuration lacks 'path' or 'name' keys. |
Source code in neps/utils/run_args_from_yaml.py
process_config_key
#
Enhance 'settings' by adding keys and their corresponding values or loaded objects from 'special_configs'. Keys in 'special_configs' are processed to directly insert their values into 'settings' or to load functions/objects using 'path' and 'name'. Key handling varies: 'RUN_PIPELINE' requires a dictionary defining a loadable function , whereas other keys may accept either strings or dictionaries
Parameters: - settings (dict): Dictionary to update. - special_configs (dict): Contains keys and values for processing. - keys (list): List of keys to process in 'special_configs'.
Raises: - KeyError: Missing 'path'/'name' for dictionaries. - TypeError: Incorrect type for key's value; RUN_PIPELINE must be a dict, others can be dict or string.