From 530faba61c54c9ec087459456603492e75f8ab73 Mon Sep 17 00:00:00 2001 From: Manuel Raimann Date: Fri, 30 Jan 2026 18:08:13 +0100 Subject: [PATCH] refactor: rename library from optimize to optimizer --- Cargo.toml | 4 +-- README.md | 14 +++++----- src/error.rs | 2 +- src/lib.rs | 16 +++++------ src/sampler/mod.rs | 2 +- src/sampler/random.rs | 2 +- src/sampler/tpe.rs | 18 ++++++------ src/study.rs | 64 +++++++++++++++++++++---------------------- src/trial.rs | 16 +++++------ src/types.rs | 2 +- tests/async_tests.rs | 4 +-- tests/integration.rs | 8 +++--- 12 files changed, 76 insertions(+), 76 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d51d584..a265ae8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,12 +1,12 @@ [package] -name = "optimize" +name = "optimizer" version = "0.1.0" edition = "2024" rust-version = "1.88" license = "MIT" authors = ["Manuel Raimann = Study::with_sampler(Direction::Minimize, sampler); @@ -25,7 +25,7 @@ let study: Study = Study::with_sampler(Direction::Minimize, sampler); study .optimize_with_sampler(20, |trial| { let x = trial.suggest_float("x", -10.0, 10.0)?; - Ok::<_, optimize::TpeError>(x * x) + Ok::<_, optimizer::TpeError>(x * x) }) .unwrap(); @@ -40,7 +40,7 @@ println!("Best value: {} at x={:?}", best.value, best.params); ## Documentation -Full API documentation is available at [docs.rs/optimize](https://docs.rs/optimize). +Full API documentation is available at [docs.rs/optimizer](https://docs.rs/optimizer). ## License diff --git a/src/error.rs b/src/error.rs index 3503408..7e1e610 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,4 +1,4 @@ -//! Error types for the optimize library. +//! Error types for the optimizer library. use thiserror::Error; diff --git a/src/lib.rs b/src/lib.rs index 9350a24..bed8faf 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -12,7 +12,7 @@ //! # Quick Start //! //! ``` -//! use optimize::{Direction, Study, TpeSampler}; +//! use optimizer::{Direction, Study, TpeSampler}; //! //! // Create a study with TPE sampler //! let sampler = TpeSampler::builder().seed(42).build(); @@ -22,7 +22,7 @@ //! study //! .optimize_with_sampler(20, |trial| { //! let x = trial.suggest_float("x", -10.0, 10.0)?; -//! Ok::<_, optimize::TpeError>(x * x) +//! Ok::<_, optimizer::TpeError>(x * x) //! }) //! .unwrap(); //! @@ -36,7 +36,7 @@ //! A [`Study`] manages optimization trials. Create one with an optimization direction: //! //! ``` -//! use optimize::{Direction, RandomSampler, Study, TpeSampler}; +//! use optimizer::{Direction, RandomSampler, Study, TpeSampler}; //! //! // Minimize with default random sampler //! let study: Study = Study::new(Direction::Minimize); @@ -53,7 +53,7 @@ //! Within the objective function, use [`Trial`] to suggest parameter values: //! //! ``` -//! use optimize::{Direction, Study}; +//! use optimizer::{Direction, Study}; //! //! let study: Study = Study::new(Direction::Minimize); //! @@ -73,7 +73,7 @@ //! let optimizer = trial.suggest_categorical("optimizer", &["sgd", "adam", "rmsprop"])?; //! //! // Return objective value -//! Ok::<_, optimize::TpeError>(x * n as f64) +//! Ok::<_, optimizer::TpeError>(x * n as f64) //! }) //! .unwrap(); //! ``` @@ -83,7 +83,7 @@ //! The [`TpeSampler`] can be configured using the builder pattern: //! //! ``` -//! use optimize::TpeSampler; +//! use optimizer::TpeSampler; //! //! let sampler = TpeSampler::builder() //! .gamma(0.15) // Quantile for good/bad split @@ -98,7 +98,7 @@ //! With the `async` feature enabled, you can run trials asynchronously: //! //! ```ignore -//! use optimize::{Study, Direction}; +//! use optimizer::{Study, Direction}; //! //! // Sequential async //! study.optimize_async(10, |mut trial| async move { @@ -118,7 +118,7 @@ //! With the `serde` feature enabled, studies can be serialized: //! //! ```ignore -//! use optimize::{Study, Direction, TpeSampler}; +//! use optimizer::{Study, Direction, TpeSampler}; //! //! // Save study state //! let study: Study = Study::new(Direction::Minimize); diff --git a/src/sampler/mod.rs b/src/sampler/mod.rs index 246d8bd..501b1d5 100644 --- a/src/sampler/mod.rs +++ b/src/sampler/mod.rs @@ -59,7 +59,7 @@ impl CompletedTrial { /// Implementing a custom sampler: /// /// ```ignore -/// use optimize::{Sampler, ParamValue, Distribution, CompletedTrial}; +/// use optimizer::{Sampler, ParamValue, Distribution, CompletedTrial}; /// /// struct MySampler; /// diff --git a/src/sampler/random.rs b/src/sampler/random.rs index bd2602b..7aee1c5 100644 --- a/src/sampler/random.rs +++ b/src/sampler/random.rs @@ -17,7 +17,7 @@ use crate::sampler::{CompletedTrial, Sampler}; /// # Examples /// /// ``` -/// use optimize::RandomSampler; +/// use optimizer::RandomSampler; /// /// // Create with default RNG /// let sampler = RandomSampler::new(); diff --git a/src/sampler/tpe.rs b/src/sampler/tpe.rs index ea3649c..9d5a047 100644 --- a/src/sampler/tpe.rs +++ b/src/sampler/tpe.rs @@ -27,7 +27,7 @@ use crate::sampler::{CompletedTrial, Sampler}; /// # Examples /// /// ``` -/// use optimize::TpeSampler; +/// use optimizer::TpeSampler; /// /// // Create with default settings /// let sampler = TpeSampler::new(); @@ -76,7 +76,7 @@ impl TpeSampler { /// # Examples /// /// ``` - /// use optimize::TpeSampler; + /// use optimizer::TpeSampler; /// /// let sampler = TpeSampler::builder() /// .gamma(0.15) @@ -395,7 +395,7 @@ impl Default for TpeSampler { /// # Examples /// /// ``` -/// use optimize::TpeSamplerBuilder; +/// use optimizer::TpeSamplerBuilder; /// /// let sampler = TpeSamplerBuilder::new() /// .gamma(0.15) @@ -448,7 +448,7 @@ impl TpeSamplerBuilder { /// # Examples /// /// ``` - /// use optimize::TpeSamplerBuilder; + /// use optimizer::TpeSamplerBuilder; /// /// let sampler = TpeSamplerBuilder::new() /// .gamma(0.10) // Use top 10% as "good" trials @@ -476,7 +476,7 @@ impl TpeSamplerBuilder { /// # Examples /// /// ``` - /// use optimize::TpeSamplerBuilder; + /// use optimizer::TpeSamplerBuilder; /// /// let sampler = TpeSamplerBuilder::new() /// .n_startup_trials(20) // Random sample first 20 trials @@ -500,7 +500,7 @@ impl TpeSamplerBuilder { /// # Examples /// /// ``` - /// use optimize::TpeSamplerBuilder; + /// use optimizer::TpeSamplerBuilder; /// /// let sampler = TpeSamplerBuilder::new() /// .n_ei_candidates(48) // Evaluate more candidates @@ -530,7 +530,7 @@ impl TpeSamplerBuilder { /// # Examples /// /// ``` - /// use optimize::TpeSamplerBuilder; + /// use optimizer::TpeSamplerBuilder; /// /// let sampler = TpeSamplerBuilder::new() /// .kde_bandwidth(0.5) // Fixed bandwidth of 0.5 @@ -554,7 +554,7 @@ impl TpeSamplerBuilder { /// # Examples /// /// ``` - /// use optimize::TpeSamplerBuilder; + /// use optimizer::TpeSamplerBuilder; /// /// let sampler = TpeSamplerBuilder::new() /// .seed(42) // Reproducible results @@ -570,7 +570,7 @@ impl TpeSamplerBuilder { /// # Examples /// /// ``` - /// use optimize::TpeSamplerBuilder; + /// use optimizer::TpeSamplerBuilder; /// /// let sampler = TpeSamplerBuilder::new() /// .gamma(0.15) diff --git a/src/study.rs b/src/study.rs index 71c5fe5..9c2b00d 100644 --- a/src/study.rs +++ b/src/study.rs @@ -39,7 +39,7 @@ fn default_sampler() -> Arc { /// # Examples /// /// ``` -/// use optimize::{Direction, Study}; +/// use optimizer::{Direction, Study}; /// /// // Create a study to minimize an objective function /// let study: Study = Study::new(Direction::Minimize); @@ -74,7 +74,7 @@ where /// # Examples /// /// ``` - /// use optimize::{Direction, Study}; + /// use optimizer::{Direction, Study}; /// /// let study: Study = Study::new(Direction::Minimize); /// assert_eq!(study.direction(), Direction::Minimize); @@ -93,7 +93,7 @@ where /// # Examples /// /// ``` - /// use optimize::{Direction, RandomSampler, Study}; + /// use optimizer::{Direction, RandomSampler, Study}; /// /// let sampler = RandomSampler::with_seed(42); /// let study: Study = Study::with_sampler(Direction::Maximize, sampler); @@ -125,7 +125,7 @@ where /// # Examples /// /// ``` - /// use optimize::{Direction, Study, TpeSampler}; + /// use optimizer::{Direction, Study, TpeSampler}; /// /// // After deserializing a study, restore the TPE sampler /// let mut study: Study = Study::new(Direction::Minimize); @@ -153,7 +153,7 @@ where /// # Examples /// /// ``` - /// use optimize::{Direction, Study}; + /// use optimizer::{Direction, Study}; /// /// let study: Study = Study::new(Direction::Minimize); /// let trial = study.create_trial(); @@ -181,7 +181,7 @@ where /// # Examples /// /// ``` - /// use optimize::{Direction, Study}; + /// use optimizer::{Direction, Study}; /// /// let study: Study = Study::new(Direction::Minimize); /// let mut trial = study.create_trial(); @@ -217,7 +217,7 @@ where /// # Examples /// /// ``` - /// use optimize::{Direction, Study}; + /// use optimizer::{Direction, Study}; /// /// let study: Study = Study::new(Direction::Minimize); /// let trial = study.create_trial(); @@ -243,7 +243,7 @@ where /// # Examples /// /// ``` - /// use optimize::{Direction, Study}; + /// use optimizer::{Direction, Study}; /// /// let study: Study = Study::new(Direction::Minimize); /// let mut trial = study.create_trial(); @@ -268,7 +268,7 @@ where /// # Examples /// /// ``` - /// use optimize::{Direction, Study}; + /// use optimizer::{Direction, Study}; /// /// let study: Study = Study::new(Direction::Minimize); /// assert_eq!(study.n_trials(), 0); @@ -295,7 +295,7 @@ where /// # Examples /// /// ``` - /// use optimize::{Direction, Study}; + /// use optimizer::{Direction, Study}; /// /// let study: Study = Study::new(Direction::Minimize); /// @@ -360,7 +360,7 @@ where /// # Examples /// /// ``` - /// use optimize::{Direction, Study}; + /// use optimizer::{Direction, Study}; /// /// let study: Study = Study::new(Direction::Maximize); /// @@ -409,7 +409,7 @@ where /// # Examples /// /// ``` - /// use optimize::{Direction, RandomSampler, Study}; + /// use optimizer::{Direction, RandomSampler, Study}; /// /// // Minimize x^2 /// let sampler = RandomSampler::with_seed(42); @@ -418,7 +418,7 @@ where /// study /// .optimize(10, |trial| { /// let x = trial.suggest_float("x", -10.0, 10.0)?; - /// Ok::<_, optimize::TpeError>(x * x) + /// Ok::<_, optimizer::TpeError>(x * x) /// }) /// .unwrap(); /// @@ -476,10 +476,10 @@ where /// # Examples /// /// ``` - /// use optimize::{Direction, RandomSampler, Study}; + /// use optimizer::{Direction, RandomSampler, Study}; /// /// # #[cfg(feature = "async")] - /// # async fn example() -> optimize::Result<()> { + /// # async fn example() -> optimizer::Result<()> { /// // Minimize x^2 with async objective /// let sampler = RandomSampler::with_seed(42); /// let study: Study = Study::with_sampler(Direction::Minimize, sampler); @@ -489,7 +489,7 @@ where /// let x = trial.suggest_float("x", -10.0, 10.0)?; /// // Simulate async work (e.g., network request) /// let value = x * x; - /// Ok::<_, optimize::TpeError>((trial, value)) + /// Ok::<_, optimizer::TpeError>((trial, value)) /// }) /// .await?; /// @@ -556,10 +556,10 @@ where /// # Examples /// /// ``` - /// use optimize::{Direction, RandomSampler, Study}; + /// use optimizer::{Direction, RandomSampler, Study}; /// /// # #[cfg(feature = "async")] - /// # async fn example() -> optimize::Result<()> { + /// # async fn example() -> optimizer::Result<()> { /// // Minimize x^2 with parallel async evaluation /// let sampler = RandomSampler::with_seed(42); /// let study: Study = Study::with_sampler(Direction::Minimize, sampler); @@ -569,7 +569,7 @@ where /// let x = trial.suggest_float("x", -10.0, 10.0)?; /// // Async objective function (e.g., network request) /// let value = x * x; - /// Ok::<_, optimize::TpeError>((trial, value)) + /// Ok::<_, optimizer::TpeError>((trial, value)) /// }) /// .await?; /// @@ -657,7 +657,7 @@ where /// ``` /// use std::ops::ControlFlow; /// - /// use optimize::{Direction, RandomSampler, Study}; + /// use optimizer::{Direction, RandomSampler, Study}; /// /// // Stop early when we find a good enough value /// let sampler = RandomSampler::with_seed(42); @@ -668,7 +668,7 @@ where /// 100, /// |trial| { /// let x = trial.suggest_float("x", -10.0, 10.0)?; - /// Ok::<_, optimize::TpeError>(x * x) + /// Ok::<_, optimizer::TpeError>(x * x) /// }, /// |_study, completed_trial| { /// // Stop early if we find a value less than 1.0 @@ -746,7 +746,7 @@ impl Study { /// # Examples /// /// ``` - /// use optimize::{Direction, RandomSampler, Study}; + /// use optimizer::{Direction, RandomSampler, Study}; /// /// // With a seeded sampler for reproducibility /// let sampler = RandomSampler::with_seed(42); @@ -767,7 +767,7 @@ impl Study { /// Runs optimization with full sampler integration. /// - /// This method is similar to the generic `optimize` method but creates trials + /// This method is similar to the generic `optimizer` method but creates trials /// using `create_trial_with_sampler()`, giving the sampler access to the history /// of completed trials for informed parameter suggestions. /// @@ -787,7 +787,7 @@ impl Study { /// # Examples /// /// ``` - /// use optimize::{Direction, RandomSampler, Study}; + /// use optimizer::{Direction, RandomSampler, Study}; /// /// // Minimize x^2 with sampler integration /// let sampler = RandomSampler::with_seed(42); @@ -796,7 +796,7 @@ impl Study { /// study /// .optimize_with_sampler(10, |trial| { /// let x = trial.suggest_float("x", -10.0, 10.0)?; - /// Ok::<_, optimize::TpeError>(x * x) + /// Ok::<_, optimizer::TpeError>(x * x) /// }) /// .unwrap(); /// @@ -856,7 +856,7 @@ impl Study { /// ``` /// use std::ops::ControlFlow; /// - /// use optimize::{Direction, RandomSampler, Study}; + /// use optimizer::{Direction, RandomSampler, Study}; /// /// // Optimize with sampler integration and early stopping /// let sampler = RandomSampler::with_seed(42); @@ -867,7 +867,7 @@ impl Study { /// 100, /// |trial| { /// let x = trial.suggest_float("x", -10.0, 10.0)?; - /// Ok::<_, optimize::TpeError>(x * x) + /// Ok::<_, optimizer::TpeError>(x * x) /// }, /// |study, _completed_trial| { /// // Stop after finding 5 good trials @@ -950,10 +950,10 @@ impl Study { /// # Examples /// /// ``` - /// use optimize::{Direction, RandomSampler, Study}; + /// use optimizer::{Direction, RandomSampler, Study}; /// /// # #[cfg(feature = "async")] - /// # async fn example() -> optimize::Result<()> { + /// # async fn example() -> optimizer::Result<()> { /// // Minimize x^2 with async objective and sampler integration /// let sampler = RandomSampler::with_seed(42); /// let study: Study = Study::with_sampler(Direction::Minimize, sampler); @@ -963,7 +963,7 @@ impl Study { /// let x = trial.suggest_float("x", -10.0, 10.0)?; /// // Simulate async work (e.g., network request) /// let value = x * x; - /// Ok::<_, optimize::TpeError>((trial, value)) + /// Ok::<_, optimizer::TpeError>((trial, value)) /// }) /// .await?; /// @@ -1030,10 +1030,10 @@ impl Study { /// # Examples /// /// ``` - /// use optimize::{Direction, RandomSampler, Study}; + /// use optimizer::{Direction, RandomSampler, Study}; /// /// # #[cfg(feature = "async")] - /// # async fn example() -> optimize::Result<()> { + /// # async fn example() -> optimizer::Result<()> { /// // Minimize x^2 with parallel async evaluation and sampler integration /// let sampler = RandomSampler::with_seed(42); /// let study: Study = Study::with_sampler(Direction::Minimize, sampler); diff --git a/src/trial.rs b/src/trial.rs index ad05f09..bac8d69 100644 --- a/src/trial.rs +++ b/src/trial.rs @@ -71,7 +71,7 @@ impl Trial { /// # Examples /// /// ``` - /// use optimize::Trial; + /// use optimizer::Trial; /// /// let trial = Trial::new(0); /// assert_eq!(trial.id(), 0); @@ -178,7 +178,7 @@ impl Trial { /// # Examples /// /// ``` - /// use optimize::Trial; + /// use optimizer::Trial; /// /// let mut trial = Trial::new(0); /// let x = trial.suggest_float("x", 0.0, 1.0).unwrap(); @@ -261,7 +261,7 @@ impl Trial { /// # Examples /// /// ``` - /// use optimize::Trial; + /// use optimizer::Trial; /// /// let mut trial = Trial::new(0); /// let lr = trial @@ -358,7 +358,7 @@ impl Trial { /// # Examples /// /// ``` - /// use optimize::Trial; + /// use optimizer::Trial; /// /// let mut trial = Trial::new(0); /// let x = trial.suggest_float_step("x", 0.0, 1.0, 0.25).unwrap(); @@ -450,7 +450,7 @@ impl Trial { /// # Examples /// /// ``` - /// use optimize::Trial; + /// use optimizer::Trial; /// /// let mut trial = Trial::new(0); /// let n = trial.suggest_int("n_layers", 1, 10).unwrap(); @@ -536,7 +536,7 @@ impl Trial { /// # Examples /// /// ``` - /// use optimize::Trial; + /// use optimizer::Trial; /// /// let mut trial = Trial::new(0); /// let batch_size = trial.suggest_int_log("batch_size", 1, 1024).unwrap(); @@ -627,7 +627,7 @@ impl Trial { /// # Examples /// /// ``` - /// use optimize::Trial; + /// use optimizer::Trial; /// /// let mut trial = Trial::new(0); /// let n = trial @@ -731,7 +731,7 @@ impl Trial { /// # Examples /// /// ``` - /// use optimize::Trial; + /// use optimizer::Trial; /// /// let mut trial = Trial::new(0); /// let optimizer = trial diff --git a/src/types.rs b/src/types.rs index ec9a477..6ceedce 100644 --- a/src/types.rs +++ b/src/types.rs @@ -1,4 +1,4 @@ -//! Core types for the optimize library. +//! Core types for the optimizer library. #[cfg(feature = "serde")] use serde::{Deserialize, Serialize}; diff --git a/tests/async_tests.rs b/tests/async_tests.rs index ca9c68a..e29525b 100644 --- a/tests/async_tests.rs +++ b/tests/async_tests.rs @@ -1,10 +1,10 @@ -//! Async integration tests for the optimize library. +//! Async integration tests for the optimizer library. //! //! These tests are only compiled when the `async` feature is enabled. #![cfg(feature = "async")] -use optimize::{Direction, RandomSampler, Study, TpeError, TpeSampler}; +use optimizer::{Direction, RandomSampler, Study, TpeError, TpeSampler}; #[tokio::test] async fn test_optimize_async_basic() { diff --git a/tests/integration.rs b/tests/integration.rs index 2d7999f..e608ee9 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -1,6 +1,6 @@ -//! Integration tests for the optimize library. +//! Integration tests for the optimizer library. -use optimize::{Direction, RandomSampler, Study, TpeError, TpeSampler, Trial}; +use optimizer::{Direction, RandomSampler, Study, TpeError, TpeSampler, Trial}; // ============================================================================= // Test: optimize simple quadratic function with TPE, finds near-optimal @@ -671,7 +671,7 @@ fn test_study_direction() { #[test] fn test_trial_state() { - use optimize::TrialState; + use optimizer::TrialState; let trial = Trial::new(0); assert_eq!(trial.state(), TrialState::Running); @@ -863,7 +863,7 @@ fn test_trial_debug_format() { #[test] fn test_tpe_sampler_builder_default_trait() { - use optimize::TpeSamplerBuilder; + use optimizer::TpeSamplerBuilder; let builder = TpeSamplerBuilder::default(); let sampler = builder.build();