Skip to content

Commit

Permalink
test: fixups
Browse files Browse the repository at this point in the history
  • Loading branch information
eddiebergman committed Jan 8, 2025
1 parent b764ccf commit 0c7f66f
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 4 deletions.
2 changes: 2 additions & 0 deletions tests/test_runtime/test_default_report_values.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ def test_default_values_on_not_specified(
max_wallclock_time_for_worker_seconds=None,
max_evaluation_time_for_worker_seconds=None,
max_cost_for_worker=None,
batch_size=None,
)

def eval_function(*args, **kwargs) -> float:
Expand Down Expand Up @@ -146,6 +147,7 @@ def test_default_value_objective_to_minimize_curve_take_objective_to_minimize_va
max_wallclock_time_for_worker_seconds=None,
max_evaluation_time_for_worker_seconds=None,
max_cost_for_worker=None,
batch_size=None,
)

LOSS = 1.0
Expand Down
3 changes: 3 additions & 0 deletions tests/test_runtime/test_error_handling_strategies.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def test_worker_raises_when_error_in_self(
max_wallclock_time_for_worker_seconds=None,
max_evaluation_time_for_worker_seconds=None,
max_cost_for_worker=None,
batch_size=None,
)

def eval_function(*args, **kwargs) -> float:
Expand Down Expand Up @@ -92,6 +93,7 @@ def test_worker_raises_when_error_in_other_worker(neps_state: NePSState) -> None
max_wallclock_time_for_worker_seconds=None,
max_evaluation_time_for_worker_seconds=None,
max_cost_for_worker=None,
batch_size=None,
)

def evaler(*args, **kwargs) -> float:
Expand Down Expand Up @@ -153,6 +155,7 @@ def test_worker_does_not_raise_when_error_in_other_worker(
max_wallclock_time_for_worker_seconds=None,
max_evaluation_time_for_worker_seconds=None,
max_cost_for_worker=None,
batch_size=None,
)

@dataclass
Expand Down
8 changes: 8 additions & 0 deletions tests/test_runtime/test_stopping_criterion.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def test_max_evaluations_total_stopping_criterion(
max_wallclock_time_for_worker_seconds=None,
max_evaluation_time_for_worker_seconds=None,
max_cost_for_worker=None,
batch_size=None,
)

def eval_function(*args, **kwargs) -> float:
Expand Down Expand Up @@ -97,6 +98,7 @@ def test_worker_evaluations_total_stopping_criterion(
max_wallclock_time_for_worker_seconds=None,
max_evaluation_time_for_worker_seconds=None,
max_cost_for_worker=None,
batch_size=None,
)

def eval_function(*args, **kwargs) -> float:
Expand Down Expand Up @@ -159,6 +161,7 @@ def test_include_in_progress_evaluations_towards_maximum_with_work_eval_count(
max_wallclock_time_for_worker_seconds=None,
max_evaluation_time_for_worker_seconds=None,
max_cost_for_worker=None,
batch_size=None,
)

# We put in one trial as being inprogress
Expand Down Expand Up @@ -215,6 +218,7 @@ def test_max_cost_total(
max_wallclock_time_for_worker_seconds=None,
max_evaluation_time_for_worker_seconds=None,
max_cost_for_worker=None,
batch_size=None,
)

def eval_function(*args, **kwargs) -> dict:
Expand Down Expand Up @@ -266,6 +270,7 @@ def test_worker_cost_total(
max_wallclock_time_for_worker_seconds=None,
max_evaluation_time_for_worker_seconds=None,
max_cost_for_worker=2, # <- Highlight, only 2 maximum evaluations allowed
batch_size=None,
)

def eval_function(*args, **kwargs) -> dict:
Expand Down Expand Up @@ -325,6 +330,7 @@ def test_worker_wallclock_time(
max_wallclock_time_for_worker_seconds=1, # <- highlight, 1 second
max_evaluation_time_for_worker_seconds=None,
max_cost_for_worker=None,
batch_size=None,
)

def eval_function(*args, **kwargs) -> float:
Expand Down Expand Up @@ -383,6 +389,7 @@ def test_max_worker_evaluation_time(
max_wallclock_time_for_worker_seconds=None,
max_evaluation_time_for_worker_seconds=0.5,
max_cost_for_worker=None,
batch_size=None,
)

