Skip to content

Introduce PedAnovaBuilder for PedAnovaImportanceEvaluator - #262

Draft
Alnusjaponica wants to merge 3 commits into
mainfrom
feat/importance-builder
Draft

Alnusjaponica wants to merge 3 commits into
mainfrom
feat/importance-builder

Conversation

@Alnusjaponica

@Alnusjaponica Alnusjaponica commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Replace the positional constructor arguments of PedAnovaImportanceEvaluator with a builder following the API style of std::thread::Builder: settings are configured by chaining setter methods and the evaluator is created with build. Builder::new() is the only entry point, matching thread::Builder::new().

let evaluator = PedAnovaBuilder::new()
    .target_quantile(0.2)
    .region_quantile(0.9)
    .evaluate_on_local(false)
    .n_steps(100)
    .prior_weight(2.0)
    .min_n_trials_in_regime(3)
    .build()
    .unwrap();

Changes

  • Add PedAnovaBuilder (with Default) exposing chainable setters and build()
  • The builder exposes all evaluator settings: target_quantile, region_quantile, evaluate_on_local, n_steps, prior_weight, and min_n_trials_in_regime, which were previously fixed to their internal defaults
  • Remove the builder() entry point from PedAnovaImportanceEvaluator in favor of Builder::new() (no dual entry points)
  • new and Default are kept for backward compatibility and now delegate to the builder
  • The validation (0.0 < target_quantile < region_quantile <= 1.0) moved into build
  • Update the pyo3 binding to construct the evaluator through the builder

Verification

  • cargo test --all-features — 273 tests pass (including a new test_builder and doctests)
  • cargo test -p rustuna_storage --locked -- --ignored (from rustuna_pyo3) — 3 pass
  • cargo clippy --locked --workspace --lib --bins --tests --examples --all-features -- -D warnings — clean
  • cargo fmt --all -- --check — clean
  • Python: uv run --no-sync pytest tests/ — 701 pass (constructor, ValueError, and warning behavior verified through the new builder path)

@c-bata

c-bata commented Oct 5, 2026

Copy link
Copy Markdown
Member

@kAIto47802 Could you review this PR?

Alnusjaponica added a commit that referenced this pull request Nov 4, 2026
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>
@Alnusjaponica
Alnusjaponica marked this pull request as ready for review November 4, 2026 10:06
Comment on lines +163 to +184
/// 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
}
}

@kAIto47802 kAIto47802 Nov 5, 2026 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// 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?

Comment on lines +103 to +105
/// .n_steps(100)
/// .prior_weight(2.0)
/// .min_n_trials_in_regime(3)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto

Suggested change
/// .n_steps(100)
/// .prior_weight(2.0)
/// .min_n_trials_in_regime(3)

Comment on lines +720 to +722
.n_steps(100)
.prior_weight(2.0)
.min_n_trials_in_regime(3)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.n_steps(100)
.prior_weight(2.0)
.min_n_trials_in_regime(3)

@Alnusjaponica
Alnusjaponica marked this pull request as draft November 6, 2026 05:32
@Alnusjaponica
Alnusjaponica force-pushed the feat/importance-builder branch from c0a72af to 0f80088 Compare November 19, 2026 08:30

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants