Skip to content

Commit

Permalink
Merge pull request #249 from alphaville/feature/248
Browse files Browse the repository at this point in the history
Support for WASM
  • Loading branch information
ruairimoran authored Nov 17, 2021
2 parents 1420a41 + 3b6b7fb commit 80e760f
Show file tree
Hide file tree
Showing 29 changed files with 65 additions and 11 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ Note: This is the main Changelog file for the Rust solver. The Changelog file fo
<!-- ---------------------
Unreleased
--------------------- -->
## [v0.7.4] - 2021-11-15

### Added

- Optional feature `wasm` in `Cargo.toml` (WebAssembly support); see https://alphaville.github.io/optimization-engine/docs/openrust-features for details
- Using `instant::Instant` instead of `std::Instant` (Wasm-compatible)
- Fixed Rust documentation of `Ball1`

<!-- ---------------------
v0.7.3
Expand Down Expand Up @@ -207,6 +214,7 @@ This is a breaking API change.

<!-- Releases -->
[Unreleased]: https://github.com/alphaville/optimization-engine/compare/v0.7.3...master
[v0.7.4]: https://github.com/alphaville/optimization-engine/compare/v0.7.3...v0.7.4
[v0.7.3]: https://github.com/alphaville/optimization-engine/compare/v0.7.2...v0.7.3
[v0.7.2]: https://github.com/alphaville/optimization-engine/compare/v0.7.1...v0.7.2
[v0.7.1]: https://github.com/alphaville/optimization-engine/compare/v0.7.0...v0.7.1
Expand Down
15 changes: 11 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ num = "0.2.0"
# Our own stuff - L-BFGS: limited-memory BFGS directions
lbfgs = "0.2"

# Instant is a generic timer that works on Wasm (with wasm-bindgen)
instant = { version = "0.1" }

# Wasm-bindgen is only activated if OpEn is compiled with `--features wasm`
wasm-bindgen = { version = "0.2.74", optional = true }

# sc-allocator provides an implementation of a bump allocator
rpmalloc = { version = "0.2.0", features = ["guards", "statistics"], optional = true }

Expand All @@ -91,17 +97,20 @@ rpmalloc = { version = "0.2.0", features = ["guards", "statistics"], optional =
jemallocator = {version = "0.3.2", optional = true}




# --------------------------------------------------------------------------
# F.E.A.T.U.R.E.S.
# --------------------------------------------------------------------------
[features]
# Use `jemallocator` as a global memory allocator (requires the dependency
# `jemallocator` - see above)
jem = ["jemallocator"]

# RPMalloc
rp = ["rpmalloc"]

# WebAssembly
wasm = ["wasm-bindgen", "instant/wasm-bindgen", "instant/inaccurate"]

# --------------------------------------------------------------------------
# T.E.S.T. D.E.P.E.N.D.E.N.C.I.E.S
# --------------------------------------------------------------------------
Expand All @@ -128,5 +137,3 @@ travis-ci = { repository = "alphaville/optimization-engine", branch = "master" }

# Actively maintained badge
maintenance = { status = "actively-developed" }


2 changes: 1 addition & 1 deletion docs/openrust-alm.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
id: openrust-alm
title: Advanced Rust
title: ALM/PM
description: OpEn in Rust and the augmented Lagrangian method
---

Expand Down
2 changes: 1 addition & 1 deletion docs/openrust-basic.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
id: openrust-basic
title: Basic usage
title: Introduction
description: How to use OpEn directly in Rust
---

Expand Down
36 changes: 36 additions & 0 deletions docs/openrust-features.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
id: openrust-features
title: Features
description: Rust Features
---


## Features

The following [features] are supported in OpEn:

### Memory allocators

You can use the feature `rp` to use the memory allocator `rpmalloc` and `jem` for `jemalloc`.
For example, you can include OpEn as a dependency in your Rust project by adding the following line to you `Cargo.toml` file:

```.toml
[dependencies]
optimization-engine = { version = "0.7", features = ["rp"] }
```

You cannot use both `rp` and `jemalloc`.


### WebAssembly Support

If you intend to use OpEn in WebAssembly you need to use the feature `wasm`.

```.toml
[dependencies]
optimization-engine = { version = "0.7", features = ["wasm"] }
```

<!-- Links -->

[features]: https://doc.rust-lang.org/cargo/reference/features.html
2 changes: 1 addition & 1 deletion docs/python-bindings.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ description: How to access the auto-generated optimizer from Python

<div class="alert alert-warning">
<b>Info:</b> The functionality presented here was introduced in <code>opengen</code> version <code>0.6.4</code>.
The API is still young and is likely to change in versions <code>0.7.X</code>.
The API is still young and is likely to change in versions <code>0.8.X</code>.
</div>


Expand Down
3 changes: 2 additions & 1 deletion src/alm/alm_optimizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -913,7 +913,8 @@ where
///
pub fn solve(&mut self, u: &mut [f64]) -> Result<AlmOptimizerStatus, SolverError> {
let mut num_outer_iterations = 0;
let tic = std::time::Instant::now();
// let tic = std::time::Instant::now();
let tic = instant::Instant::now();
let mut exit_status = ExitStatus::Converged;
self.alm_cache.reset(); // first, reset the cache
self.alm_cache.available_time = self.max_duration;
Expand Down
2 changes: 1 addition & 1 deletion src/core/fbs/fbs_optimizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ where
ConstraintType: constraints::Constraint + 'life,
{
fn solve(&mut self, u: &mut [f64]) -> Result<SolverStatus, SolverError> {
let now = time::Instant::now();
let now = instant::Instant::now();

// Initialize - propagate error upstream, if any
self.fbs_engine.init(u)?;
Expand Down
5 changes: 3 additions & 2 deletions website/sidebars.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
],
"Rust": [
"openrust-basic",
"openrust-alm"
"openrust-alm",
"openrust-features"
],
"Docker": [
"docker"
Expand All @@ -46,4 +47,4 @@
"doc5"
]
}
}
}
Binary file added website/static/img/cart_schematic.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added website/static/img/chat.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added website/static/img/examples_almpm.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added website/static/img/examples_bnp_nmpc.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added website/static/img/examples_invpend.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added website/static/img/examples_rosenbrock.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added website/static/img/examples_tanks.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions website/static/img/external-link-square-alt-solid.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added website/static/img/lv-oc-sol-2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added website/static/img/lv-oc-sol.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added website/static/img/nav-oc-sol-refs.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added website/static/img/nav-oc-sol-theta.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added website/static/img/nav-oc-sol-xy-obst.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added website/static/img/nav-oc-sol-xy.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added website/static/img/nav-oc-sol-xyt.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added website/static/img/open-functionality.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added website/static/img/python-interfaces.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added website/static/img/udp_socket.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 80e760f

Please sign in to comment.