Skip to content

Commit

Permalink
Version 0.8.0
Browse files Browse the repository at this point in the history
  • Loading branch information
stefan-k committed Jan 28, 2023
1 parent a3abb7b commit 627adae
Show file tree
Hide file tree
Showing 8 changed files with 223 additions and 19 deletions.
48 changes: 43 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,43 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## argmin-math [Unreleased]

## argmin [argmin v0.8.0] 2023-01-28

### Added

* Added a `full` feature which enables all features (@stefan-k)
* Added a particle swarm optimization example using the `nalgebra` math backend (@stefan-k)
* Added a L-BFGS example using the `nalgebra` math backend (@stefan-k)

### Changed

* Improved termination handling (@relf, #305)
- Introduced `TerminationStatus` which can either be `Terminated(TerminationReason)` or `NotTerminated`
- The fields of the `TerminationReason` enum were reduced to cases potentially relevant to any solver. Solver-specific cases can be handled with `SolverExit(String)`.
- Added new `TerminationReason::KeyboardInterrupt` and `TerminationReason::Converged`
* Changes to KV store used to get values from the solver to observers (@stefan-k)
- KV store is now typed (via `KvValue`), which means that observers can now use the actual numbers (in the past those values were only `dyn Display` and as such could only be printed)
- `make_kv!` renamed to `kv!`
* Solver does not need to be `Serialize` anymore when `serde1` feature is enabled. This was an oversight reported by @relf and fixed by @stefan-k
* Better calculation of elapsed time inside `Executor` (@TheIronBorn)
* The check whether the target cost is reached is now based on the current best cost function value rather than the current cost function value (@relf)


## argmin-math [argmin-math v0.3.0] 2023-01-28

### Added

* Added support for `nalgebra` 0.32

### Changed

* All math backends now implement all math related traits (apart from the `Vec` backend which does not implement `ArgminInv`). Therefore (almost) all solvers work with all backends. (@hypotrochoid, @stefan-k)
* More primitive and complex types are now covered as well (@stefan-k)
* Reached 100% test coverage (@stefan-k)
* `InverseError` is not `Clone` anymore (@stefan-k)
* Upgraded `ndarray-linalg` to version 0.16 for the `ndarray` 0.15 backend


## [argmin-math v0.2.1] 2022-09-09

### Added
Expand Down Expand Up @@ -186,9 +223,10 @@ This is a rather large release with many (breaking) changes.

For older versions please see the Git history.

[Unreleased]: https://github.com/argmin-rs/argmin/compare/v0.6.0...HEAD
[Unreleased]: https://github.com/argmin-rs/argmin/compare/argmin-v0.8.0...HEAD
[argmin v0.8.0]: https://github.com/argmin-rs/argmin/compare/argmin-v0.7.0...argmin-v0.8.0
[argmin v0.7.0]: https://github.com/argmin-rs/argmin/compare/argmin-v0.6.0...argmin-v0.7.0
[argmin v0.6.0]: https://github.com/argmin-rs/argmin/compare/v0.5.1...argmin-v0.6.0
[argmin-math v0.1.0]: https://github.com/argmin-rs/argmin/compare/v0.5.1...argmin-v0.6.0
[argmin v0.6.0]: https://github.com/argmin-rs/argmin/compare/argmin-v0.6.0...argmin-v0.7.0
[argmin-math v0.2.0]: https://github.com/argmin-rs/argmin/compare/argmin-v0.6.0...argmin-v0.7.0
[argmin-math v0.2.1]: https://github.com/argmin-rs/argmin/compare/argmin-v0.7.0...argmin-math-v0.2.1
[argmin-math v0.2.1]: https://github.com/argmin-rs/argmin/compare/argmin-math-v0.2.0...argmin-math-v0.2.1
[argmin-math v0.2.0]: https://github.com/argmin-rs/argmin/compare/argmin-math-v0.1.0...argmin-math-v0.2.0
[argmin-math v0.1.0]: https://github.com/argmin-rs/argmin/compare/v0.5.1...argmin-math-v0.1.0
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
</p>

<p align="center">
<a href="http://argmin-rs.org">Website</a>
<a href="https://argmin-rs.org">Website</a>
|
<a href="http://argmin-rs.org/book/">Book</a>
<a href="https://argmin-rs.org/book/">Book</a>
|
<a href="https://docs.rs/argmin">Docs (latest release)</a>
|
Expand All @@ -24,12 +24,12 @@

<p align="center">
<!--
<a href="http://argmin-rs.org"
<a href="https://argmin-rs.org"
><img
src="https://img.shields.io/website?down_message=offline&style=flat-square&up_message=argmin-rs.org&url=http%3A%2F%2Fargmin-rs.org"
alt="Website"
/></a>
<a href="http://argmin-rs.org/book/"
<a href="https://argmin-rs.org/book/"
><img
src="https://img.shields.io/website?label=book&style=flat-square&url=http%3A%2F%2Fargmin-rs.org%2Fbook%2F"
alt="Website"
Expand Down
4 changes: 2 additions & 2 deletions argmin-math/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[package]
name = "argmin-math"
version = "0.2.1"
version = "0.3.0"
authors = ["Stefan Kroboth <stefan.kroboth@gmail.com>"]
edition = "2021"
license = "MIT OR Apache-2.0"
description = "argmin math abstractions"
documentation = "https://docs.rs/argmin-math/"
homepage = "http://argmin-rs.org"
homepage = "https://argmin-rs.org"
repository = "https://github.com/argmin-rs/argmin"
readme = "README.md"
keywords = ["optimization", "math", "science"]
Expand Down
6 changes: 3 additions & 3 deletions argmin-math/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
</p>

<p align="center">
<a href="http://argmin-rs.org">Website</a>
<a href="https://argmin-rs.org">Website</a>
|
<a href="http://argmin-rs.org/book/">Book</a>
<a href="https://argmin-rs.org/book/">Book</a>
|
<a href="https://docs.rs/argmin-math">Docs (latest release)</a>
|
Expand Down Expand Up @@ -41,7 +41,7 @@
</p>


This create provides a abstractions for mathematical operations needed in [argmin](http://argmin-rs.org).
This create provides a abstractions for mathematical operations needed in [argmin](https://argmin-rs.org).
The supported math backends so far are basic `Vec`s, `ndarray` and `nalgebra`.
Please consult the documentation for details.

Expand Down
2 changes: 1 addition & 1 deletion argmin-math/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
//! argmin.
//!
//! For an introduction on how to use argmin, please also have a look at the
//! [book](http://www.argmin-rs.org/book/).
//! [book](https://www.argmin-rs.org/book/).
//!
//! # Usage
//!
Expand Down
6 changes: 3 additions & 3 deletions argmin/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[package]
name = "argmin"
version = "0.7.0"
version = "0.8.0"
authors = ["Stefan Kroboth <stefan.kroboth@gmail.com>"]
edition = "2021"
license = "MIT OR Apache-2.0"
description = "Mathematical optimization in pure Rust"
documentation = "https://docs.rs/argmin/"
homepage = "http://argmin-rs.org"
homepage = "https://argmin-rs.org"
repository = "https://github.com/argmin-rs/argmin"
readme = "../README.md"
keywords = ["optimization", "math", "science"]
Expand All @@ -22,7 +22,7 @@ num-traits = { version = "0.2" }
rand = { version = "0.8.5" }
rand_xoshiro = { version = "0.6.0" }
thiserror = "1.0"
argmin-math = { path = "../argmin-math", version = "0.2", default-features = false, features = ["primitives"] }
argmin-math = { path = "../argmin-math", version = "0.3", default-features = false, features = ["primitives"] }
# optional
bincode = { version = "1.3.3", optional = true }
ctrlc = { version = "3.1.2", optional = true }
Expand Down
2 changes: 1 addition & 1 deletion argmin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
//! and Hessians is taken care of by the library.
//!
//! For an introduction on how to use argmin, please also have a look at the
//! [book](http://www.argmin-rs.org/book/).
//! [book](https://www.argmin-rs.org/book/).
//!
//! # Highlights
//!
Expand Down
166 changes: 166 additions & 0 deletions media/website/content/blog/version-v0.8.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
+++
title = "argmin 0.8.0 and argmin-math 0.3.0 released"
description = ""
date = 2023-01-28T00:00:00+00:00
updated = 2023-01-28T00:00:00+00:00
draft = false
template = "blog/page.html"

[taxonomies]
authors = ["Stefan Kroboth"]

[extra]
+++

<b>argmin</b> is a Rust library which offers a range of numerical optimization methods and a framework for
developing optimization algorithms. <b>argmin-math</b> is a trait-based abstraction layer for mathematical operations,
which makes argmin compatible with various math backends such as [ndarray](https://crates.io/crates/ndarray) and
[nalgebra](https://crates.io/crates/nalgebra) (or your own backend).
For details about the design of argmin and its features I suggest having a look at
[the website](https://argmin-rs.org),
[the book](https://argmin-rs.org/book),
[Github](https://github.com/argmin-rs/argmin),
[crates.io](https://crates.io/crates/argmin) and
[lib.rs](https://lib.rs/crates/argmin).

This is a short summary of the changes in argmin 0.8.0 and argmin-math 0.3.0.
Both releases include breaking API changes; however upgrading from the previous versions should hopefully be fairly smooth.
Don't hesitate [to get in touch](https://github.com/argmin-rs/argmin/issues) in case you run into problems during upgrading.

## argmin 0.8.0

#### Improved termination handling

The solver state contains a `TerminationReason` enum which indicates why the solver terminated.
The enum variants offered in previous versions of argmin were either applicable to all solvers or were solver-specific.
[@relf](https://github.com/relf) [rightfully pointed out](https://github.com/argmin-rs/argmin/issues/305) that these variants weren't ideal:
For instance, it included an awkward variant `NotTerminated` and a couple of variants could be summarized as `Converged`.
Whenever a `Ctrl+C` was intercepted, the reason would be `Aborted`, which is suboptimal because a solver could also abort
due to other reasons.
In the discussion we decided to change the `TerminationReason` enum to the following:

```rust
pub enum TerminationReason {
/// Reached maximum number of iterations
MaxItersReached,
/// Reached target cost function value
TargetCostReached,
/// Algorithm manually interrupted with Ctrl+C
KeyboardInterrupt,
/// Converged
SolverConverged,
/// Solver exit with given reason
SolverExit(String),
}
```

The first two are potential outcomes of two checks performed by the `Executor` for every solver.
`KeyboardInterrupt` replaces `Aborted` and is only used for `Ctrl+C`.
`SolverConverged` indicates a successful optimization run and `SolverExit(String)` is used for
cases where the solver stopped for a solver-specific reason specified by a string.

The awkward `NotTerminated` was dropped and instead a new enum `TerminationStatus` is introduced:

```rust
enum TerminationStatus {
NotTerminated,
Terminated(TerminationReason)
}
```

This enum is stored in the state instead of `TerminationReason`.
It can be obtained from an `OptimizationResult` via the solver state:

```rust
// of type &TerminationStatus
let status = result.state().get_termination_status();

// ... or ...

// of type Option<&TerminationReason>
let reason = result.state().get_termination_reason();
```

Both methods are part of the `State` trait and as such available for all available states.

Note that this is a breaking change and as such you may have to adapt your code, in particular if you use the returned
termination reason.

Huge thanks to [@relf](https://github.com/relf) for the fruitful discussion and for doing all the heavy lifting!


#### Changes to the observer interface

In the past, values sent to the observers were only `dyn Display`, which means they could effectively only be turned into strings.
To get the actual value one had to parse the strings into a given type, which isn't great (to put it mildly).

Therefore I decided [to make the values sent to the observers typed](https://github.com/argmin-rs/argmin/pull/269) and
added support for 64bit floats, signed and unsigned 64bit integer, Booleans and Strings via the `KvValue` enum:

```rust
pub enum KvValue {
Float(f64),
Int(i64),
Uint(u64),
Bool(bool),
Str(String),
}
```

The actual values can be retrieved via the getters `get_float`, `get_int`, `get_uint`, `get_bool` and `get_string`,
which return `Some(<inner_value>)` if the `KvValue` is of the appropriate type and `None` otherwise.

The `make_kv!` macro used in solvers to construct the Key-Value store was renamed to `kv!`.

These changes will only affect you if you wrote an observer or solver yourself.
All observers shipped with argmin should continue to work as before.

#### Other

* Implementing the `Solver` trait for a solver does not require anymore that the solver implements `serde::Serialize` when the `serde1` feature is enabled.
This was a remnant of an earlier design of the `Solver` trait found by [@relf](https://github.com/relf).
Note that checkpointing requires solvers to be serializable!
Therefore, despite lifting this requirement, it is still recommended that solvers are (de)serializable if possible.
* The check whether an optional target cost is reached is now based on the best cost function value so far rather than the current cost function value ([@relf](https://github.com/relf))
* Added a `full` feature which activates all features.
* Added a particle swarm optimization and L-BFGS example using the nalgebra backend.
* Elapsed time is now computed using `as_secs_f64` ([@TheIronBorn](https://github.com/TheIronBorn))
* Internally uses argmin-math 0.3.0, so make sure to update both!

## argmin-math 0.3.0

With this release all backends finally implement all math-related traits, meaning that every backend now works with every solver.
The only exception to this is the `vec` backend, which does not implement `ArgminInv` and as such does not
work with (Gauss-)Newton methods.
I've spent multiple days tediously implementing all missing traits and adding tests for every implementation
(eventually reaching 100% test coverage).
[@hypotrochoid](https://github.com/hypotrochoid) implemented the `ArgminRandom` trait for the ndarray backend
and with that kicked off this entire endeavour. Thanks!

Apart from that support for nalgebra 0.32 was added and ndarray-linalg was updated from version 0.14 to 0.16 for
the ndarray v0.15 backend.
Therefore you may have to update ndarray-linalg as well.

Upgrading to version 0.3.0 of argmin-math should be smooth for most cases.

## Other news

argmin is not only a collection of optimization algorithms but also aims to be a framework which facilitates
the development of optimization algorithms.
Solvers implemented using argmin get features such as checkpointing, observers and support for various math backends for free.

However, I have not seen any use of this feature outside of argmin itself up until recently, when [@relf](https://github.com/relf)
made his [egobox-ego solver](https://crates.io/crates/egobox-ego)
[compatible with argmin](https://github.com/relf/egobox/pull/67).
This is very exciting for me as this led to valuable feedback on the design of argmin and I hope that others will follow
that example and make their solvers compatible with argmin.


<br>
<script async defer src="https://buttons.github.io/buttons.js"></script>
<p align="center">
<a class="github-button" href="https://github.com/argmin-rs/argmin" data-icon="octicon-star" data-size="large" data-show-count="true" aria-label="Star argmin-rs/argmin on GitHub">Star</a>
<a class="github-button" href="https://github.com/argmin-rs/argmin/subscription" data-icon="octicon-eye" data-size="large" data-show-count="true" aria-label="Watch argmin-rs/argmin on GitHub">Watch</a>
<a class="github-button" href="https://github.com/argmin-rs/argmin/fork" data-icon="octicon-repo-forked" data-size="large" data-show-count="true" aria-label="Fork argmin-rs/argmin on GitHub">Fork</a>
<a class="github-button" href="https://github.com/sponsors/stefan-k" data-icon="octicon-heart" data-size="large" aria-label="Sponsor @stefan-k on GitHub">Sponsor</a>
</p>

0 comments on commit 627adae

Please sign in to comment.