Repository navigation
Introduce PedAnovaBuilder for PedAnovaImportanceEvaluator - #262
Alnusjaponica wants to merge 3 commits into
Conversation
|
@kAIto47802 Could you review this PR? |
Resolve conflicts with main, which added `attr_format` to the storage options, by adding an `attr_format` setter to each builder. Following the decision in #262, `XxxBuilder::new()` is now the only entry point (matching `std::thread::Builder::new()`); the `XxxStorage::builder()` methods are removed. - `InMemoryStorageBuilder::new().apply_discard(true).attr_format(..).build()` - `SQLite3StorageBuilder::new(file_path).apply_discard(true).build()?` - `JournalStorageBuilder::new(backend).apply_discard(true).build()?` Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
| /// Sets the number of grid steps used by the Parzen estimators. | ||
| pub fn n_steps(self, n_steps: usize) -> Self { | ||
| Self { n_steps, ..self } | ||
| } | ||
|
|
||
| /// Sets the prior weight used by the Parzen estimators. | ||
| pub fn prior_weight(self, prior_weight: f64) -> Self { | ||
| Self { | ||
| prior_weight, | ||
| ..self | ||
| } | ||
| } | ||
|
|
||
| /// Sets the minimum number of completed trials for a search regime to contribute to | ||
| /// the importance. | ||
| pub fn min_n_trials_in_regime(self, min_n_trials_in_regime: usize) -> Self { | ||
| Self { | ||
| min_n_trials_in_regime, | ||
| ..self | ||
| } | ||
| } | ||
|
|
There was a problem hiding this comment.
| /// Sets the number of grid steps used by the Parzen estimators. | |
| pub fn n_steps(self, n_steps: usize) -> Self { | |
| Self { n_steps, ..self } | |
| } | |
| /// Sets the prior weight used by the Parzen estimators. | |
| pub fn prior_weight(self, prior_weight: f64) -> Self { | |
| Self { | |
| prior_weight, | |
| ..self | |
| } | |
| } | |
| /// Sets the minimum number of completed trials for a search regime to contribute to | |
| /// the importance. | |
| pub fn min_n_trials_in_regime(self, min_n_trials_in_regime: usize) -> Self { | |
| Self { | |
| min_n_trials_in_regime, | |
| ..self | |
| } | |
| } |
target_quantile, region_quantile, and evaluate_on_local are options we encourage users to customize for their use cases. In contrast, n_steps, prior_weight, and min_n_trials_in_regime are advanced settings that we generally expect users to leave at their defaults.
In Optuna, the latter three are kept as instance attributes so they can still be adjusted if necessary, but are deliberately omitted from the constructor arguments to avoid encouraging customization:
https://github.com/optuna/optuna/blob/v5.0.0/optuna/importance/_ped_anova/evaluator.py#L177-L182
Could we follow the same approach here by removing the builder methods for n_steps, prior_weight, and min_n_trials_in_regime, while keeping them as fields in the struct?
| /// .n_steps(100) | ||
| /// .prior_weight(2.0) | ||
| /// .min_n_trials_in_regime(3) |
There was a problem hiding this comment.
Ditto
| /// .n_steps(100) | |
| /// .prior_weight(2.0) | |
| /// .min_n_trials_in_regime(3) |
| .n_steps(100) | ||
| .prior_weight(2.0) | ||
| .min_n_trials_in_regime(3) |
There was a problem hiding this comment.
| .n_steps(100) | |
| .prior_weight(2.0) | |
| .min_n_trials_in_regime(3) |
c0a72af to
0f80088
Compare
Summary
Replace the positional constructor arguments of
PedAnovaImportanceEvaluatorwith a builder following the API style ofstd::thread::Builder: settings are configured by chaining setter methods and the evaluator is created withbuild.Builder::new()is the only entry point, matchingthread::Builder::new().Changes
PedAnovaBuilder(withDefault) exposing chainable setters andbuild()target_quantile,region_quantile,evaluate_on_local,n_steps,prior_weight, andmin_n_trials_in_regime, which were previously fixed to their internal defaultsbuilder()entry point fromPedAnovaImportanceEvaluatorin favor ofBuilder::new()(no dual entry points)newandDefaultare kept for backward compatibility and now delegate to the builder0.0 < target_quantile < region_quantile <= 1.0) moved intobuildVerification
cargo test --all-features— 273 tests pass (including a newtest_builderand doctests)cargo test -p rustuna_storage --locked -- --ignored(fromrustuna_pyo3) — 3 passcargo clippy --locked --workspace --lib --bins --tests --examples --all-features -- -D warnings— cleancargo fmt --all -- --check— cleanuv run --no-sync pytest tests/— 701 pass (constructor,ValueError, and warning behavior verified through the new builder path)