9
9
import logging
10
10
import sys
11
11
from pathlib import Path
12
- from typing import Any , Callable
12
+ from typing import Callable
13
13
14
14
import yaml
15
15
@@ -45,13 +45,13 @@ def get_run_args_from_yaml(path: str) -> dict:
45
45
"""Load and validate NEPS run arguments from a specified YAML configuration file
46
46
provided via run_args.
47
47
48
- This function reads a YAML file, extracts the arguments required by NEPS ,
48
+ This function reads a YAML file, extracts the arguments required by NePS ,
49
49
validates these arguments, and then returns them in a dictionary. It checks for the
50
50
presence and validity of expected parameters, and distinctively handles more complex
51
51
configurations, specifically those that are dictionaries(e.g. pipeline_space) or
52
52
objects(e.g. run_pipeline) requiring loading.
53
53
54
- Parameters :
54
+ Args :
55
55
path (str): The file path to the YAML configuration file.
56
56
57
57
Returns:
@@ -66,7 +66,7 @@ def get_run_args_from_yaml(path: str) -> dict:
66
66
# Initialize an empty dictionary to hold the extracted settings
67
67
settings = {}
68
68
69
- # List allowed NEPS run arguments with simple types (e.g., string, int). Parameters
69
+ # List allowed NePS run arguments with simple types (e.g., string, int). Parameters
70
70
# like 'run_pipeline', 'preload_hooks', 'pipeline_space',
71
71
# and 'searcher' are excluded due to needing specialized processing.
72
72
expected_parameters = [
@@ -119,22 +119,15 @@ def get_run_args_from_yaml(path: str) -> dict:
119
119
def config_loader (path : str ) -> dict :
120
120
"""Loads a YAML file and returns the contents under the 'run_args' key.
121
121
122
- Validates the existence and format of the YAML file and checks for the presence of
123
- the 'run_args' as the only top level key. If any conditions are not met,
124
- raises an
125
- exception with a helpful message.
126
-
127
122
Args:
128
123
path (str): Path to the YAML file.
129
124
130
125
Returns:
131
- dict: Contents under the 'run_args' key.
126
+ Content of the yaml (dict)
132
127
133
128
Raises:
134
129
FileNotFoundError: If the file at 'path' does not exist.
135
130
ValueError: If the file is not a valid YAML.
136
- KeyError: If 'run_args' key is missing.
137
- KeyError: If 'run_args' is not the only top level key
138
131
"""
139
132
try :
140
133
with open (path ) as file : # noqa: PTH123
@@ -156,10 +149,13 @@ def extract_leaf_keys(d: dict, special_keys: dict | None = None) -> tuple[dict,
156
149
Special keys (e.g.'run_pipeline') are also extracted if present
157
150
and their corresponding values (dict) at any level in the nested structure.
158
151
159
- :param d: The dictionary to extract values from.
160
- :param special_keys: A dictionary to store values of special keys.
161
- :return: A tuple containing the leaf keys dictionary and the dictionary for
162
- special keys.
152
+ Args:
153
+ d (dict): The dictionary to extract values from.
154
+ special_keys (dict|None): A dictionary to store values of special keys.
155
+
156
+ Returns:
157
+ A tuple containing the leaf keys dictionary and the dictionary for
158
+ special keys.
163
159
"""
164
160
if special_keys is None :
165
161
special_keys = {
@@ -191,14 +187,11 @@ def handle_special_argument_cases(settings: dict, special_configs: dict) -> None
191
187
configurations like 'pre_load_hooks' which need individual processing or function
192
188
loading.
193
189
194
- Parameters :
195
- - settings (dict): The dictionary to be updated with processed configurations.
196
- - special_configs (dict): A dictionary containing configuration keys and values
190
+ Args :
191
+ settings (dict): The dictionary to be updated with processed configurations.
192
+ special_configs (dict): A dictionary containing configuration keys and values
197
193
that require special processing.
198
194
199
- Returns:
200
- - None: The function modifies 'settings' in place.
201
-
202
195
"""
203
196
# process special configs
204
197
process_run_pipeline (RUN_PIPELINE , special_configs , settings )
@@ -261,13 +254,13 @@ def process_searcher(key: str, special_configs: dict, settings: dict) -> None:
261
254
Checks if the key exists in special_configs. If found, it processes the
262
255
value based on its type. Updates settings with the processed searcher.
263
256
264
- Parameters :
265
- key (str): Key to look up in special_configs.
266
- special_configs (dict): Dictionary of special configurations.
267
- settings (dict): Dictionary to update with the processed searcher.
257
+ Args :
258
+ key (str): Key to look up in special_configs.
259
+ special_configs (dict): Dictionary of special configurations.
260
+ settings (dict): Dictionary to update with the processed searcher.
268
261
269
262
Raises:
270
- TypeError: If the value for the key is neither a string, Path, nor a dictionary.
263
+ TypeError: If the value for the key is neither a string, Path, nor a dictionary.
271
264
"""
272
265
if special_configs .get (key ) is not None :
273
266
searcher = special_configs [key ]
@@ -294,13 +287,13 @@ def process_searcher(key: str, special_configs: dict, settings: dict) -> None:
294
287
def process_run_pipeline (key : str , special_configs : dict , settings : dict ) -> None :
295
288
"""Processes the run pipeline configuration and updates the settings dictionary.
296
289
297
- Parameters :
298
- key (str): Key to look up in special_configs.
299
- special_configs (dict): Dictionary of special configurations.
300
- settings (dict): Dictionary to update with the processed function.
290
+ Args :
291
+ key (str): Key to look up in special_configs.
292
+ special_configs (dict): Dictionary of special configurations.
293
+ settings (dict): Dictionary to update with the processed function.
301
294
302
295
Raises:
303
- KeyError: If required keys ('path' and 'name') are missing in the config.
296
+ KeyError: If required keys ('path' and 'name') are missing in the config.
304
297
"""
305
298
if special_configs .get (key ) is not None :
306
299
config = special_configs [key ]
@@ -403,7 +396,7 @@ def check_run_args(settings: dict) -> None:
403
396
TypeError for type mismatches.
404
397
405
398
Args:
406
- settings (dict): NEPS configuration settings.
399
+ settings (dict): NePS configuration settings.
407
400
408
401
Raises:
409
402
TypeError: For mismatched setting value types.
@@ -462,14 +455,14 @@ def check_essential_arguments(
462
455
searcher : BaseOptimizer | None ,
463
456
run_args : str | None ,
464
457
) -> None :
465
- """Validates essential NEPS configuration arguments.
458
+ """Validates essential NePS configuration arguments.
466
459
467
460
Ensures 'run_pipeline', 'root_directory', 'pipeline_space', and either
468
461
'max_cost_total' or 'max_evaluation_total' are provided for NePS execution.
469
462
Raises ValueError with missing argument details. Additionally, checks 'searcher'
470
463
is a BaseOptimizer if 'pipeline_space' is absent.
471
464
472
- Parameters :
465
+ Args :
473
466
run_pipeline: Function for the pipeline execution.
474
467
root_directory (str): Directory path for data storage.
475
468
pipeline_space: search space for this run.
@@ -499,19 +492,19 @@ def check_essential_arguments(
499
492
500
493
def check_double_reference (
501
494
func : Callable , func_arguments : dict , yaml_arguments : dict
502
- ) -> Any :
495
+ ) -> None :
503
496
"""Checks if no argument is defined both via function arguments and YAML.
504
497
505
- Parameters :
506
- - func (Callable): The function to check arguments against.
507
- - func_arguments (Dict): A dictionary containing the provided arguments to the
508
- function and their values.
509
- - yaml_arguments (Dict): A dictionary containing the arguments provided via a YAML
510
- file.
498
+ Args :
499
+ func (Callable): The function to check arguments against.
500
+ func_arguments (Dict): A dictionary containing the provided arguments to the
501
+ function and their values.
502
+ yaml_arguments (Dict): A dictionary containing the arguments provided via a YAML
503
+ file.
511
504
512
505
Raises:
513
- - ValueError: If any provided argument is defined both via function arguments and the
514
- YAML file.
506
+ ValueError: If any provided argument is defined both via function arguments and
507
+ the YAML file.
515
508
"""
516
509
sig = inspect .signature (func )
517
510
0 commit comments