def eval_function(*args, **kwargs) -> float:
Expand Down Expand Up @@ -442,6 +449,7 @@ def test_max_evaluation_time_global(
max_wallclock_time_for_worker_seconds=None,
max_evaluation_time_for_worker_seconds=None,
max_cost_for_worker=None,
batch_size=None,
)

def eval_function(*args, **kwargs) -> float:
Expand Down
15 changes: 14 additions & 1 deletion tests/test_settings/test_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"pre_load_hooks": Default(None),
"searcher": Default("default"),
"searcher_kwargs": {},
"sample_batch_size": Default(None),
},
Default(None),
{
Expand All @@ -65,6 +66,7 @@
"pre_load_hooks": None,
"searcher": "default",
"searcher_kwargs": {},
"sample_batch_size": None,
},
),
(
Expand All @@ -87,6 +89,7 @@
"pre_load_hooks": Default(None),
"searcher": Default("default"),
"searcher_kwargs": {},
"sample_batch_size": Default(None),
},
"run_args_required.yaml",
{
Expand All @@ -107,6 +110,7 @@
"pre_load_hooks": None,
"searcher": "default",
"searcher_kwargs": {},
"sample_batch_size": None,
},
),
(
Expand All @@ -129,6 +133,7 @@
"pre_load_hooks": Default(None),
"searcher": Default("default"),
"searcher_kwargs": {},
"sample_batch_size": Default(None),
},
"run_args_optional.yaml",
{
Expand All @@ -149,6 +154,7 @@
"pre_load_hooks": None,
"searcher": "hyperband",
"searcher_kwargs": {},
"sample_batch_size": None,
},
),
(
Expand All @@ -171,6 +177,7 @@
"pre_load_hooks": None,
"searcher": "default",
"searcher_kwargs": {},
"sample_batch_size": Default(None),
},
"overwrite_run_args.yaml",
{
Expand All @@ -191,6 +198,7 @@
"pre_load_hooks": None,
"searcher": "default",
"searcher_kwargs": {},
"sample_batch_size": None,
},
),
(
Expand Down Expand Up @@ -219,6 +227,7 @@
"sample_prior_first": False,
"sample_prior_at_target": False,
},
"sample_batch_size": Default(None),
},
"run_args_optimizer_settings.yaml",
{
Expand Down Expand Up @@ -253,6 +262,7 @@
"sample_prior_first": False,
"sample_prior_at_target": False,
},
"sample_batch_size": None,
},
),
(
Expand All @@ -277,6 +287,7 @@
"searcher_kwargs": {
"initial_design_size": 9,
},
"sample_batch_size": Default(None),
},
"run_args_optimizer_outside.yaml",
{
Expand All @@ -297,6 +308,7 @@
"pre_load_hooks": None,
"searcher": my_bayesian,
"searcher_kwargs": {"initial_design_size": 9},
"sample_batch_size": None,
},
),
],
Expand Down Expand Up @@ -333,14 +345,15 @@ def test_check_settings(func_args: dict, yaml_args: str, expected_output: dict)
"pre_load_hooks": Default(None),
"searcher": Default("default"),
"searcher_kwargs": {},
"sample_batch_size": Default(None),
},
Default(None),
ValueError,
)
],
)
def test_settings_initialization_error(
func_args: dict, yaml_args: str | Default, error: Exception
func_args: dict, yaml_args: str | Default, error: type[Exception]
) -> None:
"""Test if Settings raises Error when essential arguments are missing."""
with pytest.raises(error):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ def test_run_with_yaml(config: dict) -> None:
pytest.fail(f"NePS run failed for configuration: {file_name}")

if check_optimizer:
optimizer_path = config.pop("optimizer_path")
result_path = config.pop("result_path")
optimizer_path = Path(config.pop("optimizer_path"))
result_path = Path(config.pop("result_path"))
compare_generated_yaml(result_path, optimizer_path)


def compare_generated_yaml(result_path, optimizer_path):
def compare_generated_yaml(result_path: Path, optimizer_path: Path) -> None:
"""Compare generated optimizer settings and solution settings."""
assert result_path.exists(), "Generated YAML file does not exist."

Expand Down

0 comments on commit 0c7f66f

Please sign in to comment.