Skip to content

Introduce NsgaiiBuilder and TpeBuilder for samplers - #212

Merged
c-bata merged 3 commits into
mainfrom
feat/nsgaii-builder
Oct 5, 2026
Merged

c-bata merged 3 commits into
mainfrom
feat/nsgaii-builder

Conversation

@Alnusjaponica

@Alnusjaponica Alnusjaponica commented Aug 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Replace the XxxConfig/from_config construction pattern with builders following the API style of std::thread::Builder: settings are configured by chaining setter methods and the sampler is created with build. Builder::new() is the only entry point, matching thread::Builder::new().

let sampler = NsgaiiBuilder::new()
    .population_size(100)
    .mutation_prob(0.1)
    .crossover_prob(0.9)
    .swapping_prob(0.5)
    .seed(42)
    .build();

let sampler = TpeBuilder::new()
    .n_startup_trials(20)
    .multivariate(true)
    .seed(42)
    .build();

Changes

  • Add NsgaiiBuilder and TpeBuilder (with Default) exposing chainable setters and build()
  • Remove NsgaiiConfig/TpeConfig and from_config
  • Remove the builder() entry point from the samplers in favor of Builder::new() (no dual entry points)
  • Keep new, seed_from_u64, and Default on the samplers for backward compatibility; they now delegate to the builders
  • Update the pyo3 bindings to construct samplers through the builders
  • Rebase onto latest main (the branch previously conflicted with main)

The previous NsgaiiConfig approach is preserved in backup/pr212-before-builder-20260926.

Verification

  • cargo test --all-features — 273 tests pass (including new 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

@Alnusjaponica
Alnusjaponica marked this pull request as draft August 18, 2026 02:40
@c-bata c-bata self-assigned this Aug 19, 2026
Replace the XxxConfig/from_config construction pattern with builders
following the API style of std::thread::Builder: settings are configured
by chaining setter methods and the sampler is created with `build`.

NSGAIISampler and TpeSampler keep `new`, `seed_from_u64` and `Default`
for backward compatibility, and they now delegate to the builders. The
pyo3 bindings construct samplers through the builders as well.
@Alnusjaponica Alnusjaponica changed the title Introduce NsgaiiConfig for NSGAIISampler Introduce NsgaiiBuilder and TpeBuilder for samplers Sep 25, 2026
NSGAIISampler::builder() and TpeSampler::builder() were redundant with
NsgaiiBuilder::new() and TpeBuilder::new(). Keep Builder::new() as the
only entry point, matching std::thread::Builder.

@c-bata c-bata left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM!

@c-bata
c-bata merged commit 84b4517 into main Oct 5, 2026
7 checks passed
@c-bata
c-bata deleted the feat/nsgaii-builder branch October 5, 2026 04:56
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.

2 participants