3 releases (breaking)
✓ Uses Rust 2018 edition
|0.3.0||Dec 10, 2018|
|0.2.0||Jul 20, 2018|
|0.1.0||Jul 19, 2018|
#101 in Science
42 downloads per month
Used in 2 crates
A non-linear constrained optimisation (mathematical programming) modelling library with first and second order automatic differentiation / source-code symbolic differentiation. Currently has an interface to the non-linear solver Ipopt.
It has only been tested on linux, but presumably would also work on macos, and potentially on windows in the right environment.
For use in your own crate, add the following to your own
[dependencies] descent = "0.3" descent_ipopt = "0.3" descent_macro = "0.3" # for optional expr! procedural macro use
The following code shows how to solve the following simple problem in IPOPT:
min 2 y s.t. y >= x * x - x, x in [-10, 10].
use descent::model::Model; use descent_ipopt::IpoptModel; let mut m = IpoptModel::new(); let x = m.add_var(-10.0, 10.0, 0.0); let y = m.add_var(std::f64::NEG_INFINITY, std::f64::INFINITY, 0.0); m.set_obj(2.0 * y); m.add_con(y - x * x + x, 0.0, std::f64::INFINITY); let (stat, sol) = m.solve();
A full example of this with additional details is provided under
descent_ipopt/examples/simple.rs, which can be built and run as follows:
cargo build --release --example simple ./target/release/examples/simple
Code optimizations are important, so be sure to turn them on or use the release build option when testing your code for performance.
.cos() are supported
in mathematical expressions. Expressions can be generated either via operator
overloading or with a procedural macro (requires nightly rust).
Expressions can be dynamically generated with maximum flexibility using operator overloading. This is the approach adopted in the example provided above.
If nightly rust is available, then a procedural macro can be used to "statically" generate functions for evaluating the expression and calculating its first and second derivatives. This provides a huge performance increase over the dynamic operator overloading and AD approach. The above example using the procedural macro expression generation approach looks like the following:
#![feature(proc_macro_hygiene)] use descent::model::Model; use descent_ipopt::IpoptModel; use descent_macro::expr; let mut m = IpoptModel::new(); let x = m.add_var(-10.0, 10.0, 0.0); let y = m.add_var(std::f64::NEG_INFINITY, std::f64::INFINITY, 0.0); m.set_obj(expr!(2.0 * y; y)); m.add_con(expr!(y - x * x + x; x, y), 0.0, std::f64::INFINITY); let (stat, sol) = m.solve();
A more complete example can be found in
The library allows parameterisation of values and easy solver warmstarting to enable quick model adjustments and resolving.
- Clean up the hastily written procedural macro.
- Integrate with ipopt-sys crate and possibly ipopt crate instead of using / maintaining own bindings.
- Bonmin bindings (enabling MINLP).
Apache-2.0 or MIT