Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ version = {attr = "optuna_integration.version.__version__"}

[tool.black]
line-length = 99
target-version = ['py38']
target-version = ['py39']
exclude = '''
/(
\.eggs
Expand Down
11 changes: 6 additions & 5 deletions tests/botorch/test_botorch.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,11 +476,12 @@ def test_botorch_n_startup_trials() -> None:
sampler = BoTorchSampler(n_startup_trials=2, independent_sampler=independent_sampler)
study = optuna.create_study(directions=["minimize", "maximize"], sampler=sampler)

with patch.object(
independent_sampler, "sample_independent", wraps=independent_sampler.sample_independent
) as mock_independent, patch.object(
sampler, "sample_relative", wraps=sampler.sample_relative
) as mock_relative:
with (
patch.object(
independent_sampler, "sample_independent", wraps=independent_sampler.sample_independent
) as mock_independent,
patch.object(sampler, "sample_relative", wraps=sampler.sample_relative) as mock_relative,
):
study.optimize(
lambda t: [t.suggest_float("x0", 0, 1), t.suggest_float("x1", 0, 1)], n_trials=3
)
Expand Down
17 changes: 10 additions & 7 deletions tests/cma/test_cma.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,16 @@ def test_sample_relative_n_startup_trials() -> None:

# The independent sampler is used for Trial#0 and Trial#1.
# The CMA-ES is used for Trial#2.
with patch.object(
independent_sampler,
"sample_independent",
wraps=independent_sampler.sample_independent,
) as mock_independent, patch.object(
sampler, "sample_relative", wraps=sampler.sample_relative
) as mock_relative:
with (
patch.object(
independent_sampler,
"sample_independent",
wraps=independent_sampler.sample_independent,
) as mock_independent,
patch.object(
sampler, "sample_relative", wraps=sampler.sample_relative
) as mock_relative,
):
study.optimize(
lambda t: t.suggest_int("x", -1, 1) + t.suggest_int("y", -1, 1),
n_trials=3,
Expand Down
24 changes: 14 additions & 10 deletions tests/lightgbm/test_optimize.py
Original file line number Diff line number Diff line change
Expand Up @@ -512,17 +512,19 @@ def test_when_a_step_does_not_improve_best_score(self) -> None:
tuner = LightGBMTuner(params, dataset, valid_sets=valid_sets)
assert not tuner.higher_is_better()

with mock.patch("lightgbm.train"), mock.patch.object(
_BaseTuner, "_get_booster_best_score", return_value=0.9
with (
mock.patch("lightgbm.train"),
mock.patch.object(_BaseTuner, "_get_booster_best_score", return_value=0.9),
):
tuner.tune_feature_fraction()

assert "feature_fraction" in tuner.best_params
assert tuner.best_score == 0.9

# Assume that tuning `num_leaves` doesn't improve the `best_score`.
with mock.patch("lightgbm.train"), mock.patch.object(
_BaseTuner, "_get_booster_best_score", return_value=1.1
with (
mock.patch("lightgbm.train"),
mock.patch.object(_BaseTuner, "_get_booster_best_score", return_value=1.1),
):
tuner.tune_num_leaves()

Expand Down Expand Up @@ -562,9 +564,10 @@ def test_run_show_progress_bar(self, show_progress_bar: bool, expected: int) ->
show_progress_bar=show_progress_bar,
)

with mock.patch.object(
_BaseTuner, "_get_booster_best_score", return_value=1.0
), mock.patch("tqdm.tqdm") as mock_tqdm:
with (
mock.patch.object(_BaseTuner, "_get_booster_best_score", return_value=1.0),
mock.patch("tqdm.tqdm") as mock_tqdm,
):
tuner.run()

assert mock_tqdm.call_count == expected
Expand Down Expand Up @@ -918,9 +921,10 @@ def test_run_show_progress_bar(self, show_progress_bar: bool, expected: int) ->
params, dataset, study=study, time_budget=1, show_progress_bar=show_progress_bar
)

with mock.patch.object(
_OptunaObjectiveCV, "_get_cv_scores", return_value=[1.0]
), mock.patch("tqdm.tqdm") as mock_tqdm:
with (
mock.patch.object(_OptunaObjectiveCV, "_get_cv_scores", return_value=[1.0]),
mock.patch("tqdm.tqdm") as mock_tqdm,
):
tuner.run()

assert mock_tqdm.call_count == expected
Expand Down