Skip to content

Commit

Permalink
Prepare release 0.15.2 (#137)
Browse files Browse the repository at this point in the history
* Lint README

* Bump 0.15.2

* Fix moe smooth derivatives test and some cleanup
  • Loading branch information
relf authored Feb 12, 2024
1 parent 54b27a9 commit b206773
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 50 deletions.
10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "egobox"
version = "0.15.1"
version = "0.15.2"
authors = ["Rémi Lafage <[email protected]>"]
edition = "2021"
description = "A toolbox for efficient global optimization"
Expand Down Expand Up @@ -31,10 +31,10 @@ persistent-moe = ["egobox-moe/persistent"]
blas = ["ndarray/blas", "egobox-gp/blas", "egobox-moe/blas", "egobox-ego/blas"]

[dependencies]
egobox-doe = { version = "0.15.1", path = "./doe" }
egobox-gp = { version = "0.15.1", path = "./gp" }
egobox-moe = { version = "0.15.1", path = "./moe", features = ["persistent"] }
egobox-ego = { version = "0.15.1", path = "./ego", features = ["persistent"] }
egobox-doe = { version = "0.15.2", path = "./doe" }
egobox-gp = { version = "0.15.2", path = "./gp" }
egobox-moe = { version = "0.15.2", path = "./moe", features = ["persistent"] }
egobox-ego = { version = "0.15.2", path = "./ego", features = ["persistent"] }

linfa = { version = "0.7", default-features = false }

Expand Down
52 changes: 32 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,23 @@
[![linting](https://github.com/relf/egobox/workflows/lint/badge.svg)](https://github.com/relf/egobox/actions?query=workflow%3Alint)
[![DOI](https://joss.theoj.org/papers/10.21105/joss.04737/status.svg)](https://doi.org/10.21105/joss.04737)

Rust toolbox for Efficient Global Optimization algorithms inspired from [SMT](https://github.com/SMTorg/smt).
Rust toolbox for Efficient Global Optimization algorithms inspired from [SMT](https://github.com/SMTorg/smt).

`egobox` is twofold:
1. for end-users: [a Python module](#the-python-module), the Python binding of the optimizer named `Egor` and the surrogate model `Gpx`, mixture of Gaussian processes, written in Rust.
`egobox` is twofold:

1. for end-users: [a Python module](#the-python-module), the Python binding of the optimizer named `Egor` and the surrogate model `Gpx`, mixture of Gaussian processes, written in Rust.
2. for developers: [a set of Rust libraries](#the-rust-libraries) useful to implement bayesian optimization (EGO-like) algorithms,

## The Python module

Thanks to the [PyO3 project](https://pyo3.rs), which makes Rust well suited for building Python extensions.
Thanks to the [PyO3 project](https://pyo3.rs), which makes Rust well suited for building Python extensions.
You can install the Python package using:

```bash
$ pip install egobox
pip install egobox
```

See the [tutorial notebooks](https://github.com/relf/egobox/tree/master/doc/README.md) for usage of the optimizer
See the [tutorial notebooks](https://github.com/relf/egobox/tree/master/doc/README.md) for usage of the optimizer
and mixture of Gaussian processes surrogate model.

## The Rust libraries
Expand All @@ -40,10 +41,10 @@ Depending on the sub-packages you want to use, you have to add following declara

```text
[dependencies]
egobox-doe = { version = "0.15.0" }
egobox-gp = { version = "0.15.0" }
egobox-moe = { version = "0.15.0" }
egobox-ego = { version = "0.15.0" }
egobox-doe = { version = "0.15" }
egobox-gp = { version = "0.15" }
egobox-moe = { version = "0.15" }
egobox-ego = { version = "0.15" }
```

### Features
Expand All @@ -53,37 +54,46 @@ The table below presents the various features available depending on the subcrat
| Name | doe | gp | moe | ego |
| :----------- | :--- | :--- | :--- | :--- |
| serializable | ✔️ | ✔️ | ✔️ | |
| persistent | | | ✔️ | |
| persistent | | | ✔️ | ✔️(*) |
| blas | | ✔️ | ✔️ | ✔️ |
| nlopt | | ✔️ | | ✔️ |

(*) required for mixed-variable gaussian process

#### serializable

When selected, the serialization with [serde crate](https://serde.rs/) is enabled.

#### persistent
When selected, the save and load as a json file with [serde_json crate](https://serde.rs/) is enabled.

When selected, the save and load as a json file with [serde_json crate](https://serde.rs/) is enabled.

#### blas

When selected, the usage of BLAS/LAPACK backend is possible, see [below](#blaslapack-backend-optional) for more information.

#### nlopt

When selected, the [nlopt crate](https://github.com/adwhit/rust-nlopt) is used to provide optimizer implementations (ie Cobyla, Slsqp)

### Examples

Examples (in `examples/` sub-packages folder) are run as follows:

```bash
$ cd doe && cargo run --example samplings --release
cd doe && cargo run --example samplings --release
```

``` bash
$ cd gp && cargo run --example kriging --release
cd gp && cargo run --example kriging --release
```

``` bash
$ cd moe && cargo run --example clustering --release
cd moe && cargo run --example clustering --release
```

``` bash
$ cd ego && cargo run --example ackley --release
cd ego && cargo run --example ackley --release
```

### BLAS/LAPACK backend (optional)
Expand All @@ -95,20 +105,23 @@ As for `linfa`, the linear algebra routines used in `gp`, `moe` ad `ego` are pro
Otherwise, you can choose an external BLAS/LAPACK backend available through the [ndarray-linalg](https://github.com/rust-ndarray/ndarray-linalg) crate. In this case, you have to specify the `blas` feature and a `linfa` [BLAS/LAPACK backend feature](https://github.com/rust-ml/linfa#blaslapack-backend) (more information in [linfa features](https://github.com/rust-ml/linfa#blaslapack-backend)).

Thus, for instance, to use `gp` with the Intel MKL BLAS/LAPACK backend, you could specify in your `Cargo.toml` the following features:

```text
[dependencies]
egobox-gp = { version = "0.15.0", features = ["blas", "linfa/intel-mkl-static"] }
egobox-gp = { version = "0.15", features = ["blas", "linfa/intel-mkl-static"] }
```

or you could run the `gp` example as follows:

``` bash
$ cd gp && cargo run --example kriging --release --features blas,linfa/intel-mkl-static
cd gp && cargo run --example kriging --release --features blas,linfa/intel-mkl-static
```

## Citation

[![DOI](https://joss.theoj.org/papers/10.21105/joss.04737/status.svg)](https://doi.org/10.21105/joss.04737)

If you find this project useful for your research, you may cite it as follows:
If you find this project useful for your research, you may cite it as follows:

```text
@article{
Expand All @@ -127,4 +140,3 @@ If you find this project useful for your research, you may cite it as follows:
```

Additionally, you may consider adding a star to the repository. This positive feedback improves the visibility of the project.

2 changes: 1 addition & 1 deletion doe/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "egobox-doe"
version = "0.15.1"
version = "0.15.2"
authors = ["Rémi Lafage <[email protected]>"]
edition = "2021"
description = "A library for design of experiments"
Expand Down
8 changes: 4 additions & 4 deletions ego/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "egobox-ego"
version = "0.15.1"
version = "0.15.2"
authors = ["Rémi Lafage <[email protected]>"]
edition = "2021"
description = "A library for efficient global optimization"
Expand All @@ -16,11 +16,11 @@ persistent = ["egobox-moe/persistent"]
blas = ["ndarray-linalg", "linfa/ndarray-linalg", "linfa-pls/blas"]

[dependencies]
egobox-doe = { version = "0.15.1", path = "../doe", features = [
egobox-doe = { version = "0.15.2", path = "../doe", features = [
"serializable",
] }
egobox-gp = { version = "0.15.1", path = "../gp", features = ["serializable"] }
egobox-moe = { version = "0.15.1", path = "../moe", features = [
egobox-gp = { version = "0.15.2", path = "../gp", features = ["serializable"] }
egobox-moe = { version = "0.15.2", path = "../moe", features = [
"serializable",
] }

Expand Down
4 changes: 2 additions & 2 deletions gp/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "egobox-gp"
version = "0.15.1"
version = "0.15.2"
authors = ["Rémi Lafage <[email protected]>"]
edition = "2021"
description = "A library for gaussian process modeling"
Expand All @@ -18,7 +18,7 @@ persistent = ["serializable", "serde_json"]
blas = ["ndarray-linalg", "linfa/ndarray-linalg", "linfa-pls/blas"]

[dependencies]
egobox-doe = { version = "0.15.1", path = "../doe" }
egobox-doe = { version = "0.15.2", path = "../doe" }

linfa = { version = "0.7", default-features = false }
linfa-pls = { version = "0.7", default-features = false }
Expand Down
6 changes: 3 additions & 3 deletions moe/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "egobox-moe"
version = "0.15.1"
version = "0.15.2"
authors = ["Rémi Lafage <[email protected]>"]
edition = "2021"
description = "A library for mixture of expert gaussian processes"
Expand Down Expand Up @@ -29,8 +29,8 @@ serializable = [
blas = ["ndarray-linalg", "linfa/ndarray-linalg", "linfa-pls/blas"]

[dependencies]
egobox-doe = { version = "0.15.1", path = "../doe" }
egobox-gp = { version = "0.15.1", path = "../gp" }
egobox-doe = { version = "0.15.2", path = "../doe" }
egobox-gp = { version = "0.15.2", path = "../gp" }

linfa = { version = "0.7", default-features = false }
linfa-clustering = { version = "0.7", default-features = false }
Expand Down
5 changes: 0 additions & 5 deletions moe/src/clustering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,6 @@ mod tests {
use crate::gp_algorithm::GpMixture;
use approx::assert_abs_diff_eq;
use egobox_doe::{FullFactorial, Lhs, SamplingMethod};
use env_logger::{Builder, Env};
#[cfg(not(feature = "blas"))]
use linfa_linalg::norm::*;
use ndarray::{array, Array1, Array2, Axis, Zip};
Expand Down Expand Up @@ -413,10 +412,6 @@ mod tests {

#[test]
fn test_find_best_cluster_nb_2d() {
let env = Env::new().filter_or("EGOBOX_LOG", "info");
let mut builder = Builder::from_env(env);
let builder = builder.target(env_logger::Target::Stdout);
builder.try_init().ok();
let doe = egobox_doe::FullFactorial::new(&array![[-1., 1.], [-1., 1.]]);
let xtrain = doe.sample(100);
let ytrain = l1norm(&xtrain);
Expand Down
15 changes: 7 additions & 8 deletions moe/src/gp_algorithm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ impl<R: Rng + SeedableRng + Clone> GpMixValidParams<f64, R> {
yt: &ArrayBase<impl Data<Elem = f64>, Ix2>,
) -> Result<GpMixture> {
trace!("Moe training...");
let _opt = env_logger::try_init().ok();
let nx = xt.ncols();
let data = concatenate(Axis(1), &[xt.view(), yt.view()]).unwrap();

Expand Down Expand Up @@ -1085,24 +1084,23 @@ mod tests {
let x = Array1::linspace(0., 1., 50).insert_axis(Axis(1));
let preds = moe.predict_values(&x).expect("MOE prediction");
let dpreds = moe.predict_derivatives(&x).expect("MOE drv prediction");
println!("dpred = {dpreds}");

let test_dir = "target/tests";
std::fs::create_dir_all(test_dir).ok();
write_npy(format!("{test_dir}/x_hard.npy"), &x).expect("x saved");
write_npy(format!("{test_dir}/preds_hard.npy"), &preds).expect("preds saved");
write_npy(format!("{test_dir}/dpreds_hard.npy"), &dpreds).expect("dpreds saved");
write_npy(format!("{test_dir}/x_moe_smooth.npy"), &x).expect("x saved");
write_npy(format!("{test_dir}/preds_moe_smooth.npy"), &preds).expect("preds saved");
write_npy(format!("{test_dir}/dpreds_moe_smooth.npy"), &dpreds).expect("dpreds saved");

let mut rng = Xoshiro256Plus::seed_from_u64(42);
for _ in 0..20 {
let x1: f64 = rng.gen_range(0.0..1.0);

let h = 1e-4;
let h = 1e-8;
let xtest = array![[x1]];

let x = array![[x1], [x1 + h], [x1 - h]];
let preds = moe.predict_derivatives(&x).unwrap();
let fdiff = preds[[1, 0]] - preds[[1, 0]] / 2. * h;
let preds = moe.predict_values(&x).unwrap();
let fdiff = (preds[[1, 0]] - preds[[2, 0]]) / (2. * h);

let drv = moe.predict_derivatives(&xtest).unwrap();
let df = df_test_1d(&xtest);
Expand All @@ -1115,6 +1113,7 @@ mod tests {
println!(
"Test predicted derivatives at {xtest}: drv {drv}, true df {df}, fdiff {fdiff}"
);
println!("preds(x, x+h, x-h)={}", preds);
assert_abs_diff_eq!(err, 0.0, epsilon = 2.5e-1);
}
}
Expand Down
1 change: 0 additions & 1 deletion moe/src/sgp_algorithm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ impl<R: Rng + SeedableRng + Clone> SparseGpMixtureValidParams<f64, R> {
yt: &ArrayBase<impl Data<Elem = f64>, Ix2>,
) -> Result<SparseGpMixture> {
trace!("Sgp training...");
let _opt = env_logger::try_init().ok();
let nx = xt.ncols();
let data = concatenate(Axis(1), &[xt.view(), yt.view()]).unwrap();

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ python-source = "python"

[tool.poetry]
name = "egobox"
version = "0.15.1"
version = "0.15.2"
description = "Python binding for egobox EGO optimizer written in Rust"
authors = ["Rémi Lafage <[email protected]>"]
packages = [{ include = "egobox", from = "python" }]
Expand Down

0 comments on commit b206773

Please sign in to comment.