diff --git a/Cargo.toml b/Cargo.toml index d29a58c..3650b04 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,10 +11,14 @@ keywords = ["optimizer", "optimization", "constrained", "derivative-free"] categories = ["algorithms", "api-bindings", "science"] documentation = "https://docs.rs/cobyla" +[features] +serde1 = ["dep:serde", "argmin/serde1"] + [dependencies] +serde = { version = "1", features = ["derive"], optional = true } libc = "0.2" -argmin = "0.8.0" -serde = "1" +argmin-observer-slog = "0.1" +argmin = "0.10" instant = "0.1" [dev-dependencies] diff --git a/examples/paraboloid.rs b/examples/paraboloid.rs index 9ff3616..7d6322f 100644 --- a/examples/paraboloid.rs +++ b/examples/paraboloid.rs @@ -1,5 +1,6 @@ -use argmin::core::observers::{ObserverMode, SlogLogger}; +use argmin::core::observers::ObserverMode; use argmin::core::{CostFunction, Error, Executor}; +use argmin_observer_slog::SlogLogger; use cobyla::{minimize, CobylaSolver, Func, RhoBeg, StopTols}; /// Problem cost function diff --git a/src/cobyla_solver.rs b/src/cobyla_solver.rs index 48b36a0..3e4fe24 100644 --- a/src/cobyla_solver.rs +++ b/src/cobyla_solver.rs @@ -6,13 +6,15 @@ use crate::cobyla_state::*; use std::mem::ManuallyDrop; use argmin::core::{CostFunction, Problem, Solver, State, TerminationStatus, KV}; +#[cfg(feature = "serde1")] use serde::{Deserialize, Serialize}; /// [Argmin Solver](https://www.argmin-rs.org/book/index.html) which implements COBYLA method. /// /// ``` /// use argmin::core::{CostFunction, Error, Executor}; -/// use argmin::core::observers::{ObserverMode, SlogLogger}; +/// use argmin::core::observers::{ObserverMode}; +/// use argmin_observer_slog::SlogLogger; /// use cobyla::CobylaSolver; /// /// struct ParaboloidProblem; @@ -40,7 +42,7 @@ use serde::{Deserialize, Serialize}; /// /// println!("Result of COBYLA:\n{}", res); /// ``` -#[derive(Clone, Serialize, Deserialize)] +#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))] pub struct CobylaSolver { /// Initial guess for x value x0: Vec, diff --git a/src/cobyla_state.rs b/src/cobyla_state.rs index a1f9c4d..c38208b 100644 --- a/src/cobyla_state.rs +++ b/src/cobyla_state.rs @@ -1,6 +1,7 @@ use crate::cobyla::cobyla_context_t; /// Implementation of `argmin::IterState` for Cobyla optimizer use argmin::core::{Problem, State, TerminationReason, TerminationStatus}; +#[cfg(feature = "serde1")] use serde::{Deserialize, Serialize}; use std::collections::HashMap; use std::mem::ManuallyDrop; @@ -24,7 +25,8 @@ use std::mem::ManuallyDrop; /// * termination status /// * COBYLA specific parameters: rhobeg, rhoend, iprint, maxfun /// -#[derive(Clone, Debug, Default, Serialize, Deserialize)] +#[derive(Clone, Debug, Default)] +#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))] pub struct CobylaState { /// Current parameter vector pub param: Option>, @@ -68,7 +70,7 @@ pub struct CobylaState { /// Cost function calls budget pub maxfun: i32, - #[serde(skip)] + #[cfg_attr(feature = "serde1", serde(skip))] pub cobyla_context: Option>, } @@ -83,7 +85,7 @@ where /// /// ``` /// # use argmin::core::{IterState, State}; - /// # let state: IterState, (), (), (), f64> = IterState::new(); + /// # let state: IterState, (), (), (), (), f64> = IterState::new(); /// # let param_old = vec![1.0f64, 2.0f64]; /// # let state = state.param(param_old); /// # assert!(state.prev_param.is_none()); @@ -529,7 +531,7 @@ impl State for CobylaState { /// /// ``` /// # use argmin::core::{IterState, State, ArgminFloat, TerminationStatus}; - /// # let mut state: IterState, (), (), (), f64> = IterState::new(); + /// # let mut state: IterState, (), (), (), (), f64> = IterState::new(); /// let termination_status = state.get_termination_status(); /// # assert_eq!(*termination_status, TerminationStatus::NotTerminated); /// ``` @@ -543,7 +545,7 @@ impl State for CobylaState { /// /// ``` /// # use argmin::core::{IterState, State, ArgminFloat, TerminationReason}; - /// # let mut state: IterState, (), (), (), f64> = IterState::new(); + /// # let mut state: IterState, (), (), (), (), f64> = IterState::new(); /// let termination_reason = state.get_termination_reason(); /// # assert_eq!(termination_reason, None); /// ```