Repository navigation
Add importance evaluator test cases to optuna.testing - #6765
Conversation
|
@kAIto47802 @c-bata Could you review this PR? |
c-bata
left a comment
There was a problem hiding this comment.
Looks almost good to me. I left one suggestion though.
Co-authored-by: c-bata <[email protected]>
c-bata
left a comment
There was a problem hiding this comment.
LGTM. Thank you for the update.
| assert param_importance["x"] > 0.0 | ||
| assert param_importance["y"] == 0.0 | ||
| class TestMultiObjectiveImportanceEvaluator(MultiObjectiveImportanceEvaluatorTestCase): | ||
| @pytest.fixture(params=ALL_EVALUATORS[2:]) |
There was a problem hiding this comment.
Currently, it is inconsistent with the way PedAnovaImportanceEvaluator is handled in TestConditionalImportanceEvaluator.
We should use the explicit construction here as well (cf. #6765 (comment))
| @pytest.fixture(params=ALL_EVALUATORS[2:]) | |
| @pytest.fixture(params=[pytest.param(_ped_anova_evaluator, id="PedAnovaImportanceEvaluator")]) |
| evaluator_cls: Callable[[], BaseImportanceEvaluator], normalize: bool | ||
| ) -> None: | ||
| def test_get_param_importances_unnormalized_experimental() -> None: | ||
| def objective(trial: Trial) -> float: |
There was a problem hiding this comment.
What about using
study = _get_study(seed=0, n_trials=3, is_multi_obj=False)here as well?
| study = create_study() | ||
| study.optimize(objective, n_trials=3) | ||
|
|
||
| with pytest.raises(ValueError): |
There was a problem hiding this comment.
The original comment has gone away
| with pytest.raises(ValueError): | |
| # None of the trials with `x2` are completed. | |
| with pytest.raises(ValueError): |
|
|
||
| with pytest.raises(ValueError): | ||
| get_param_importances(study, evaluator=evaluator(), params=["x2"]) | ||
| with pytest.raises(ValueError): |
There was a problem hiding this comment.
ditto
| with pytest.raises(ValueError): | |
| # None of the trials with `x2` are completed. Adding "x1" should not matter. | |
| with pytest.raises(ValueError): |
| get_param_importances(study, evaluator=evaluator(), params=["x2"]) | ||
| with pytest.raises(ValueError): | ||
| get_param_importances(study, evaluator=evaluator(), params=["x1", "x2"]) | ||
| with pytest.raises(ValueError): |
There was a problem hiding this comment.
ditto
| with pytest.raises(ValueError): | |
| # None of the trials contain `x3`. | |
| with pytest.raises(ValueError): |
|
Thank you for the PR. It almost LGTM, with some minor comments listed above |
- Use explicit param for PedAnovaImportanceEvaluator in TestMultiObjectiveImportanceEvaluator for consistency. - Reuse _get_study in test_get_param_importances_unnormalized_experimental. - Restore comments in test_get_param_importances_invalid_no_completed_trials_params. Co-Authored-By: kAIto47802 <[email protected]> Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
I applied the suggestions. |
kAIto47802
left a comment
There was a problem hiding this comment.
Thank you for the update. LGTM
Motivation
Optuna already provides reusable test cases for storages and samplers through
optuna.testing(#6369 and #6424). This PR introduces the same testing pattern for importance evaluators.Description of the changes
optuna.testing.pytest_importancewith the following reusable test cases:BasicImportanceEvaluatorTestCaseConditionalImportanceEvaluatorTestCaseNonConditionalImportanceEvaluatorTestCaseMultiObjectiveImportanceEvaluatorTestCaseevaluatorfixtures.optuna.testing.pytest_importance.A third-party evaluator can use the test cases by inheriting the applicable classes and overriding the
evaluatorfixture: