Skip to content

Commit

Permalink
Upgrade argmin 0.10 (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
relf authored Apr 22, 2024
1 parent 56e799d commit b51df50
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 10 deletions.
8 changes: 6 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
3 changes: 2 additions & 1 deletion examples/paraboloid.rs
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 4 additions & 2 deletions src/cobyla_solver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<f64>,
Expand Down
12 changes: 7 additions & 5 deletions src/cobyla_state.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<Vec<f64>>,
Expand Down Expand Up @@ -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<ManuallyDrop<*mut cobyla_context_t>>,
}

Expand All @@ -83,7 +85,7 @@ where
///
/// ```
/// # use argmin::core::{IterState, State};
/// # let state: IterState<Vec<f64>, (), (), (), f64> = IterState::new();
/// # let state: IterState<Vec<f64>, (), (), (), (), f64> = IterState::new();
/// # let param_old = vec![1.0f64, 2.0f64];
/// # let state = state.param(param_old);
/// # assert!(state.prev_param.is_none());
Expand Down Expand Up @@ -529,7 +531,7 @@ impl State for CobylaState {
///
/// ```
/// # use argmin::core::{IterState, State, ArgminFloat, TerminationStatus};
/// # let mut state: IterState<Vec<f64>, (), (), (), f64> = IterState::new();
/// # let mut state: IterState<Vec<f64>, (), (), (), (), f64> = IterState::new();
/// let termination_status = state.get_termination_status();
/// # assert_eq!(*termination_status, TerminationStatus::NotTerminated);
/// ```
Expand All @@ -543,7 +545,7 @@ impl State for CobylaState {
///
/// ```
/// # use argmin::core::{IterState, State, ArgminFloat, TerminationReason};
/// # let mut state: IterState<Vec<f64>, (), (), (), f64> = IterState::new();
/// # let mut state: IterState<Vec<f64>, (), (), (), (), f64> = IterState::new();
/// let termination_reason = state.get_termination_reason();
/// # assert_eq!(termination_reason, None);
/// ```
Expand Down

0 comments on commit b51df50

Please sign in to comment.