diff --git a/docs/doc_yamls/full_configuration_template.yaml b/docs/doc_yamls/full_configuration_template.yaml index c68b7570..ca6abf1a 100644 --- a/docs/doc_yamls/full_configuration_template.yaml +++ b/docs/doc_yamls/full_configuration_template.yaml @@ -22,7 +22,7 @@ max_cost_total: # Debug and Monitoring overwrite_working_directory: True -post_run_summary: True +post_run_summary: False development_stage_id: task_id: @@ -36,7 +36,7 @@ cost_value_on_error: ignore_errors: # Customization Options -searcher: bayesian_optimization # Internal key to select a NePS optimizer. +searcher: hyperband # Internal key to select a NePS optimizer. # Hooks pre_load_hooks: diff --git a/docs/reference/optimizers.md b/docs/reference/optimizers.md index 5838d974..927ebe14 100644 --- a/docs/reference/optimizers.md +++ b/docs/reference/optimizers.md @@ -59,18 +59,17 @@ The library will then load your custom settings and use them for optimization. Here's the format of a custom YAML (`custom_bo.yaml`) configuration using `Bayesian Optimization` as an example: ```yaml -searcher_init: - algorithm: bayesian_optimization -searcher_kwargs: # Specific arguments depending on the searcher - initial_design_size: 7 - surrogate_model: gp - acquisition: EI - log_prior_weighted: false - acquisition_sampler: random - random_interleave_prob: 0.1 - disable_priors: false - prior_confidence: high - sample_default_first: false +algorithm: bayesian_optimization +# Specific arguments depending on the searcher +initial_design_size: 7 +surrogate_model: gp +acquisition: EI +log_prior_weighted: false +acquisition_sampler: random +random_interleave_prob: 0.1 +disable_priors: false +prior_confidence: high +sample_default_first: false ``` ```python diff --git a/neps/api.py b/neps/api.py index 664c163f..9a5d47e9 100644 --- a/neps/api.py +++ b/neps/api.py @@ -10,7 +10,7 @@ import ConfigSpace as CS from neps.utils.run_args_from_yaml import check_essential_arguments, get_run_args_from_yaml,\ - check_arg_defaults + check_double_reference from neps.utils.common import instance_from_map from neps.runtime import launch_runtime @@ -221,46 +221,37 @@ def run( del searcher_kwargs["budget"] logger = logging.getLogger("neps") - # if arguments via run_args provided overwrite them if run_args: - # Check if the user provided other arguments directly to neps.run(). - # If so, raise an error. - check_arg_defaults(run, locals()) - - # Warning if the user has specified default values for arguments that differ - # from those specified in 'run_args'. These user-defined changes are not applied. - warnings.warn( - "WARNING: Loading arguments from 'run_args'. Arguments directly provided " - "to neps.run(...) will be not used!" - ) - optim_settings = get_run_args_from_yaml(run_args) + check_double_reference(run, locals(), optim_settings) - # Update each argument based on optim_settings. If not key is not provided in yaml - # use default value. Currently strict but will change in the future. - run_pipeline = optim_settings.get("run_pipeline", None) - root_directory = optim_settings.get("root_directory", None) - pipeline_space = optim_settings.get("pipeline_space", None) + run_pipeline = optim_settings.get("run_pipeline", run_pipeline) + root_directory = optim_settings.get("root_directory", root_directory) + pipeline_space = optim_settings.get("pipeline_space", pipeline_space) overwrite_working_directory = optim_settings.get( - "overwrite_working_directory", False + "overwrite_working_directory", overwrite_working_directory ) - post_run_summary = optim_settings.get("post_run_summary", False) - development_stage_id = optim_settings.get("development_stage_id", None) - task_id = optim_settings.get("task_id", None) - max_evaluations_total = optim_settings.get("max_evaluations_total", None) - max_evaluations_per_run = optim_settings.get("max_evaluations_per_run", None) + post_run_summary = optim_settings.get("post_run_summary", post_run_summary) + development_stage_id = optim_settings.get("development_stage_id", + development_stage_id) + task_id = optim_settings.get("task_id", task_id) + max_evaluations_total = optim_settings.get("max_evaluations_total", + max_evaluations_total) + max_evaluations_per_run = optim_settings.get("max_evaluations_per_run", + max_evaluations_per_run) continue_until_max_evaluation_completed = optim_settings.get( "continue_until_max_evaluation_completed", - False, - ) - max_cost_total = optim_settings.get("max_cost_total", None) - ignore_errors = optim_settings.get("ignore_errors", False) - loss_value_on_error = optim_settings.get("loss_value_on_error", None) - cost_value_on_error = optim_settings.get("cost_value_on_error", None) - pre_load_hooks = optim_settings.get("pre_load_hooks", None) - searcher = optim_settings.get("searcher", "default") - searcher_path = optim_settings.get("searcher_path", None) - for key, value in optim_settings.get("searcher_kwargs", {}).items(): + continue_until_max_evaluation_completed) + max_cost_total = optim_settings.get("max_cost_total", max_cost_total) + ignore_errors = optim_settings.get("ignore_errors", ignore_errors) + loss_value_on_error = optim_settings.get("loss_value_on_error", + loss_value_on_error) + cost_value_on_error = optim_settings.get("cost_value_on_error", + cost_value_on_error) + pre_load_hooks = optim_settings.get("pre_load_hooks", pre_load_hooks) + searcher = optim_settings.get("searcher", searcher) + searcher_path = optim_settings.get("searcher_path", searcher_path) + for key, value in optim_settings.get("searcher_kwargs", searcher_kwargs).items(): searcher_kwargs[key] = value # check if necessary arguments are provided. @@ -447,10 +438,11 @@ def _run_args( # Fetching the searcher data, throws an error when the searcher is not found config = get_searcher_data(searcher) - searcher_alg = config["searcher_init"]["algorithm"] - searcher_config = ( - {} if config["searcher_kwargs"] is None else config["searcher_kwargs"] - ) + if "algorithm" in config: + searcher_alg = config.pop("algorithm") + else: + raise KeyError(f"Missing key algorithm in searcher config:{config}") + searcher_config = config logger.info(f"Running {searcher} as the searcher") logger.info(f"Algorithm: {searcher_alg}") diff --git a/neps/optimizers/default_searchers/asha.yaml b/neps/optimizers/default_searchers/asha.yaml index 169adf36..8d914ad4 100644 --- a/neps/optimizers/default_searchers/asha.yaml +++ b/neps/optimizers/default_searchers/asha.yaml @@ -1,15 +1,13 @@ -searcher_init: - algorithm: asha -searcher_kwargs: - # Arguments that can be modified by the user - eta: 3 - early_stopping_rate: 0 - initial_design_type: max_budget - use_priors: false - random_interleave_prob: 0.0 - sample_default_first: false - sample_default_at_target: false +algorithm: asha +# Arguments that can be modified by the user +eta: 3 +early_stopping_rate: 0 +initial_design_type: max_budget +use_priors: false +random_interleave_prob: 0.0 +sample_default_first: false +sample_default_at_target: false - # Arguments that can not be modified by the user - # sampling_policy: RandomUniformPolicy - # promotion_policy: AsyncPromotionPolicy +# Arguments that can not be modified by the user +# sampling_policy: RandomUniformPolicy +# promotion_policy: AsyncPromotionPolicy diff --git a/neps/optimizers/default_searchers/asha_prior.yaml b/neps/optimizers/default_searchers/asha_prior.yaml index e43ecdd2..dc6852d1 100644 --- a/neps/optimizers/default_searchers/asha_prior.yaml +++ b/neps/optimizers/default_searchers/asha_prior.yaml @@ -1,15 +1,13 @@ -searcher_init: - algorithm: asha_prior -searcher_kwargs: - # Arguments that can be modified by the user - eta: 3 - early_stopping_rate: 0 - initial_design_type: max_budget - prior_confidence: medium # or {"low", "high"} - random_interleave_prob: 0.0 - sample_default_first: false - sample_default_at_target: false +algorithm: asha_prior +# Arguments that can be modified by the user +eta: 3 +early_stopping_rate: 0 +initial_design_type: max_budget +prior_confidence: medium # or {"low", "high"} +random_interleave_prob: 0.0 +sample_default_first: false +sample_default_at_target: false - # Arguments that can not be modified by the user - # sampling_policy: FixedPriorPolicy - # promotion_policy: AsyncPromotionPolicy +# Arguments that can not be modified by the user +# sampling_policy: FixedPriorPolicy +# promotion_policy: AsyncPromotionPolicy diff --git a/neps/optimizers/default_searchers/bayesian_optimization.yaml b/neps/optimizers/default_searchers/bayesian_optimization.yaml index ffc18c82..26d2c507 100644 --- a/neps/optimizers/default_searchers/bayesian_optimization.yaml +++ b/neps/optimizers/default_searchers/bayesian_optimization.yaml @@ -1,19 +1,17 @@ -searcher_init: - algorithm: bayesian_optimization -searcher_kwargs: - # Arguments that can be modified by the user - initial_design_size: 10 - surrogate_model: gp # or {"gp_hierarchy"} - acquisition: EI # or {"LogEI", "AEI"} - log_prior_weighted: false - acquisition_sampler: mutation # or {"random", "evolution"} - random_interleave_prob: 0.0 - disable_priors: true - sample_default_first: false +algorithm: bayesian_optimization +# Arguments that can be modified by the user +initial_design_size: 10 +surrogate_model: gp # or {"gp_hierarchy"} +acquisition: EI # or {"LogEI", "AEI"} +log_prior_weighted: false +acquisition_sampler: mutation # or {"random", "evolution"} +random_interleave_prob: 0.0 +disable_priors: true +sample_default_first: false - # Other arguments: - # surrogate_model_args: None # type: dict - # optimal_assignment: false # type: bool - # domain_se_kernel: None # type: str - # graph_kernels: None # type: list - # hp_kernels: None # type: list +# Other arguments: +# surrogate_model_args: None # type: dict +# optimal_assignment: false # type: bool +# domain_se_kernel: None # type: str +# graph_kernels: None # type: list +# hp_kernels: None # type: list diff --git a/neps/optimizers/default_searchers/hyperband.yaml b/neps/optimizers/default_searchers/hyperband.yaml index d3a16145..d39fb139 100644 --- a/neps/optimizers/default_searchers/hyperband.yaml +++ b/neps/optimizers/default_searchers/hyperband.yaml @@ -1,14 +1,12 @@ -searcher_init: - algorithm: hyperband -searcher_kwargs: - # Arguments that can be modified by the user - eta: 3 - initial_design_type: max_budget - use_priors: false - random_interleave_prob: 0.0 - sample_default_first: false - sample_default_at_target: false +algorithm: hyperband +# Arguments that can be modified by the user +eta: 3 +initial_design_type: max_budget +use_priors: false +random_interleave_prob: 0.0 +sample_default_first: false +sample_default_at_target: false - # Arguments that can not be modified by the user - # sampling_policy: RandomUniformPolicy - # promotion_policy: SyncPromotionPolicy +# Arguments that can not be modified by the user +# sampling_policy: RandomUniformPolicy +# promotion_policy: SyncPromotionPolicy diff --git a/neps/optimizers/default_searchers/mobster.yaml b/neps/optimizers/default_searchers/mobster.yaml index c016000b..385b74ad 100644 --- a/neps/optimizers/default_searchers/mobster.yaml +++ b/neps/optimizers/default_searchers/mobster.yaml @@ -1,27 +1,25 @@ -searcher_init: - algorithm: mobster -searcher_kwargs: - # Arguments that can be modified by the user - eta: 3 - initial_design_type: max_budget - use_priors: false - random_interleave_prob: 0.0 - sample_default_first: false - sample_default_at_target: false +algorithm: mobster +# Arguments that can be modified by the user +eta: 3 +initial_design_type: max_budget +use_priors: false +random_interleave_prob: 0.0 +sample_default_first: false +sample_default_at_target: false - # arguments for model - surrogate_model: gp # or {"gp_hierarchy"} - acquisition: EI # or {"LogEI", "AEI"} - log_prior_weighted: false - acquisition_sampler: random # or {"mutation", "evolution"} +# arguments for model +surrogate_model: gp # or {"gp_hierarchy"} +acquisition: EI # or {"LogEI", "AEI"} +log_prior_weighted: false +acquisition_sampler: random # or {"mutation", "evolution"} - # Arguments that can not be modified by the user - # sampling_policy: RandomUniformPolicy - # promotion_policy: AsyncPromotionPolicy - # model_policy: ModelPolicy +# Arguments that can not be modified by the user +# sampling_policy: RandomUniformPolicy +# promotion_policy: AsyncPromotionPolicy +# model_policy: ModelPolicy - # Other arguments - # surrogate_model_args: None # type: dict - # domain_se_kernel: None # type: str - # graph_kernels: None # type: list - # hp_kernels: None # type: list +# Other arguments +# surrogate_model_args: None # type: dict +# domain_se_kernel: None # type: str +# graph_kernels: None # type: list +# hp_kernels: None # type: list diff --git a/neps/optimizers/default_searchers/pibo.yaml b/neps/optimizers/default_searchers/pibo.yaml index 8c4fecf6..b75a23f3 100644 --- a/neps/optimizers/default_searchers/pibo.yaml +++ b/neps/optimizers/default_searchers/pibo.yaml @@ -1,20 +1,18 @@ -searcher_init: - algorithm: bayesian_optimization -searcher_kwargs: - # Arguments that can be modified by the user - initial_design_size: 10 - surrogate_model: gp # or {"gp_hierarchy"} - acquisition: EI # or {"LogEI", "AEI"} - log_prior_weighted: false - acquisition_sampler: mutation # or {"random", "evolution"} - random_interleave_prob: 0.0 - disable_priors: false - prior_confidence: medium # or {"low", "high"} - sample_default_first: false +algorithm: bayesian_optimization +# Arguments that can be modified by the user +initial_design_size: 10 +surrogate_model: gp # or {"gp_hierarchy"} +acquisition: EI # or {"LogEI", "AEI"} +log_prior_weighted: false +acquisition_sampler: mutation # or {"random", "evolution"} +random_interleave_prob: 0.0 +disable_priors: false +prior_confidence: medium # or {"low", "high"} +sample_default_first: false - # Other arguments: - # surrogate_model_args: None # type: dict - # optimal_assignment: false # type: bool - # domain_se_kernel: None # type: str - # graph_kernels: None # type: list - # hp_kernels: None # type: list +# Other arguments: +# surrogate_model_args: None # type: dict +# optimal_assignment: false # type: bool +# domain_se_kernel: None # type: str +# graph_kernels: None # type: list +# hp_kernels: None # type: list diff --git a/neps/optimizers/default_searchers/priorband.yaml b/neps/optimizers/default_searchers/priorband.yaml index 9b11ae9a..f5a16f6f 100644 --- a/neps/optimizers/default_searchers/priorband.yaml +++ b/neps/optimizers/default_searchers/priorband.yaml @@ -1,22 +1,20 @@ -searcher_init: - algorithm: priorband -searcher_kwargs: - # Arguments that can be modified by the user - eta: 3 - initial_design_type: max_budget - prior_confidence: medium # or {"low", "high"} - random_interleave_prob: 0.0 - sample_default_first: true - sample_default_at_target: false - prior_weight_type: geometric - inc_sample_type: mutation - inc_mutation_rate: 0.5 - inc_mutation_std: 0.25 - inc_style: dynamic +algorithm: priorband +# Arguments that can be modified by the user +eta: 3 +initial_design_type: max_budget +prior_confidence: medium # or {"low", "high"} +random_interleave_prob: 0.0 +sample_default_first: true +sample_default_at_target: false +prior_weight_type: geometric +inc_sample_type: mutation +inc_mutation_rate: 0.5 +inc_mutation_std: 0.25 +inc_style: dynamic - # arguments for model - model_based: false # crucial argument to set to allow model-search +# arguments for model +model_based: false # crucial argument to set to allow model-search - # Arguments that can not be modified by the user - # sampling_policy: EnsemblePolicy - # promotion_policy: SyncPromotionPolicy +# Arguments that can not be modified by the user +# sampling_policy: EnsemblePolicy +# promotion_policy: SyncPromotionPolicy diff --git a/neps/optimizers/default_searchers/priorband_bo.yaml b/neps/optimizers/default_searchers/priorband_bo.yaml index 04e530c1..134ff78c 100644 --- a/neps/optimizers/default_searchers/priorband_bo.yaml +++ b/neps/optimizers/default_searchers/priorband_bo.yaml @@ -1,32 +1,30 @@ -searcher_init: - algorithm: priorband -searcher_kwargs: - # Arguments that can be modified by the user - eta: 3 - initial_design_type: max_budget - prior_confidence: medium # or {"low", "high"} - random_interleave_prob: 0.0 - sample_default_first: true - sample_default_at_target: false - prior_weight_type: geometric - inc_sample_type: mutation - inc_mutation_rate: 0.5 - inc_mutation_std: 0.25 - inc_style: dynamic +algorithm: priorband +# Arguments that can be modified by the user +eta: 3 +initial_design_type: max_budget +prior_confidence: medium # or {"low", "high"} +random_interleave_prob: 0.0 +sample_default_first: true +sample_default_at_target: false +prior_weight_type: geometric +inc_sample_type: mutation +inc_mutation_rate: 0.5 +inc_mutation_std: 0.25 +inc_style: dynamic - # arguments for model - model_based: true # crucial argument to set to allow model-search - modelling_type: joint - initial_design_size: 10 - surrogate_model: gp # or {"gp_hierarchy"} - acquisition: EI # or {"LogEI", "AEI"} - log_prior_weighted: false - acquisition_sampler: mutation # or {"random", "evolution"} +# arguments for model +model_based: true # crucial argument to set to allow model-search +modelling_type: joint +initial_design_size: 10 +surrogate_model: gp # or {"gp_hierarchy"} +acquisition: EI # or {"LogEI", "AEI"} +log_prior_weighted: false +acquisition_sampler: mutation # or {"random", "evolution"} - # Arguments that can not be modified by the user - # sampling_policy: EnsemblePolicy - # promotion_policy: SyncPromotionPolicy - # model_policy: ModelPolicy +# Arguments that can not be modified by the user +# sampling_policy: EnsemblePolicy +# promotion_policy: SyncPromotionPolicy +# model_policy: ModelPolicy # Other arguments # surrogate_model_args: None # type: dict diff --git a/neps/optimizers/default_searchers/random_search.yaml b/neps/optimizers/default_searchers/random_search.yaml index 745aeef5..848a7873 100644 --- a/neps/optimizers/default_searchers/random_search.yaml +++ b/neps/optimizers/default_searchers/random_search.yaml @@ -1,6 +1,4 @@ -searcher_init: - algorithm: random_search -searcher_kwargs: - # Arguments that can be modified by the user - use_priors: false - ignore_fidelity: true +algorithm: random_search +# Arguments that can be modified by the user +use_priors: false +ignore_fidelity: true diff --git a/neps/optimizers/default_searchers/regularized_evolution.yaml b/neps/optimizers/default_searchers/regularized_evolution.yaml index efb62a6a..0e298423 100644 --- a/neps/optimizers/default_searchers/regularized_evolution.yaml +++ b/neps/optimizers/default_searchers/regularized_evolution.yaml @@ -1,11 +1,9 @@ -searcher_init: - algorithm: regularized_evolution -searcher_kwargs: - # Arguments that can be modified by the user - population_size: 30 - sample_size: 10 - assisted: false +algorithm: regularized_evolution +# Arguments that can be modified by the user +population_size: 30 +sample_size: 10 +assisted: false - # Other arguments - # assisted_zero_cost_proxy: None # type: Callable - # assisted_init_population_dir: None # type: str | Path +# Other arguments +# assisted_zero_cost_proxy: None # type: Callable +# assisted_init_population_dir: None # type: str | Path diff --git a/neps/optimizers/default_searchers/successive_halving.yaml b/neps/optimizers/default_searchers/successive_halving.yaml index 17161685..148cbc69 100644 --- a/neps/optimizers/default_searchers/successive_halving.yaml +++ b/neps/optimizers/default_searchers/successive_halving.yaml @@ -1,15 +1,13 @@ -searcher_init: - algorithm: successive_halving -searcher_kwargs: - # Arguments that can be modified by the user - eta: 3 - early_stopping_rate: 0 - initial_design_type: max_budget - use_priors: false - random_interleave_prob: 0.0 - sample_default_first: false - sample_default_at_target: false +algorithm: successive_halving +# Arguments that can be modified by the user +eta: 3 +early_stopping_rate: 0 +initial_design_type: max_budget +use_priors: false +random_interleave_prob: 0.0 +sample_default_first: false +sample_default_at_target: false - # Arguments that can not be modified by the user - # sampling_policy: RandomUniformPolicy - # promotion_policy: SyncPromotionPolicy +# Arguments that can not be modified by the user +# sampling_policy: RandomUniformPolicy +# promotion_policy: SyncPromotionPolicy diff --git a/neps/optimizers/default_searchers/successive_halving_prior.yaml b/neps/optimizers/default_searchers/successive_halving_prior.yaml index f107940d..29b320dd 100644 --- a/neps/optimizers/default_searchers/successive_halving_prior.yaml +++ b/neps/optimizers/default_searchers/successive_halving_prior.yaml @@ -1,15 +1,13 @@ -searcher_init: - algorithm: successive_halving_prior -searcher_kwargs: - # Arguments that can be modified by the user - eta: 3 - early_stopping_rate: 0 - initial_design_type: max_budget - prior_confidence: medium # or {"low", "high"} - random_interleave_prob: 0.0 - sample_default_first: false - sample_default_at_target: false +algorithm: successive_halving_prior +# Arguments that can be modified by the user +eta: 3 +early_stopping_rate: 0 +initial_design_type: max_budget +prior_confidence: medium # or {"low", "high"} +random_interleave_prob: 0.0 +sample_default_first: false +sample_default_at_target: false - # Arguments that can not be modified by the user - # sampling_policy: FixedPriorPolicy - # promotion_policy: SyncPromotionPolicy +# Arguments that can not be modified by the user +# sampling_policy: FixedPriorPolicy +# promotion_policy: SyncPromotionPolicy diff --git a/neps/search_spaces/yaml_search_space_utils.py b/neps/search_spaces/yaml_search_space_utils.py index 8606a3e5..27c268e4 100644 --- a/neps/search_spaces/yaml_search_space_utils.py +++ b/neps/search_spaces/yaml_search_space_utils.py @@ -99,26 +99,16 @@ def deduce_type( TypeError: If the type cannot be deduced or the details don't align with expected constraints. """ - try: - # Deduce type + if isinstance(details, (str, int, float)): + param_type = "const" + elif isinstance(details, dict): if "type" in details: param_type = details.pop("type").lower() else: - # because details could be string - if isinstance(details, (str, int, float)): - param_type = "const" - return param_type - else: - param_type = deduce_param_type(name, details) - except TypeError as e: - # because details could be int, float - if isinstance(details, (str, int, float)): - param_type = "const" - return param_type - else: - raise TypeError( - f"Unable to deduce parameter type for '{name}' with details '{details}'.") \ - from e + param_type = deduce_param_type(name, details) + else: + raise TypeError( + f"Unable to deduce parameter type for '{name}' with details '{details}'.") return param_type diff --git a/neps/utils/run_args_from_yaml.py b/neps/utils/run_args_from_yaml.py index 1f290423..c67aded3 100644 --- a/neps/utils/run_args_from_yaml.py +++ b/neps/utils/run_args_from_yaml.py @@ -85,7 +85,11 @@ def get_run_args_from_yaml(path: str) -> dict: if parameter in expected_parameters: settings[parameter] = value else: - raise KeyError(f"Parameter '{parameter}' is not an argument of neps.run().") + raise KeyError(f"Parameter '{parameter}' is not an argument of neps.run() " + f"provided via run_args." + f"See here all valid arguments:" + f" {', '.join(expected_parameters)}, " + f"'run_pipeline', 'preload_hooks', 'pipeline_space'") # Process complex configurations (e.g., 'pipeline_space', 'searcher') and integrate # them into 'settings'. @@ -257,11 +261,28 @@ def process_config_key(settings: Dict, special_configs: Dict, keys: List) -> Non def process_pipeline_space(key, special_configs, settings): + """ + Process or load the pipeline space configuration. + + This function checks if the given key exists in the `special_configs` dictionary. + If it exists, it processes the associated value, which can be either a dictionary + or a string. Based on the keys of the dictionary it decides if the pipeline_space + have to be loaded or needs to be converted into a neps search_space structure. + The processed pipeline space is then stored in the `settings` + dictionary under the given key. + + Args: + key (str): The key to check in the `special_configs` dictionary. + special_configs (dict): The dictionary containing special configuration values. + settings (dict): The dictionary where the processed pipeline space will be stored. + + Raises: + TypeError: If the value associated with the key is neither a string nor a + dictionary. + """ if special_configs.get(key) is not None: pipeline_space = special_configs[key] if isinstance(pipeline_space, dict): - # TODO: was ist wenn ein argument fehlt - # determine if dict contains path_loading or the actual search space expected_keys = {"path", "name"} actual_keys = set(pipeline_space.keys()) @@ -346,32 +367,18 @@ def import_object(path): def load_hooks_from_config(pre_load_hooks_dict: Dict) -> List: """ - 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. + Loads hook functions from a dictionary of configurations. Args: - pre_load_hooks_dict (dict): Dictionary of hook configurations, each - containing 'path' and 'name' keys for the hook function. + pre_load_hooks_dict (Dict): Dictionary with hook names as keys and paths as values Returns: - list: List of loaded hook functions. - - Raises: - KeyError: If any hook configuration lacks 'path' or 'name' keys. + List: List of loaded hook functions. """ loaded_hooks = [] - for hook_config in pre_load_hooks_dict.values(): - if "path" in hook_config and "name" in hook_config: - hook_func = load_and_return_object(hook_config["path"], hook_config[ - "name"], PRE_LOAD_HOOKS) - loaded_hooks.append(hook_func) - else: - raise KeyError( - f"Expected keys 'path' and 'name' for hook, but got: " f"{hook_config}." - ) + for name, path in pre_load_hooks_dict.items(): + hook_func = load_and_return_object(path, name, PRE_LOAD_HOOKS) + loaded_hooks.append(hook_func) return loaded_hooks @@ -480,29 +487,34 @@ def check_essential_arguments( ) -def check_arg_defaults(func: Callable, provided_arguments: Dict) -> Any: +def check_double_reference(func: Callable, func_arguments: Dict, yaml_arguments: Dict) -> Any: """ - Checks if provided arguments deviate from default values defined in the function's - signature. + Checks if no argument is defined both via function arguments and YAML. Parameters: - func (Callable): The function to check arguments against. - - provided_arguments: A dictionary containing the provided arguments and their - values. + - func_arguments (Dict): A dictionary containing the provided arguments to the + function and their values. + - yaml_arguments (Dict): A dictionary containing the arguments provided via a YAML + file. Raises: - - ValueError: If any provided argument differs from its default value in the function - signature. + - ValueError: If any provided argument is defined both via function arguments and the + YAML file. """ sig = inspect.signature(func) + for name, param in sig.parameters.items(): - if param.default != provided_arguments[name]: + if param.default != func_arguments[name]: if name == RUN_ARGS: - # ignoring run_args argument + # Ignoring run_args argument continue if name == SEARCHER_KWARGS: # searcher_kwargs does not have a default specified by inspect - if provided_arguments[name] == {}: + if func_arguments[name] == {}: continue - raise ValueError( - f"Argument '{name}' must not be set directly when 'run_args' is used.") + if name in yaml_arguments: + raise ValueError( + f"Conflict for argument '{name}': Argument is defined both via " + f"function arguments and YAML, which is not allowed." + ) diff --git a/neps_examples/basic_usage/search_space_example.yaml b/neps_examples/basic_usage/search_space_example.yaml deleted file mode 100644 index e69de29b..00000000 diff --git a/neps_examples/yaml_usage/pipeline_space.yaml b/neps_examples/yaml_usage/pipeline_space.yaml index c052c7e8..bbc8715f 100644 --- a/neps_examples/yaml_usage/pipeline_space.yaml +++ b/neps_examples/yaml_usage/pipeline_space.yaml @@ -1,16 +1,15 @@ -pipeline_space: - epochs: - lower: 1 - upper: 5 - learning_rate: - lower: 1e-5 - upper: 1e-1 - log: True - num_layers: - lower: 1 - upper: 5 - optimizer: - choices: ["adam", "sgd"] - num_neurons: - lower: 64 - upper: 128 +epochs: + lower: 1 + upper: 5 +learning_rate: + lower: 1e-5 + upper: 1e-1 + log: True +num_layers: + lower: 1 + upper: 5 +optimizer: + choices: ["adam", "sgd"] +num_neurons: + lower: 64 + upper: 128 diff --git a/tests/test_neps_api/testing_yaml/optimizer_test.yaml b/tests/test_neps_api/testing_yaml/optimizer_test.yaml index 96c585a7..9d7e27f7 100644 --- a/tests/test_neps_api/testing_yaml/optimizer_test.yaml +++ b/tests/test_neps_api/testing_yaml/optimizer_test.yaml @@ -1,12 +1,11 @@ -searcher_init: - algorithm: bayesian_optimization -searcher_kwargs: # Specific arguments depending on the searcher - initial_design_size: 7 - surrogate_model: gp - acquisition: EI - log_prior_weighted: false - acquisition_sampler: random - random_interleave_prob: 0.1 - disable_priors: false - prior_confidence: high - sample_default_first: false +algorithm: bayesian_optimization +# Specific arguments depending on the searcher +initial_design_size: 7 +surrogate_model: gp +acquisition: EI +log_prior_weighted: false +acquisition_sampler: random +random_interleave_prob: 0.1 +disable_priors: false +prior_confidence: high +sample_default_first: false diff --git a/tests/test_yaml_run_args/run_args_full.yaml b/tests/test_yaml_run_args/run_args_full.yaml index 4c87974c..e9dc08eb 100644 --- a/tests/test_yaml_run_args/run_args_full.yaml +++ b/tests/test_yaml_run_args/run_args_full.yaml @@ -31,9 +31,5 @@ search: surrogate_model: gp pre_load_hooks: - hook1: - path: "tests/test_yaml_run_args/test_yaml_run_args.py" - name: hook1 - hook2: - path: "tests/test_yaml_run_args/test_yaml_run_args.py" - name: hook2 + hook1: "tests/test_yaml_run_args/test_yaml_run_args.py" + hook2: "tests/test_yaml_run_args/test_yaml_run_args.py" diff --git a/tests/test_yaml_run_args/run_args_full_same_level.yaml b/tests/test_yaml_run_args/run_args_full_same_level.yaml index e621c892..9e32b64d 100644 --- a/tests/test_yaml_run_args/run_args_full_same_level.yaml +++ b/tests/test_yaml_run_args/run_args_full_same_level.yaml @@ -20,6 +20,4 @@ searcher_kwargs: initial_design_size: 5 surrogate_model: gp pre_load_hooks: - hook1: - path: "tests/test_yaml_run_args/test_yaml_run_args" # check if without .py also works - name: hook1 + hook1: "tests/test_yaml_run_args/test_yaml_run_args" # check if without .py also works diff --git a/tests/test_yaml_run_args/run_args_invalid_key.yaml b/tests/test_yaml_run_args/run_args_invalid_key.yaml index b478abb1..6fc840ce 100644 --- a/tests/test_yaml_run_args/run_args_invalid_key.yaml +++ b/tests/test_yaml_run_args/run_args_invalid_key.yaml @@ -31,9 +31,5 @@ search: surrogate_model: gp pre_load_hooks: - hook1: - path: "tests/test_yaml_run_args/test_yaml_run_args.py" - name: hook1 - hook2: - path: "tests/test_yaml_run_args/test_yaml_run_args.py" - name: hook2 + hook1: "tests/test_yaml_run_args/test_yaml_run_args.py" + hook2: "tests/test_yaml_run_args/test_yaml_run_args.py" diff --git a/tests/test_yaml_run_args/run_args_key_missing.yaml b/tests/test_yaml_run_args/run_args_key_missing.yaml index db3ca836..704d1a2e 100644 --- a/tests/test_yaml_run_args/run_args_key_missing.yaml +++ b/tests/test_yaml_run_args/run_args_key_missing.yaml @@ -20,6 +20,4 @@ searcher_kwargs: initial_design_size: 5 surrogate_model: gp pre_load_hooks: - hook1: - path: "tests/test_yaml_run_args/test_yaml_run_args.py" - name: hook1 + hook1: "tests/test_yaml_run_args/test_yaml_run_args.py" diff --git a/tests/test_yaml_run_args/run_args_optional_loading_format.yaml b/tests/test_yaml_run_args/run_args_optional_loading_format.yaml index 510c655c..9c447806 100644 --- a/tests/test_yaml_run_args/run_args_optional_loading_format.yaml +++ b/tests/test_yaml_run_args/run_args_optional_loading_format.yaml @@ -24,6 +24,4 @@ searcher_kwargs: initial_design_size: 5 surrogate_model: gp pre_load_hooks: - hook1: - path: "tests/test_yaml_run_args/test_yaml_run_args.py" - name: hook1 + hook1: "tests/test_yaml_run_args/test_yaml_run_args.py" diff --git a/tests/test_yaml_run_args/run_args_wrong_name.yaml b/tests/test_yaml_run_args/run_args_wrong_name.yaml index 0b187332..c0b451c4 100644 --- a/tests/test_yaml_run_args/run_args_wrong_name.yaml +++ b/tests/test_yaml_run_args/run_args_wrong_name.yaml @@ -31,9 +31,5 @@ search: surrogate_model: gp pre_load_hooks: - hook1: - path: "tests/test_yaml_run_args/test_yaml_run_args.py" - name: hook1 - hook2: - path: "tests/test_yaml_run_args/test_yaml_run_args.py" - name: hook2 + hook1: "tests/test_yaml_run_args/test_yaml_run_args.py" + hook2: "tests/test_yaml_run_args/test_yaml_run_args.py" diff --git a/tests/test_yaml_run_args/run_args_wrong_path.yaml b/tests/test_yaml_run_args/run_args_wrong_path.yaml index 47abfe04..95254e69 100644 --- a/tests/test_yaml_run_args/run_args_wrong_path.yaml +++ b/tests/test_yaml_run_args/run_args_wrong_path.yaml @@ -31,9 +31,5 @@ search: surrogate_model: gp pre_load_hooks: - hook1: - path: "tests/test_yaml_run_args/test_yaml_run_args.py" - name: hook1 - hook2: - path: "tests/test_yaml_run_args/test_yaml_run_args.py" - name: hook2 + hook1: "tests/test_yaml_run_args/test_yaml_run_args.py" + hook2: "tests/test_yaml_run_args/test_yaml_run_args.py" diff --git a/tests/test_yaml_run_args/test_declarative_usage_docs/customizing_neps_optimizer.yaml b/tests/test_yaml_run_args/test_declarative_usage_docs/customizing_neps_optimizer.yaml index da1f4ca5..b079193e 100644 --- a/tests/test_yaml_run_args/test_declarative_usage_docs/customizing_neps_optimizer.yaml +++ b/tests/test_yaml_run_args/test_declarative_usage_docs/customizing_neps_optimizer.yaml @@ -1,6 +1,6 @@ run_pipeline: path: path/to/your/run_pipeline.py # Path to the function file - name: example_run # Function name within the file + name: example_pipeline # Function name within the file pipeline_space: learning_rate: @@ -19,10 +19,6 @@ searcher: initial_design_size: 7 surrogate_model: gp acquisition: EI - log_prior_weighted: false acquisition_sampler: random random_interleave_prob: 0.1 - disable_priors: false - prior_confidence: high - sample_default_first: false diff --git a/tests/test_yaml_run_args/test_declarative_usage_docs/defining_hooks.yaml b/tests/test_yaml_run_args/test_declarative_usage_docs/defining_hooks.yaml index d792f7d7..922bb542 100644 --- a/tests/test_yaml_run_args/test_declarative_usage_docs/defining_hooks.yaml +++ b/tests/test_yaml_run_args/test_declarative_usage_docs/defining_hooks.yaml @@ -1,20 +1,25 @@ # Basic NEPS Configuration Example run_pipeline: - path: path/to/your/run_pipeline.py # Path to the function file - name: example_run # Function name within the file + path: tests/test_yaml_run_args/test_declarative_usage_docs/run_pipeline.py + name: run_pipeline_constant pipeline_space: learning_rate: lower: 1e-5 upper: 1e-1 log: True # Log scale for learning rate + epochs: + lower: 5 + upper: 20 + is_fidelity: True optimizer: choices: [adam, sgd, adamw] - epochs: 50 + batch_size: 64 -root_directory: path/to/results # Directory for result storage +root_directory: path/to/results/hooks # Directory for result storage max_evaluations_total: 20 # Budget pre_load_hooks: - hook1: path/to/your/hooks.py # (function_name: Path to the function's file) - hook2: path/to/your/hooks.py # Different function name from the same file source + hook1: tests/test_yaml_run_args/test_declarative_usage_docs/hooks.py + +overwrite_working_directory: True diff --git a/tests/test_yaml_run_args/test_declarative_usage_docs/full_configuration_template.yaml b/tests/test_yaml_run_args/test_declarative_usage_docs/full_configuration_template.yaml index eee0b0fe..b79616a4 100644 --- a/tests/test_yaml_run_args/test_declarative_usage_docs/full_configuration_template.yaml +++ b/tests/test_yaml_run_args/test_declarative_usage_docs/full_configuration_template.yaml @@ -1,24 +1,28 @@ # Full Configuration Template for NePS run_pipeline: - path: tests/test_yaml_run_args/test_declarative_usage_docs/run_pipeline.py # Path to the Python file that contains your run_pipeline - name: run_pipeline # Name of your run_pipeline function within this file + path: tests/test_yaml_run_args/test_declarative_usage_docs/run_pipeline.py + name: run_pipeline_constant pipeline_space: learning_rate: lower: 1e-5 upper: 1e-1 - log: True + log: True # Log scale for learning rate + epochs: + lower: 5 + upper: 20 + is_fidelity: True optimizer: choices: [adam, sgd, adamw] - epochs: 50 + batch_size: 64 -root_directory: path/to/results # Directory for result storage +root_directory: path/to/results/full_config # Directory for result storage max_evaluations_total: 20 # Budget max_cost_total: # Debug and Monitoring overwrite_working_directory: True -post_run_summary: True +post_run_summary: False development_stage_id: task_id: @@ -32,7 +36,7 @@ cost_value_on_error: ignore_errors: # Customization Options -searcher: bayesian_optimization # Internal key to select a NePS optimizer. +searcher: hyperband # Internal key to select a NePS optimizer. # Hooks pre_load_hooks: diff --git a/tests/test_yaml_run_args/test_declarative_usage_docs/hooks.py b/tests/test_yaml_run_args/test_declarative_usage_docs/hooks.py new file mode 100644 index 00000000..a26f28f3 --- /dev/null +++ b/tests/test_yaml_run_args/test_declarative_usage_docs/hooks.py @@ -0,0 +1,8 @@ +def hook1(sampler): + """func to test loading of pre_load_hooks""" + return sampler + + +def hook2(sampler): + """func to test loading of pre_load_hooks""" + return sampler diff --git a/tests/test_yaml_run_args/test_declarative_usage_docs/loading_own_optimizer.yaml b/tests/test_yaml_run_args/test_declarative_usage_docs/loading_own_optimizer.yaml index 6174cd38..26897062 100644 --- a/tests/test_yaml_run_args/test_declarative_usage_docs/loading_own_optimizer.yaml +++ b/tests/test_yaml_run_args/test_declarative_usage_docs/loading_own_optimizer.yaml @@ -1,6 +1,6 @@ run_pipeline: path: path/to/your/run_pipeline.py # Path to the function file - name: example_run # Function name within the file + name: example_pipeline # Function name within the file pipeline_space: learning_rate: diff --git a/tests/test_yaml_run_args/test_declarative_usage_docs/loading_pipeline_space_dict.yaml b/tests/test_yaml_run_args/test_declarative_usage_docs/loading_pipeline_space_dict.yaml index f5f532e2..a8185c79 100644 --- a/tests/test_yaml_run_args/test_declarative_usage_docs/loading_pipeline_space_dict.yaml +++ b/tests/test_yaml_run_args/test_declarative_usage_docs/loading_pipeline_space_dict.yaml @@ -1,11 +1,11 @@ -# Basic NEPS Configuration Example +# Loading pipeline space from a python dict run_pipeline: path: path/to/your/run_pipeline.py # Path to the function file - name: example_run # Function name within the file + name: example_pipeline # Function name within the file pipeline_space: path: path/to/your/search_space.py # Path to the dict file - name: search_space # Name of the dict instance + name: pipeline_space # Name of the dict instance root_directory: path/to/results # Directory for result storage max_evaluations_total: 20 # Budget diff --git a/tests/test_yaml_run_args/test_declarative_usage_docs/neps_run.py b/tests/test_yaml_run_args/test_declarative_usage_docs/neps_run.py index 7829225d..16533af6 100644 --- a/tests/test_yaml_run_args/test_declarative_usage_docs/neps_run.py +++ b/tests/test_yaml_run_args/test_declarative_usage_docs/neps_run.py @@ -1,15 +1,7 @@ import argparse -import numpy as np import neps - - -def run_pipeline(learning_rate, optimizer, epochs): - """func for test loading of run_pipeline""" - if optimizer == "a": - eval_score = np.random.choice([learning_rate, epochs], 1) - else: - eval_score = 5.0 - return {"loss": eval_score} +from tests.test_yaml_run_args.test_declarative_usage_docs.run_pipeline import \ + run_pipeline_constant if __name__ == "__main__": @@ -17,5 +9,11 @@ def run_pipeline(learning_rate, optimizer, epochs): description="Run NEPS optimization with run_args.yml." ) parser.add_argument("run_args", type=str, help="Path to the YAML configuration file.") + parser.add_argument("--run_pipeline", action="store_true") args = parser.parse_args() - neps.run(run_args=args.run_args) + + if args.run_pipeline: + neps.run(run_args=args.run_args, run_pipeline=run_pipeline_constant) + else: + neps.run(run_args=args.run_args) + diff --git a/tests/test_yaml_run_args/test_declarative_usage_docs/outsourcing_optimizer.yaml b/tests/test_yaml_run_args/test_declarative_usage_docs/outsourcing_optimizer.yaml index 17bd4ab4..e6a3cea5 100644 --- a/tests/test_yaml_run_args/test_declarative_usage_docs/outsourcing_optimizer.yaml +++ b/tests/test_yaml_run_args/test_declarative_usage_docs/outsourcing_optimizer.yaml @@ -1,7 +1,7 @@ -# Basic NEPS Configuration Example +# Optimizer settings from YAML configuration run_pipeline: path: path/to/your/run_pipeline.py # Path to the function file - name: example_run # Function name within the file + name: example_pipeline # Function name within the file pipeline_space: learning_rate: diff --git a/tests/test_yaml_run_args/test_declarative_usage_docs/outsourcing_pipeline_space.yaml b/tests/test_yaml_run_args/test_declarative_usage_docs/outsourcing_pipeline_space.yaml index 75e50c30..68558569 100644 --- a/tests/test_yaml_run_args/test_declarative_usage_docs/outsourcing_pipeline_space.yaml +++ b/tests/test_yaml_run_args/test_declarative_usage_docs/outsourcing_pipeline_space.yaml @@ -1,6 +1,7 @@ +# Pipeline space settings from YAML run_pipeline: path: path/to/your/run_pipeline.py # Path to the function file - name: example_run # Function name within the file + name: example_pipeline # Function name within the file pipeline_space: path/to/your/pipeline_space.yaml diff --git a/tests/test_yaml_run_args/test_declarative_usage_docs/pipeline_space.yaml b/tests/test_yaml_run_args/test_declarative_usage_docs/pipeline_space.yaml index 5f416fbd..a4782db5 100644 --- a/tests/test_yaml_run_args/test_declarative_usage_docs/pipeline_space.yaml +++ b/tests/test_yaml_run_args/test_declarative_usage_docs/pipeline_space.yaml @@ -1,8 +1,22 @@ +# pipeline_space including priors and fidelity pipeline_space: learning_rate: lower: 1e-5 upper: 1e-1 log: True # Log scale for learning rate + default: 1e-2 + default_confidence: "medium" + epochs: + lower: 5 + upper: 20 + is_fidelity: True + dropout_rate: + lower: 0.1 + upper: 0.5 + default: 0.2 + default_confidence: "high" optimizer: choices: [adam, sgd, adamw] - epochs: 50 + default: adam + # default confidence low + batch_size: 64 diff --git a/tests/test_yaml_run_args/test_declarative_usage_docs/run_pipeline.py b/tests/test_yaml_run_args/test_declarative_usage_docs/run_pipeline.py index b0b26c3d..f44e6e71 100644 --- a/tests/test_yaml_run_args/test_declarative_usage_docs/run_pipeline.py +++ b/tests/test_yaml_run_args/test_declarative_usage_docs/run_pipeline.py @@ -9,3 +9,13 @@ def run_pipeline(learning_rate, optimizer, epochs): eval_score = 5.0 return {"loss": eval_score} + +def run_pipeline_constant(learning_rate, optimizer, epochs, batch_size): + """func for test loading of run_pipeline""" + if optimizer == "a": + eval_score = np.random.choice([learning_rate, epochs], 1) + else: + eval_score = 5.0 + eval_score += batch_size + return {"loss": eval_score} + diff --git a/tests/test_yaml_run_args/test_declarative_usage_docs/simple_example.yaml b/tests/test_yaml_run_args/test_declarative_usage_docs/simple_example.yaml index 77ceccb5..a167964c 100644 --- a/tests/test_yaml_run_args/test_declarative_usage_docs/simple_example.yaml +++ b/tests/test_yaml_run_args/test_declarative_usage_docs/simple_example.yaml @@ -3,10 +3,17 @@ pipeline_space: learning_rate: lower: 1e-5 upper: 1e-1 - log: True + log: True # Log scale for learning rate + epochs: + lower: 5 + upper: 20 + is_fidelity: True optimizer: choices: [adam, sgd, adamw] - epochs: 50 + batch_size: 64 -root_directory: path/to/results # Directory for result storage +root_directory: path/to/results/simple_example # Directory for result storage max_evaluations_total: 20 # Budget + + +overwrite_working_directory: True diff --git a/tests/test_yaml_run_args/test_declarative_usage_docs/simple_example_including_run_pipeline.yaml b/tests/test_yaml_run_args/test_declarative_usage_docs/simple_example_including_run_pipeline.yaml index d46f95f4..53cde312 100644 --- a/tests/test_yaml_run_args/test_declarative_usage_docs/simple_example_including_run_pipeline.yaml +++ b/tests/test_yaml_run_args/test_declarative_usage_docs/simple_example_including_run_pipeline.yaml @@ -1,16 +1,22 @@ -# Extended NePS Configuration Example with External Pipeline Function +# Simple NePS configuration including run_pipeline run_pipeline: path: tests/test_yaml_run_args/test_declarative_usage_docs/run_pipeline.py - name: run_pipeline + name: run_pipeline_constant pipeline_space: learning_rate: lower: 1e-5 upper: 1e-1 - log: True + log: True # Log scale for learning rate + epochs: + lower: 5 + upper: 20 + is_fidelity: True optimizer: choices: [adam, sgd, adamw] - epochs: 50 + batch_size: 64 -root_directory: path/to/results # Directory for result storage +root_directory: path/to/results/simple_example_including_run_pipeline # Directory for result storage max_evaluations_total: 20 # Budget + +overwrite_working_directory: True diff --git a/tests/test_yaml_run_args/test_declarative_usage_docs/test_declarative_usage_docs.py b/tests/test_yaml_run_args/test_declarative_usage_docs/test_declarative_usage_docs.py index c8459b6c..ad6d94f7 100644 --- a/tests/test_yaml_run_args/test_declarative_usage_docs/test_declarative_usage_docs.py +++ b/tests/test_yaml_run_args/test_declarative_usage_docs/test_declarative_usage_docs.py @@ -1,6 +1,6 @@ import pytest -import subprocess import os +import subprocess import sys BASE_PATH = "tests/test_yaml_run_args/test_declarative_usage_docs/" @@ -8,15 +8,38 @@ @pytest.mark.neps_api @pytest.mark.parametrize("yaml_file", [ "simple_example_including_run_pipeline.yaml", - "full_configuration_template.yaml" + "full_configuration_template.yaml", + "defining_hooks.yaml" ]) def test_run_with_yaml(yaml_file: str) -> None: - """Test "neps.run" with various run_args.yaml settings to simulate loading options - for variables.""" - assert os.path.exists(BASE_PATH + yaml_file), f"{yaml_file} does not exist." + """ + Test 'neps.run' with various run_args.yaml settings to simulate loading options + for variables. + """ + yaml_path = os.path.join(BASE_PATH, yaml_file) + assert os.path.exists(yaml_path), f"{yaml_file} does not exist." + + try: + subprocess.check_call( + [sys.executable, BASE_PATH + 'neps_run.py', yaml_path]) + except subprocess.CalledProcessError as e: + pytest.fail( + f"NePS run failed for configuration: {yaml_file} with error: {str(e)}") + + +@pytest.mark.neps_api +def test_run_with_yaml_and_run_pipeline() -> None: + """ + Test 'neps.run' with simple_example.yaml as run_args + a run_pipeline that is + provided separately. + """ + yaml_path = os.path.join(BASE_PATH, "simple_example.yaml") + assert os.path.exists(yaml_path), f"{yaml_path} does not exist." try: - subprocess.check_call([sys.executable, BASE_PATH + 'neps_run.py', BASE_PATH + - yaml_file]) - except subprocess.CalledProcessError: - pytest.fail(f"NePS run failed for configuration: {yaml_file}") + subprocess.check_call( + [sys.executable, BASE_PATH + 'neps_run.py', yaml_path, "--run_pipeline"] + ) + except subprocess.CalledProcessError as e: + pytest.fail( + f"NePS run failed for configuration: simple_example.yaml with error: {str(e)}") diff --git a/tests/test_yaml_run_args/test_yaml_run_args.py b/tests/test_yaml_run_args/test_yaml_run_args.py index c9d3901e..6ebb7ddc 100644 --- a/tests/test_yaml_run_args/test_yaml_run_args.py +++ b/tests/test_yaml_run_args/test_yaml_run_args.py @@ -12,7 +12,6 @@ batch_size=neps.ConstantParameter(value=64)) - def run_pipeline(): """func to test loading of run_pipeline""" return