Yaml search space utils
neps.search_spaces.yaml_search_space_utils
#
SearchSpaceFromYamlFileError
#
SearchSpaceFromYamlFileError(exception: Exception)
Bases: Exception
Exception raised for errors occurring during the initialization of the search space from a YAML file.
ATTRIBUTE | DESCRIPTION |
---|---|
exception_type |
The type of the original exception.
TYPE:
|
message |
A detailed message that includes the type of the original exception and the error description.
TYPE:
|
PARAMETER | DESCRIPTION |
---|---|
exception
|
The original exception that was raised during the initialization of the search space from the YAML file.
TYPE:
|
Example Usage
try: # Code to initialize search space from YAML file except (KeyError, TypeError, ValueError) as e: raise SearchSpaceFromYamlFileError(e)
Source code in neps/search_spaces/yaml_search_space_utils.py
convert_scientific_notation
#
convert_scientific_notation(
value: str | int | float, show_usage_flag: bool = False
) -> float | tuple[float, bool]
Convert a given value to a float if it's a string that matches scientific e notation. This is especially useful for numbers like "3.3e-5" which YAML parsers may not directly interpret as floats.
If the 'show_usage_flag' is set to True, the function returns a tuple of the float conversion and a boolean flag indicating whether scientific notation was detected.
PARAMETER | DESCRIPTION |
---|---|
value
|
The value to convert. Can be an integer, float, or a string representing a number, possibly in scientific notation. |
show_usage_flag
|
Optional; defaults to False. If True, the function also returns a flag indicating whether scientific notation was detected in the string.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
float
|
The value converted to float if 'show_usage_flag' is False. (float, bool): A tuple containing the value converted to float and a flag indicating scientific notation detection if 'show_usage_flag' is True. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the value is a string and does not represent a valid number. |
Source code in neps/search_spaces/yaml_search_space_utils.py
deduce_param_type
#
Deduces the parameter type based on the provided details.
The function interprets the 'details' dictionary to determine the parameter type. The dictionary should include key-value pairs that describe the parameter's characteristics, such as lower, upper and choices.
PARAMETER | DESCRIPTION |
---|---|
name
|
The name of the parameter.
TYPE:
|
details
|
A dictionary containing parameter |
RETURNS | DESCRIPTION |
---|---|
str
|
The deduced parameter type ('int', 'float' or 'categorical').
TYPE:
|
RAISES | DESCRIPTION |
---|---|
TypeError
|
If the parameter type cannot be deduced from the details, or if the |
Example
param_type = deduce_param_type('example_param', {'lower': 0, 'upper': 10})
Source code in neps/search_spaces/yaml_search_space_utils.py
deduce_type
#
Deduces the parameter type from details.
PARAMETER | DESCRIPTION |
---|---|
name
|
The name of the parameter.
TYPE:
|
details
|
A dictionary containing parameter specifications or a direct value (string, integer, or float). |
RETURNS | DESCRIPTION |
---|---|
str
|
The deduced parameter type ('int', 'float', 'categorical', or 'constant'). |
RAISES | DESCRIPTION |
---|---|
TypeError
|
If the type cannot be deduced or the details don't align with expected constraints. |
Source code in neps/search_spaces/yaml_search_space_utils.py
formatting_cat
#
This function ensures that the 'choices' key in the details is a list and attempts to convert any elements expressed in scientific notation to floats. It also handles the 'default' value, converting it from scientific notation if necessary.
PARAMETER | DESCRIPTION |
---|---|
name
|
The name of the categorical parameter.
TYPE:
|
details
|
A dictionary containing the parameter's specifications. The required key is 'choices', which must be a list. The 'default' key is optional. |
RAISES | DESCRIPTION |
---|---|
TypeError
|
If 'choices' is not a list. |
RETURNS | DESCRIPTION |
---|---|
dict
|
The validated and possibly converted categorical parameter details. |
Source code in neps/search_spaces/yaml_search_space_utils.py
formatting_const
#
Validates and converts a constant parameter.
This function checks if the 'details' parameter contains a value expressed in scientific notation and converts it to a float. It ensures that the input is appropriately formatted, either as a string, integer, or float.
PARAMETER | DESCRIPTION |
---|---|
details
|
A constant parameter that can be a string, integer, or float. If the value is in scientific notation, it will be converted to a float. |
RETURNS | DESCRIPTION |
---|---|
str | int | float
|
The validated and possibly converted constant parameter. |
Source code in neps/search_spaces/yaml_search_space_utils.py
formatting_float
#
Converts scientific notation values to floats.
This function converts the 'lower' and 'upper' bounds, as well as the 'default' value (if present), from scientific notation to floats.
PARAMETER | DESCRIPTION |
---|---|
name
|
The name of the float parameter.
TYPE:
|
details
|
A dictionary containing the parameter's specifications. Expected keys include 'lower', 'upper', and optionally 'default'. |
RAISES | DESCRIPTION |
---|---|
TypeError
|
If 'lower', 'upper', or 'default' cannot be converted from scientific notation to floats. |
RETURNS | DESCRIPTION |
---|---|
dict
|
The dictionary with the converted float parameter details. |
Source code in neps/search_spaces/yaml_search_space_utils.py
formatting_int
#
Converts scientific notation values to integers.
This function converts the 'lower' and 'upper' bounds, as well as the 'default' value (if present), from scientific notation to integers.
PARAMETER | DESCRIPTION |
---|---|
name
|
The name of the integer parameter.
TYPE:
|
details
|
A dictionary containing the parameter's specifications. Expected keys include 'lower', 'upper', and optionally 'default'. |
RAISES | DESCRIPTION |
---|---|
TypeError
|
If 'lower', 'upper', or 'default' cannot be converted from scientific notation to integers. |
RETURNS | DESCRIPTION |
---|---|
dict
|
The dictionary with the converted integer parameter details. |