Git Product home page Git Product logo

alphaville / optimization-engine Goto Github PK

View Code? Open in Web Editor NEW
467.0 14.0 50.0 52.75 MB

Nonconvex embedded optimization: code generation for fast real-time optimization

Home Page: https://alphaville.github.io/optimization-engine/

License: Other

Rust 53.26% Shell 0.89% JavaScript 3.33% MATLAB 3.67% Python 30.01% C 4.87% HTML 0.16% Dockerfile 0.33% Jupyter Notebook 0.82% CMake 0.12% C++ 1.21% CSS 1.11% Makefile 0.10% Batchfile 0.12%
embedded-optimization nonconvex model-predictive-control rust-library rust rust-crate nonlinear-optimization nonlinear-model-predictive-control embedded-systems robotics

optimization-engine's Introduction

OpEn logo

CodeFactor GHA continuous integration build status

MIT license Apache v2 license

Gitter Tweet Chat on Discord

Optimization Engine (OpEn) is a solver for Fast & Accurate Embedded Optimization for next-generation Robotics and Autonomous Systems.

Documentation available at alphaville.github.io/optimization-engine

Table of contents

Features

OpEn is the counterpart of CVXGen for nonconvex problems.

  • Fast nonconvex parametric optimization
  • Numerical algorithm written in Rust
  • Provably safe memory management
  • Auto-generation of ROS packages

OpEn is ideal for:

  • Embedded Nonlinear Model Predictive Control,
  • Embedded Nonlinear Moving Horizon Estimation and their applications in
  • Robotics and Advanced Manufacturing Systems
  • Autonomous vehicles
  • Aerial Vehicles and Aerospace

Demos

Code generation

Code generation? Piece of cake!

OpEn generates parametric optimizer modules in Rust - it's blazingly fast - it's safe - it can run on embedded devices.

You can use the MATLAB or Python interface of OpEn to generate Rust code for your parametric optimizer.

This can then be called directly, using Rust, or, it can be consumed as a service over a socket.

Easy Code Generation

You can generate a parametric optimizer in just very few lines of code and in no time.

OpEn allows application developers and researchers to focus on the challenges of the application, rather than the tedious task of solving the associated parametric optimization problems (as in nonlinear model predictive control).

Embedded applications

OpEn can run on embedded devices; here we see it running on an intel Atom for the autonomous navigation of a lab-scale micro aerial vehicle - the controller runs at 20Hz using only 15% CPU!

Fast NMPC of MAV

Parametric Problems

OpEn can solve nonconvex parametric optimization problems of the general form

standard parametric optimziation problem

where f is a smooth cost, U is a simple - possibly nonconvex - set, F1 and F2 are nonlinear smooth mappings and C is a convex set (read more).

Code Generation Example

Code generation in Python in just a few lines of code (read the docs for details)

import opengen as og
import casadi.casadi as cs

# Define variables
# ------------------------------------
u = cs.SX.sym("u", 5)
p = cs.SX.sym("p", 2)

# Define cost function and constraints
# ------------------------------------
phi = og.functions.rosenbrock(u, p)
f2 = cs.vertcat(1.5 * u[0] - u[1],
                cs.fmax(0.0, u[2] - u[3] + 0.1))
bounds = og.constraints.Ball2(None, 1.5)
problem = og.builder.Problem(u, p, phi) \
    .with_penalty_constraints(f2)       \
    .with_constraints(bounds)
    
# Configuration and code generation
# ------------------------------------
build_config = og.config.BuildConfiguration()  \
    .with_build_directory("python_test_build") \
    .with_tcp_interface_config()
meta = og.config.OptimizerMeta()
solver_config = og.config.SolverConfiguration()    \
    .with_tolerance(1e-5)                          \
    .with_constraints_tolerance(1e-4)
builder = og.builder.OpEnOptimizerBuilder(problem, meta,
                                          build_config, solver_config)
builder.build()

Code generation in a few lines of MATLAB code (read the docs for details)

% Define variables
% ------------------------------------
u = casadi.SX.sym('u', 5);
p = casadi.SX.sym('p', 2);

% Define cost function and constraints
% ------------------------------------
phi = rosenbrock(u, p);
f2 = [1.5*u(1) - u(2);
      max(0, u(3)-u(4)+0.1)];

bounds = OpEnConstraints.make_ball_at_origin(5.0);

opEnBuilder = OpEnOptimizerBuilder()...
    .with_problem(u, p, phi, bounds)...
    .with_build_name('penalty_new')...
    .with_fpr_tolerance(1e-5)...
    .with_constraints_as_penalties(f2);

opEnOptimizer = opEnBuilder.build();

Getting started

Contact us

Do you like OpEn?

Show us with a star on github...

Star

License

OpEn is a free open source project. You can use it under the terms of either Apache license v2.0 or MIT license.

Core Team


Pantelis Sopasakis

Emil Fresk

Contributions

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Before you contribute to Optimization Engine, please read our contributing guidelines.

A list of contributors is automatically generated by github here.

Citing OpEn

Please, cite OpEn as follows (arXiv version):

@inproceedings{open2020,
  author="P. Sopasakis and E. Fresk and P. Patrinos",
  title="{OpEn}: Code Generation for Embedded Nonconvex Optimization",
  booktitle="IFAC World Congress",
  year="2020",
  address="Berlin"
}

optimization-engine's People

Contributors

alphaville avatar andrewjschoen avatar arun-r-m avatar c-mccullough avatar chutchi2 avatar davidrusu avatar dependabot[bot] avatar gmsanchez avatar gsilano avatar ivrolan avatar jannic avatar jgillis avatar korken89 avatar kylc avatar regexident avatar ruairimoran avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

optimization-engine's Issues

Build fails on `emil_fixes`

Describe the bug
Changes on emil_fixes make the build on my machine fail.

To Reproduce
Check out emil_fixes and run cargo clean and then cargo build. I get the following errors:

$ cargo build
   Compiling num-traits v0.2.6                                                                                               
   Compiling num-integer v0.1.39                                                                                             
   Compiling num-bigint v0.2.2                                                                                               
   Compiling num-complex v0.2.1                                                                                              
   Compiling num-iter v0.1.37                                                                                                
   Compiling num-rational v0.2.1                                                                                             
   Compiling num v0.2.0                                                                                                      
   Compiling lbfgs v0.1.1                                                                                                    
   Compiling optimization_engine v0.3.0 (/home/chung/NetBeansProjects/RUST/optimization-engine)                              
error[E0658]: imports can only refer to extern crate names passed with `--extern` on stable channel (see issue #53130)       
 --> src/constraints/mod.rs:7:9                                                                                              
  |                                                                                                                          
3 | mod ball2;                                                                                                               
  | ---------- not an extern crate passed with `--extern`                                                                    
...                                                                                                                          
7 | pub use ball2::Ball2;                                                                                                    
  |         ^^^^^                                                                                                            
  |                                                                                                                          
note: this import refers to the module defined here                                                                          
 --> src/constraints/mod.rs:3:1                                                                                              
  |                                                                                                                          
3 | mod ball2;                                                                                                               
  | ^^^^^^^^^^                                                                                                               
                                                                                                                             
error[E0658]: imports can only refer to extern crate names passed with `--extern` on stable channel (see issue #53130)       
 --> src/constraints/mod.rs:9:9                                                                                              
  |                                                                                                                          
5 | mod rectangle;                                                                                                           
  | -------------- not an extern crate passed with `--extern`                                                                
...                                                                                                                          
9 | pub use rectangle::Rectangle;                                                                                            
  |         ^^^^^^^^^                                                                                                        
  |                                                                                                                          
note: this import refers to the module defined here                                                                          
 --> src/constraints/mod.rs:5:1                                                                                              
  |                                                                                                                          
5 | mod rectangle;                                                                                                           
  | ^^^^^^^^^^^^^^                                                                                                           
                                                                                                                             
error[E0658]: imports can only refer to extern crate names passed with `--extern` on stable channel (see issue #53130)       
  --> src/core/fbs/mod.rs:49:9                                                                                               
   |                                                                                                                         
46 | mod fbs_optimizer;                                                                                                      
   | ------------------ not an extern crate passed with `--extern`                                                           
...                                                                                                                          
49 | pub use fbs_optimizer::FBSOptimizer;                                                                                    
   |         ^^^^^^^^^^^^^                                                                                                   
   |                                                                                                                         
note: this import refers to the module defined here                                                                          
  --> src/core/fbs/mod.rs:46:1                                                                                               
   |                                                                                                                         
46 | mod fbs_optimizer;                                                                                                      
   | ^^^^^^^^^^^^^^^^^^                                                                                                      
                                                                                                                             
error[E0658]: imports can only refer to extern crate names passed with `--extern` on stable channel (see issue #53130)       
 --> src/core/panoc/mod.rs:8:9                                                                                               
  |                                                                                                                          
5 | mod panoc_optimizer;                                                                                                     
  | -------------------- not an extern crate passed with `--extern`                                                          
...                                                                                                                          
8 | pub use panoc_optimizer::PANOCOptimizer;                                                                                 
  |         ^^^^^^^^^^^^^^^                                                                                                  
  |                                                                                                                          
note: this import refers to the module defined here                                                                          
 --> src/core/panoc/mod.rs:5:1                                                                                               
  |                                                                                                                          
5 | mod panoc_optimizer;                                                                                                     
  | ^^^^^^^^^^^^^^^^^^^^                                                                                                     
                                                                                                                             
error[E0658]: imports can only refer to extern crate names passed with `--extern` on stable channel (see issue #53130)       
  --> src/core/mod.rs:11:9                                                                                                   
   |                                                                                                                         
7  | pub mod problem;                                                                                                        
   | ---------------- not an extern crate passed with `--extern`                                                             
...                                                                                                                          
11 | pub use problem::Problem;                                                                                               
   |         ^^^^^^^                                                                                                         
   |                                                                                                                         
note: this import refers to the module defined here                                                                          
  --> src/core/mod.rs:7:1                                                                                                    
   |                                                                                                                         
7  | pub mod problem;                                                                                                        
   | ^^^^^^^^^^^^^^^^                                                                                                        
                                                                                                                             
error[E0658]: imports can only refer to extern crate names passed with `--extern` on stable channel (see issue #53130)       
 --> src/constraints/mod.rs:8:9                                                                                              
  |                                                                                                                          
4 | mod no_constraints;                                                                                                      
  | ------------------- not an extern crate passed with `--extern`                                                           
...                                                                                                                          
8 | pub use no_constraints::NoConstraints;                                                                                   
  |         ^^^^^^^^^^^^^^                                                                                                   
  |                                                                                                                          
note: this import refers to the module defined here                                                                          
 --> src/constraints/mod.rs:4:1                                                                                              
  |                                                                                                                          
4 | mod no_constraints;                                                                                                      
  | ^^^^^^^^^^^^^^^^^^^                                                                                                      
                                                                                                                             
error[E0658]: imports can only refer to extern crate names passed with `--extern` on stable channel (see issue #53130)       
  --> src/core/fbs/mod.rs:48:9                                                                                               
   |                                                                                                                         
44 | mod fbs_cache;                                                                                                          
   | -------------- not an extern crate passed with `--extern`                                                               
...                                                                                                                          
48 | pub use fbs_cache::FBSCache;                                                                                            
   |         ^^^^^^^^^                                                                                                       
   |                                                                                                                         
note: this import refers to the module defined here                                                                          
  --> src/core/fbs/mod.rs:44:1                                                                                               
   |                                                                                                                         
44 | mod fbs_cache;                                                                                                          
   | ^^^^^^^^^^^^^^                                                                                                          
                                                                                                                             
error[E0658]: imports can only refer to extern crate names passed with `--extern` on stable channel (see issue #53130)       
 --> src/core/panoc/mod.rs:7:9                                                                                               
  |                                                                                                                          
3 | mod panoc_cache;                                                                                                         
  | ---------------- not an extern crate passed with `--extern`                                                              
...                                                                                                                          
7 | pub use panoc_cache::PANOCCache;                                                                                         
  |         ^^^^^^^^^^^                                                                                                      
  |                                                                                                                          
note: this import refers to the module defined here                                                                          
 --> src/core/panoc/mod.rs:3:1                                                                                               
  |                                                                                                                          
3 | mod panoc_cache;                                                                                                         
  | ^^^^^^^^^^^^^^^^                                                                                                         
                                                                                                                             
error[E0658]: imports can only refer to extern crate names passed with `--extern` on stable channel (see issue #53130)       
  --> src/core/mod.rs:12:9                                                                                                   
   |                                                                                                                         
8  | pub mod solver_status;                                                                                                  
   | ---------------------- not an extern crate passed with `--extern`                                                       
...                                                                                                                          
12 | pub use solver_status::SolverStatus;                                                                                    
   |         ^^^^^^^^^^^^^                                                                                                   
   |                                                                                                                         
note: this import refers to the module defined here                                                                          
  --> src/core/mod.rs:8:1                                                                                                    
   |                                                                                                                         
8  | pub mod solver_status;                                                                                                  
   | ^^^^^^^^^^^^^^^^^^^^^^                                                                                                  
                                                                                                                             
error: aborting due to 9 previous errors                                                                                     
                                                                                                                             
For more information about this error, try `rustc --explain E0658`.                                                          
error: Could not compile `optimization_engine`.                                                                              

To learn more, run the command again with --verbose.

Expected behavior
A clear and concise description of what you expected to happen.

System information:

  • Ubuntu 14.04
  • Rust: rustc 1.31.0 (abe02cefd 2018-12-04)

Additional context
The issue happens only on emil_fixes, but not on master. Related to pull request #13.

Python Example Error

I am trying your example from webpage and I am getting following error:

Traceback (most recent call last):
File "Example.py", line 35, in
builder.build()
File "/usr/local/lib/python2.7/dist-packages/opengen/builder/optimizer_builder.py", line 347, in build
self.__build_optimizer() # build overall project
File "/usr/local/lib/python2.7/dist-packages/opengen/builder/optimizer_builder.py", line 260, in __build_optimizer
raise Exception('Rust build failed')
Exception: Rust build failed

+ Rust is installed
rustc 1.35.0 (3c235d560 2019-05-20)
rustup show
Default host: x86_64-unknown-linux-gnu

stable-x86_64-unknown-linux-gnu (default)
rustc 1.35.0 (3c235d560 2019-05-20)
  • The code:
import casadi.casadi as cs
import opengen as og

u = cs.SX.sym("u", 5) # decision variable (nu = 5)
p = cs.SX.sym("p", 2) # parameter (np = 2)
phi = og.functions.rosenbrock(u, p) # cost function

bounds = og.constraints.Ball2(None, 1.5) # ball centered at origin

problem = og.builder.Problem(u, p, phi).with_constraints(bounds)

meta = og.config.OptimizerMeta()
.with_version("0.0.0")
.with_authors(["P. Sopasakis", "E. Fresk"])
.with_licence("CC4.0-By")
.with_optimizer_name("the_optimizer")

build_config = og.config.BuildConfiguration()
.with_build_directory("python_build")
.with_build_mode("debug")

solver_config = og.config.SolverConfiguration()
.with_lfbgs_memory(15)
.with_tolerance(1e-5)
.with_max_inner_iterations(155)

builder = og.builder.OpEnOptimizerBuilder(problem,
metadata=meta,
build_configuration=build_config,
solver_configuration=solver_config)
builder.enable_tcp_interface()
builder.build()

mng = og.tcp.OptimizerTcpManager('python_build/the_optimizer')
mng.start()

pong = mng.ping() # check if the server is alive
print(pong)
solution = mng.call([1.0, 50.0]) # call the solver over TCP
print(solution)

mng.kill()

Describe the bug

A clear and concise description of what the bug is.

To Reproduce

Steps to reproduce the behavior:

  1. Step 1
  2. Step 2.
  3. See error

Expected behavior

A clear and concise description of what you expected to happen.

System information:

โš ๏ธ Please, provide the following information:

  • System/Platform [e.g., Intel i5, Raspeberry Pi Model B, Mobile device, etc]
  • OS: [e.g. Ubuntu, iOS, Windows, Raspbian, etc]
  • What is the output of rustup show?
  • What is the output of rustc -V?
  • Python/MATLAB version if relevant

Additional context

Add any other context about the problem here.

Additional termination criterion

Is your feature request related to a problem? Please describe.
We need an additional termination criterion. For the problem:

Minimise_u f(u)
subj. to: u in U

we need to add the termination condition:

|| r + df(u_bar) - df(u) || <= eps,

where r is the fixed-point residual, df is the gradient of f, u_bar is the proximal gradient step that corresponds to u and and eps is a user-specified tolerance.

Describe the solution you'd like
The termination condition is inactive (e.g., we can use an Option<f64> for the tolerance parameter).

Describe alternatives you've considered
N/A

Additional context
We need this in order to implement ALM.

Design consideration: move tolerance into the optimizer

Currently we store the tolerance in the cache, but it seems to me that storing it in the optimizer would make more sense. For example, we have a setter method in panoc_optimizer which is as follows:

pub fn with_tolerance(
        mut self,
        tolerance: f64,
    ) -> Self {
        assert!(tolerance > 0.0, "tolerance must be larger than 0");
        self.panoc_engine.cache.tolerance = tolerance;
        self
    }

and it sets the tolerance in the cache object.

I am currently addressing issue #70 where we will need to introduce another tolerance value (namely, the akkt_tolerance). I think it makes more sense to have these tolerances be part of the optimizer.

TCP interface uses fixed read buffer which may overflow

Describe the bug
In lines 162-170 of the auto-generated TCP interface, in Rust, we have the following code

let mut bytes_buffer = vec![0u8; 1024];
stream
   .read(&mut bytes_buffer)
    .expect("count not read stream");
let message_len = bytes_buffer.iter().position(|&r| r == EOF).unwrap() as usize;
let buffer = String::from_utf8(bytes_buffer[0..message_len].to_vec()).unwrap();

The buffer length may not be sufficient to read large requests. We need to iterate over chunks of the input stream until we reach EOF (this is 0u8).

To Reproduce
It hasn't happened yet, but I'm sure it will (change 1024 to something small, e.g., 8, to verify it).

Expected behavior
Requests of arbitrary length should be properly processed.

System information:
Not relevant

Additional context
None

Documentation: benchmarks

Present some benchmarks in the documentation (FPR-vs-time, solution time-vs-problem size, some practical examples and code snippets)

Tolerance relaxation

In the penalty method we currently use the same tolerance for all instances of the inner solver. We can start with a higher tolerance, epsilon_0, and decrease it by multiplying by a 0<beta<1 (e.g., 0.1) until it reaches the target tolerance. Overall, this might save iterations in some cases.

This should be optional (for now) by setting the default initial tolerance equal to the target tolerance and allow the user to override this. We can later see whether it improves things and determine a meaningful initial tolerance and update parameter.

Ergonomics

The current ergonomics of the interface needs to be updated to make it more intuitive.
We should look into simplifying the steps to make an optimizer, such as:

  • Merging the Engine and Optimizer (the engine is always an input to the optimizer)
  • Finding a way to abstract away the NonZero... while it gives us type safety, it clutters the interface
  • Looking into a single line definition of an optimizer (needs some thought)
  • The imports are non-trivial (it should be like use panoc::*; or use fbs::*; - we should probably just have a prelude module to fix this

Improve docs to differentiate with_constraints and with_penalty_constraints

Currently in the documentation it is not quite clear, and I have already seen code where people only use penalty constraints (even for simple bounds on the decision variables).
I think we need to have a small guidelines section, like follow a 1. 2. 3. to make a normal solver to guide people through the process :)

Constraints on finite sets

Is your feature request related to a problem? Please describe.
No

Describe the solution you'd like
Add support for constraints on finite sets, that is, when U is of the form U = {u^1, u^2, ..., u^m} (e.g., binary constraints).

Describe alternatives you've considered
Similar to other constraints

Additional context
Should be easy.

Cartesian product of constraints

Is your feature request related to a problem? Please describe.
No.

Describe the solution you'd like
Add support for the Cartesian product of constraints in Rust and then in Python and MATLAB. This will allow to support products of Rectangles and Euclidean balls.

Describe alternatives you've considered
The Cartesian product of constraints will map indices to instances of ConstraintType

Additional context
None

Travis support for Python code generator

Is your feature request related to a problem? Please describe.
No

Describe the solution you'd like
Travis CI support for the Python code generator

Describe alternatives you've considered

  • Write tests in Python
  • Write a test script for Travis
  • Test travis and test with different version of Python

Additional context
None

C/C++ interface

Hello,

Are there any plans to make a C and/or C++ (my personal preference) interface?

Cheers!

Examples

We need to add examples in the standard Rust examples directory.

Cargo build fails with MSVC on Windows

Describe the bug
Dear Community,

in my effort in setting the proper format in running OptimizationEngine in Windows through Matlab, along with the hints pointed out yesterday in the previous issue I started, there seems to be some other minor problems. Having changed the content of the matlab_open_root in the Matlab Interface as indicated by @alphaville to the following:

function open_root = matlab_open_root()

this_file_path = which('matlab_open_root');
matlab_path_str = fileparts(this_file_path);
matlab_path_file = java.io.File(matlab_path_str);
open_root = char(matlab_path_file.getParent());

solved some issues but then when I compile the example_open_1 document I get the following message:

example_open_1
   Compiling cc v1.0.37
   Compiling libc v0.2.55
   Compiling icasadi v0.1.2 (C:\optimization-engine-master\optimization-engine-master\build\autogenerated_optimizer\icasadi)
error: failed to run custom build command for `icasadi v0.1.2 (C:\optimization-engine-master\optimization-engine-master\build\autogenerated_optimizer\icasadi)`
process didn't exit successfully: `C:\optimization-engine-master\optimization-engine-master\build\autogenerated_optimizer\icasadi\target\release\build\icasadi-4c7d82453aee18ad\build-script-build` (exit code: 1)
--- stdout
TARGET = Some("x86_64-pc-windows-msvc")
OPT_LEVEL = Some("3")
HOST = Some("x86_64-pc-windows-msvc")
CC_x86_64-pc-windows-msvc = None
CC_x86_64_pc_windows_msvc = None
HOST_CC = None
CC = None
CFLAGS_x86_64-pc-windows-msvc = None
CFLAGS_x86_64_pc_windows_msvc = None
HOST_CFLAGS = None
CFLAGS = None
CRATE_CC_NO_DEFAULTS = None
CARGO_CFG_TARGET_FEATURE = Some("fxsr,sse,sse2")
DEBUG = Some("false")
CC_x86_64-pc-windows-msvc = None
CC_x86_64_pc_windows_msvc = None
HOST_CC = None
CC = None
CFLAGS_x86_64-pc-windows-msvc = None
CFLAGS_x86_64_pc_windows_msvc = None
HOST_CFLAGS = None
CFLAGS = None
CRATE_CC_NO_DEFAULTS = None
CARGO_CFG_TARGET_FEATURE = Some("fxsr,sse,sse2")
CC_x86_64-pc-windows-msvc = None
CC_x86_64_pc_windows_msvc = None
HOST_CC = None
CC = None
CFLAGS_x86_64-pc-windows-msvc = None
CFLAGS_x86_64_pc_windows_msvc = None
HOST_CFLAGS = None
CFLAGS = None
CRATE_CC_NO_DEFAULTS = None
CARGO_CFG_TARGET_FEATURE = Some("fxsr,sse,sse2")
CC_x86_64-pc-windows-msvc = None
CC_x86_64_pc_windows_msvc = None
HOST_CC = None
CC = None
CFLAGS_x86_64-pc-windows-msvc = None
CFLAGS_x86_64_pc_windows_msvc = None
HOST_CFLAGS = None
CFLAGS = None
CRATE_CC_NO_DEFAULTS = None
CARGO_CFG_TARGET_FEATURE = Some("fxsr,sse,sse2")
running: "C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community\\VC\\Tools\\MSVC\\14.16.27023\\bin\\HostX64\\x64\\cl.exe" "/nologo" "/MD" "/O2" "/I" "src" "/W4" "-Wno-unused-parameter" "-Wall" "/FoC:\\optimization-engine-master\\optimization-engine-master\\build\\autogenerated_optimizer\\icasadi\\target\\release\\build\\icasadi-7eaa844b72b47fd5\\out\\extern\\auto_casadi_cost.o" "/c" "extern/auto_casadi_cost.c"
cargo:warning=cl : Command line error D8021 : invalid numeric argument '/Wno-unused-parameter' 
exit code: 2

--- stderr


error occurred: Command "C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community\\VC\\Tools\\MSVC\\14.16.27023\\bin\\HostX64\\x64\\cl.exe" "/nologo" "/MD" "/O2" "/I" "src" "/W4" "-Wno-unused-parameter" "-Wall" "/FoC:\\optimization-engine-master\\optimization-engine-master\\build\\autogenerated_optimizer\\icasadi\\target\\release\\build\\icasadi-7eaa844b72b47fd5\\out\\extern\\auto_casadi_cost.o" "/c" "extern/auto_casadi_cost.c" with args "cl.exe" did not execute successfully (status code exit code: 2).



[codegen] Build command: cargo build
   Compiling autocfg v0.1.4
   Compiling num-bigint v0.2.2
   Compiling proc-macro2 v0.4.30
   Compiling unicode-xid v0.1.0
   Compiling num-rational v0.2.1
   Compiling num-complex v0.2.1
   Compiling syn v0.15.34
   Compiling libc v0.2.55
   Compiling serde v1.0.91
   Compiling cc v1.0.37
   Compiling ryu v0.2.8
   Compiling itoa v0.4.4
   Compiling num-traits v0.2.8
   Compiling num-integer v0.1.41
   Compiling num-iter v0.1.39
   Compiling icasadi v0.1.2 (C:\optimization-engine-master\optimization-engine-master\build\autogenerated_optimizer\icasadi)
   Compiling quote v0.6.12
error: failed to run custom build command for `icasadi v0.1.2 (C:\optimization-engine-master\optimization-engine-master\build\autogenerated_optimizer\icasadi)`
process didn't exit successfully: `C:\optimization-engine-master\optimization-engine-master\build\autogenerated_optimizer\target\debug\build\icasadi-ff7105e17f623f1b\build-script-build` (exit code: 1)
--- stdout
TARGET = Some("x86_64-pc-windows-msvc")
OPT_LEVEL = Some("0")
HOST = Some("x86_64-pc-windows-msvc")
CC_x86_64-pc-windows-msvc = None
CC_x86_64_pc_windows_msvc = None
HOST_CC = None
CC = None
CFLAGS_x86_64-pc-windows-msvc = None
CFLAGS_x86_64_pc_windows_msvc = None
HOST_CFLAGS = None
CFLAGS = None
CRATE_CC_NO_DEFAULTS = None
CARGO_CFG_TARGET_FEATURE = Some("fxsr,sse,sse2")
DEBUG = Some("true")
CC_x86_64-pc-windows-msvc = None
CC_x86_64_pc_windows_msvc = None
HOST_CC = None
CC = None
CFLAGS_x86_64-pc-windows-msvc = None
CFLAGS_x86_64_pc_windows_msvc = None
HOST_CFLAGS = None
CFLAGS = None
CRATE_CC_NO_DEFAULTS = None
CARGO_CFG_TARGET_FEATURE = Some("fxsr,sse,sse2")
CC_x86_64-pc-windows-msvc = None
CC_x86_64_pc_windows_msvc = None
HOST_CC = None
CC = None
CFLAGS_x86_64-pc-windows-msvc = None
CFLAGS_x86_64_pc_windows_msvc = None
HOST_CFLAGS = None
CFLAGS = None
CRATE_CC_NO_DEFAULTS = None
CARGO_CFG_TARGET_FEATURE = Some("fxsr,sse,sse2")
CC_x86_64-pc-windows-msvc = None
CC_x86_64_pc_windows_msvc = None
HOST_CC = None
CC = None
CFLAGS_x86_64-pc-windows-msvc = None
CFLAGS_x86_64_pc_windows_msvc = None
HOST_CFLAGS = None
CFLAGS = None
CRATE_CC_NO_DEFAULTS = None
CARGO_CFG_TARGET_FEATURE = Some("fxsr,sse,sse2")
running: "C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community\\VC\\Tools\\MSVC\\14.16.27023\\bin\\HostX64\\x64\\cl.exe" "/nologo" "/MD" "/Z7" "/I" "src" "/W4" "-Wno-unused-parameter" "-Wall" "/FoC:\\optimization-engine-master\\optimization-engine-master\\build\\autogenerated_optimizer\\target\\debug\\build\\icasadi-081876f384fb7888\\out\\extern\\auto_casadi_cost.o" "/c" "extern/auto_casadi_cost.c"
cargo:warning=cl : Command line error D8021 : invalid numeric argument '/Wno-unused-parameter' 
exit code: 2

--- stderr


error occurred: Command "C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community\\VC\\Tools\\MSVC\\14.16.27023\\bin\\HostX64\\x64\\cl.exe" "/nologo" "/MD" "/Z7" "/I" "src" "/W4" "-Wno-unused-parameter" "-Wall" "/FoC:\\optimization-engine-master\\optimization-engine-master\\build\\autogenerated_optimizer\\target\\debug\\build\\icasadi-081876f384fb7888\\out\\extern\\auto_casadi_cost.o" "/c" "extern/auto_casadi_cost.c" with args "cl.exe" did not execute successfully (status code exit code: 2).



warning: build failed, waiting for other jobs to finish...
error: build failed
Warning: Unsuccessful read:  The specified amount of data was not returned within the Timeout period.
'udp' unable to read any data. For more information on possible reasons, see UDP Read Warnings. 
Error using jsondecode
JSON syntax error: expected value but found end of text.

Error in OpEnOptimizer/consume (line 59)
            out = jsondecode(json_response);

Error in example_open_1 (line 14)
out = opEnOptimizer.consume([1,2]);

To me the issue is with the part of the error mentioning that:

extern\\auto_casadi_cost.o" "/c" "extern/auto_casadi_cost.c" with args "cl.exe" did not execute successfully (status code exit code: 2).

I am using Windows 64-bit OS and the C compiler is MSVC in Matlab R2019a version and the most recent version of Rust and CasADi.

Any help would be appreciated.

Thank you.

Appveyor support

We had some Windows-related issues, so it's a good idea to have CI on Appveyor. I started a branch called feature/appveyor.

Penalty method in Rust

Is your feature request related to a problem? Please describe.
Implement the penalty method in Rust.

Describe the solution you'd like

-We first need to define a type (a closure) for penalty functions. These should not depend on the weights.

  • We need something like icasadi to be able to interface such penalty functions written in C (generated by CasADi).
  • We need a new trait that will define the penalty method and will allow the use of any numerical algorithm for solving the individual problems.

Describe alternatives you've considered
We can either extend icasadi into a generic code generation tool, or create a new module for penalty functions. I'd prefer the first option.

Additional context
We should keep in mind that the next step should be the implementation of the Augmented Lagrangian method. In fact, the user may choose to use the penalty method on some constraints and AL on other ones.

Error using directory handle mkdir

Dear Developers,

some days ago, I wanted to experiment with OptimizationEngine OpEn you have developed. My aim was to run the Rust project through the Matlab Interface. After having installed Rust from https://alphaville.github.io/optimization-engine/docs/installation. I followed the instructions and downloaded as well the Optimization Engine along with the CasADi Toolbox. I have put the CasADi Toolbox inside the folder "optimization-engine-master" (the folder I get after unzipping the Optimization Engine). After adding the Optimization Engine I ran the following code to activate CasADi:

addpath('<yourpath>/casadi-windows-matlabR2016a-v3.4.5')
import casadi.*
x = MX.sym('x')
disp(jacobian(sin(x),x))

I wanted to run the example_open_1 and when I stepped in line 9

opEnOptimizer = opEnBuilder.build();

I got the following messages.

Error using mkdir
The system cannot find the path specified.

Error in OpEnOptimizerBuilder/build>clean_destination (line 153)
    mkdir(destination_dir);

Error in OpEnOptimizerBuilder/build (line 38)
clean_destination(opEnBuilder);

Error in example_open_lv (line 24)
optimizer = builder.build();

The destination folder is inside the @OpEnOptimizerBuilder within cd /matlab of the Optimization Engine folder and the current folder is cd /matlab. However, I am not allowed to switch to the destination folder (@OpEnOptimizerBuilder) because it is deemed as a method.

I have the R2019a Matlab version and 64-bit Windows Operating System.

Any help would be appreciated.

Set initial guess over UDP

Is your feature request related to a problem? Please describe.
The user may need to update (or reset) the initial guess over UDP.

Describe the solution you'd like
The issue is that if an instance of the optimizer fails to converge, the approximate solution will be provided to the next instance. In some cases, the solver may return NaN as the solution. Such solutions should never be used to initialise the next instance of the solver.

Describe alternatives you've considered

Additional context
Once implemented, the documentation has to be updated.

Min/Max constraint for OpEnConstraints in Matlab

Is your feature request related to a problem? Please describe.

When the descision variables (u1 u2 u3) have different magnitudes the "make_ball" constraints are not really suitable.

Describe the solution you'd like

An alternative OpEnConstraints that takes Umin and Umax as input vectors.

Describe alternatives you've considered

Tried to implement it myself since the "rectangle.rs" file is already there, but failed miserably due to no knowledge of rust.

Builder options to be moved to BuildConfiguration

Builder options should be moved to BuildConfiguration. For example, instead of

builder.enable_c_bindings_generation()

or

builder.enable_tcp_interface()

We should rather do

build_config = og.config.BuildConfiguration() \
    .with_build_directory("python_test_build") \
    .with_build_mode("debug")
    .with_build_c_bindings(True)
    .with_tcp_interface_config(tcp_config)

๐Ÿ“ @korken89 Let's merge PR #37 and we'll resolve this afterwards.

Issues with sending/receiving large requests via TCP/IP

Describe the bug

When calling the solver via TCP/IP with

solution = mng.call(z0, initial_guess=[0.0]*(nu * N))

I get the JSON error message

File "/usr/lib/python3.5/json/decoder.py", line 357, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 167 column 1 (char 4096)

using a parameter of size 41 and 240 decision variables (Control Horizon 40).
Running the same code with parameter size of 41 but 12 decision variables (Control Horizon 2) it works as it should. Seems to be a problem with the buffer but changing READ_BUFFER_SIZE in tcp_iface/main.rs doesn't fix it.

To Reproduce

Steps to reproduce the behavior:
Run the provided python code (provided as .txt file) with N=40 (line 8) for error and N=2 for success (actually any N smaller than 27 ).

crazyflie_multiple.txt

Appveyor fails

Describe the bug
Appveyor fails after merging dev/python. The issue seems to be related to bindgen. Perhaps we can copy the appveyor configuration from here.

In particular, with MSVC and target=i686-pc-windows-msvc, we get

thread 'main' panicked at 'Unable to find libclang: "couldn\'t find any valid shared libraries matching: [\'clang.dll\', \'libclang.dll\'], set the `LIBCLANG_PATH` environment variable to a path where one of these files can be found (invalid: [(C:\\Program Files\\LLVM\\bin\\libclang.dll: invalid DLL (64-bit))])"', src\libcore\result.rs:997:5
note: Run with `RUST_BACKTRACE=1` environment variable to display a backtrace.

With target=x86_64-pc-windows-gnu, we get

error occurred: Failed to find tool. Is `gcc.exe` installed? (see https://github.com/alexcrichton/cc-rs#compile-time-requirements for help)

To Reproduce
Check appveyor

Expected behavior
It used to work some time ago.

System information:

  • Windows 686
  • Windows 32 or 64 + GCC

Additional context

Cargo build fails with MSVC on Windows version II

I removed from \optimization-engine-master \icasadi\src\build.rs line 8 as well as the same line from the \optimization-engine-master\build\autogenerated_optimizer\icasadi\src\build.rs and ran the example_open_1 again and this time I ended up with the following message:

Compiling icasadi v0.1.2 (C:\optimization-engine-master\optimization-engine-master\build\autogenerated_optimizer\icasadi)
    Finished release [optimized] target(s) in 2.60s
[codegen] Build command: cargo build
   Compiling icasadi v0.1.2 (C:\optimization-engine-master\optimization-engine-master\build\autogenerated_optimizer\icasadi)
   Compiling optimization_engine v0.3.1 (C:\optimization-engine-master\optimization-engine-master)
error[E0463]: can't find crate for `num`
  --> C:\optimization-engine-master\optimization-engine-master\src\lib.rs:15:1
   |
15 | extern crate num;
   | ^^^^^^^^^^^^^^^^^ can't find crate

error: aborting due to previous error

For more information about this error, try `rustc --explain E0463`.
error: Could not compile `optimization_engine`.
warning: build failed, waiting for other jobs to finish...
error: build failed
Warning: Unsuccessful read:  The specified amount of data was not returned within the Timeout period.
'udp' unable to read any data. For more information on possible reasons, see UDP Read Warnings. 
Error using jsondecode
JSON syntax error: expected value but found end of text.

Error in OpEnOptimizer/consume (line 59)
            out = jsondecode(json_response);

Error in example_open_1 (line 14)
out = opEnOptimizer.consume([1,2]);

Also when I ran the command rustup show in the command window I got:

stable-x86_64-pc-windows-msvc (default)
rustc 1.34.1 (fc50f328b 2019-04-24)

Borrowing/move field seems to move the whole structure

Describe the bug
Described in detail here. In brief: the borrow checker is giving me some trouble.

To Reproduce
Steps to reproduce the behavior: Checkout feature/homotopy and run cargo test.

Expected behavior

System information:
Not relevant

Additional context
Changes in that branch: constraints are borrowed by the Problem. This was done to resolve some other issues. The build fails.

OSX: malformed object (unknown load command 1)

I'm filing this on behalf of @panpat

Describe the bug

Panos is getting the following error when running cargo build in an auto-generated optimizer:

--- stderr


error occurred: Command "ar" "crs" "/Users/panospatrinos 1/Documents/optimization-engine/open-codegen/python_test_build/tcp_enabled_optimizer/target/debug/build/libloading-ffbc4424520e2553/out/libglobal_static.a" "/Users/panospatrinos 1/Documents/optimization-engine/open-codegen/python_test_build/tcp_enabled_optimizer/target/debug/build/libloading-ffbc4424520e2553/out/src/os/unix/global_static.o" with args "ar" did not execute successfully (status code exit code: 1).



warning: build failed, waiting for other jobs to finish...
error: failed to run custom build command for `backtrace-sys v0.1.28`
process didn't exit successfully: `/Users/panospatrinos 1/Documents/optimization-engine/open-codegen/python_test_build/tcp_enabled_optimizer/target/debug/build/backtrace-sys-f56a36e4527a27f8/build-script-build` (exit code: 1)
--- stdout
cargo:rustc-cfg=rbt
TARGET = Some("x86_64-apple-darwin")
OPT_LEVEL = Some("0")
HOST = Some("x86_64-apple-darwin")
CC_x86_64-apple-darwin = None
CC_x86_64_apple_darwin = None
HOST_CC = None
CC = None
CFLAGS_x86_64-apple-darwin = None
CFLAGS_x86_64_apple_darwin = None
HOST_CFLAGS = None
CFLAGS = None
CRATE_CC_NO_DEFAULTS = None
CARGO_CFG_TARGET_FEATURE = Some("fxsr,sse,sse2,sse3,ssse3")
running: "cc" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-m64" "-I" "src/libbacktrace" "-I" "/Users/panospatrinos 1/Documents/optimization-engine/open-codegen/python_test_build/tcp_enabled_optimizer/target/debug/build/backtrace-sys-6785d537ab627d53/out" "-fvisibility=hidden" "-DBACKTRACE_SUPPORTED=1" "-DBACKTRACE_USES_MALLOC=1" "-DBACKTRACE_SUPPORTS_THREADS=0" "-DBACKTRACE_SUPPORTS_DATA=0" "-DHAVE_DL_ITERATE_PHDR=1" "-D_GNU_SOURCE=1" "-D_LARGE_FILES=1" "-Dbacktrace_full=__rbt_backtrace_full" "-Dbacktrace_dwarf_add=__rbt_backtrace_dwarf_add" "-Dbacktrace_initialize=__rbt_backtrace_initialize" "-Dbacktrace_pcinfo=__rbt_backtrace_pcinfo" "-Dbacktrace_syminfo=__rbt_backtrace_syminfo" "-Dbacktrace_get_view=__rbt_backtrace_get_view" "-Dbacktrace_release_view=__rbt_backtrace_release_view" "-Dbacktrace_alloc=__rbt_backtrace_alloc" "-Dbacktrace_free=__rbt_backtrace_free" "-Dbacktrace_vector_finish=__rbt_backtrace_vector_finish" "-Dbacktrace_vector_grow=__rbt_backtrace_vector_grow" "-Dbacktrace_vector_release=__rbt_backtrace_vector_release" "-Dbacktrace_close=__rbt_backtrace_close" "-Dbacktrace_open=__rbt_backtrace_open" "-Dbacktrace_print=__rbt_backtrace_print" "-Dbacktrace_simple=__rbt_backtrace_simple" "-Dbacktrace_qsort=__rbt_backtrace_qsort" "-Dbacktrace_create_state=__rbt_backtrace_create_state" "-Dbacktrace_uncompress_zdebug=__rbt_backtrace_uncompress_zdebug" "-o" "/Users/panospatrinos 1/Documents/optimization-engine/open-codegen/python_test_build/tcp_enabled_optimizer/target/debug/build/backtrace-sys-6785d537ab627d53/out/src/libbacktrace/alloc.o" "-c" "src/libbacktrace/alloc.c"
exit code: 0
running: "cc" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-m64" "-I" "src/libbacktrace" "-I" "/Users/panospatrinos 1/Documents/optimization-engine/open-codegen/python_test_build/tcp_enabled_optimizer/target/debug/build/backtrace-sys-6785d537ab627d53/out" "-fvisibility=hidden" "-DBACKTRACE_SUPPORTED=1" "-DBACKTRACE_USES_MALLOC=1" "-DBACKTRACE_SUPPORTS_THREADS=0" "-DBACKTRACE_SUPPORTS_DATA=0" "-DHAVE_DL_ITERATE_PHDR=1" "-D_GNU_SOURCE=1" "-D_LARGE_FILES=1" "-Dbacktrace_full=__rbt_backtrace_full" "-Dbacktrace_dwarf_add=__rbt_backtrace_dwarf_add" "-Dbacktrace_initialize=__rbt_backtrace_initialize" "-Dbacktrace_pcinfo=__rbt_backtrace_pcinfo" "-Dbacktrace_syminfo=__rbt_backtrace_syminfo" "-Dbacktrace_get_view=__rbt_backtrace_get_view" "-Dbacktrace_release_view=__rbt_backtrace_release_view" "-Dbacktrace_alloc=__rbt_backtrace_alloc" "-Dbacktrace_free=__rbt_backtrace_free" "-Dbacktrace_vector_finish=__rbt_backtrace_vector_finish" "-Dbacktrace_vector_grow=__rbt_backtrace_vector_grow" "-Dbacktrace_vector_release=__rbt_backtrace_vector_release" "-Dbacktrace_close=__rbt_backtrace_close" "-Dbacktrace_open=__rbt_backtrace_open" "-Dbacktrace_print=__rbt_backtrace_print" "-Dbacktrace_simple=__rbt_backtrace_simple" "-Dbacktrace_qsort=__rbt_backtrace_qsort" "-Dbacktrace_create_state=__rbt_backtrace_create_state" "-Dbacktrace_uncompress_zdebug=__rbt_backtrace_uncompress_zdebug" "-o" "/Users/panospatrinos 1/Documents/optimization-engine/open-codegen/python_test_build/tcp_enabled_optimizer/target/debug/build/backtrace-sys-6785d537ab627d53/out/src/libbacktrace/dwarf.o" "-c" "src/libbacktrace/dwarf.c"
exit code: 0
running: "cc" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-m64" "-I" "src/libbacktrace" "-I" "/Users/panospatrinos 1/Documents/optimization-engine/open-codegen/python_test_build/tcp_enabled_optimizer/target/debug/build/backtrace-sys-6785d537ab627d53/out" "-fvisibility=hidden" "-DBACKTRACE_SUPPORTED=1" "-DBACKTRACE_USES_MALLOC=1" "-DBACKTRACE_SUPPORTS_THREADS=0" "-DBACKTRACE_SUPPORTS_DATA=0" "-DHAVE_DL_ITERATE_PHDR=1" "-D_GNU_SOURCE=1" "-D_LARGE_FILES=1" "-Dbacktrace_full=__rbt_backtrace_full" "-Dbacktrace_dwarf_add=__rbt_backtrace_dwarf_add" "-Dbacktrace_initialize=__rbt_backtrace_initialize" "-Dbacktrace_pcinfo=__rbt_backtrace_pcinfo" "-Dbacktrace_syminfo=__rbt_backtrace_syminfo" "-Dbacktrace_get_view=__rbt_backtrace_get_view" "-Dbacktrace_release_view=__rbt_backtrace_release_view" "-Dbacktrace_alloc=__rbt_backtrace_alloc" "-Dbacktrace_free=__rbt_backtrace_free" "-Dbacktrace_vector_finish=__rbt_backtrace_vector_finish" "-Dbacktrace_vector_grow=__rbt_backtrace_vector_grow" "-Dbacktrace_vector_release=__rbt_backtrace_vector_release" "-Dbacktrace_close=__rbt_backtrace_close" "-Dbacktrace_open=__rbt_backtrace_open" "-Dbacktrace_print=__rbt_backtrace_print" "-Dbacktrace_simple=__rbt_backtrace_simple" "-Dbacktrace_qsort=__rbt_backtrace_qsort" "-Dbacktrace_create_state=__rbt_backtrace_create_state" "-Dbacktrace_uncompress_zdebug=__rbt_backtrace_uncompress_zdebug" "-o" "/Users/panospatrinos 1/Documents/optimization-engine/open-codegen/python_test_build/tcp_enabled_optimizer/target/debug/build/backtrace-sys-6785d537ab627d53/out/src/libbacktrace/fileline.o" "-c" "src/libbacktrace/fileline.c"
exit code: 0
running: "cc" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-m64" "-I" "src/libbacktrace" "-I" "/Users/panospatrinos 1/Documents/optimization-engine/open-codegen/python_test_build/tcp_enabled_optimizer/target/debug/build/backtrace-sys-6785d537ab627d53/out" "-fvisibility=hidden" "-DBACKTRACE_SUPPORTED=1" "-DBACKTRACE_USES_MALLOC=1" "-DBACKTRACE_SUPPORTS_THREADS=0" "-DBACKTRACE_SUPPORTS_DATA=0" "-DHAVE_DL_ITERATE_PHDR=1" "-D_GNU_SOURCE=1" "-D_LARGE_FILES=1" "-Dbacktrace_full=__rbt_backtrace_full" "-Dbacktrace_dwarf_add=__rbt_backtrace_dwarf_add" "-Dbacktrace_initialize=__rbt_backtrace_initialize" "-Dbacktrace_pcinfo=__rbt_backtrace_pcinfo" "-Dbacktrace_syminfo=__rbt_backtrace_syminfo" "-Dbacktrace_get_view=__rbt_backtrace_get_view" "-Dbacktrace_release_view=__rbt_backtrace_release_view" "-Dbacktrace_alloc=__rbt_backtrace_alloc" "-Dbacktrace_free=__rbt_backtrace_free" "-Dbacktrace_vector_finish=__rbt_backtrace_vector_finish" "-Dbacktrace_vector_grow=__rbt_backtrace_vector_grow" "-Dbacktrace_vector_release=__rbt_backtrace_vector_release" "-Dbacktrace_close=__rbt_backtrace_close" "-Dbacktrace_open=__rbt_backtrace_open" "-Dbacktrace_print=__rbt_backtrace_print" "-Dbacktrace_simple=__rbt_backtrace_simple" "-Dbacktrace_qsort=__rbt_backtrace_qsort" "-Dbacktrace_create_state=__rbt_backtrace_create_state" "-Dbacktrace_uncompress_zdebug=__rbt_backtrace_uncompress_zdebug" "-o" "/Users/panospatrinos 1/Documents/optimization-engine/open-codegen/python_test_build/tcp_enabled_optimizer/target/debug/build/backtrace-sys-6785d537ab627d53/out/src/libbacktrace/posix.o" "-c" "src/libbacktrace/posix.c"
exit code: 0
running: "cc" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-m64" "-I" "src/libbacktrace" "-I" "/Users/panospatrinos 1/Documents/optimization-engine/open-codegen/python_test_build/tcp_enabled_optimizer/target/debug/build/backtrace-sys-6785d537ab627d53/out" "-fvisibility=hidden" "-DBACKTRACE_SUPPORTED=1" "-DBACKTRACE_USES_MALLOC=1" "-DBACKTRACE_SUPPORTS_THREADS=0" "-DBACKTRACE_SUPPORTS_DATA=0" "-DHAVE_DL_ITERATE_PHDR=1" "-D_GNU_SOURCE=1" "-D_LARGE_FILES=1" "-Dbacktrace_full=__rbt_backtrace_full" "-Dbacktrace_dwarf_add=__rbt_backtrace_dwarf_add" "-Dbacktrace_initialize=__rbt_backtrace_initialize" "-Dbacktrace_pcinfo=__rbt_backtrace_pcinfo" "-Dbacktrace_syminfo=__rbt_backtrace_syminfo" "-Dbacktrace_get_view=__rbt_backtrace_get_view" "-Dbacktrace_release_view=__rbt_backtrace_release_view" "-Dbacktrace_alloc=__rbt_backtrace_alloc" "-Dbacktrace_free=__rbt_backtrace_free" "-Dbacktrace_vector_finish=__rbt_backtrace_vector_finish" "-Dbacktrace_vector_grow=__rbt_backtrace_vector_grow" "-Dbacktrace_vector_release=__rbt_backtrace_vector_release" "-Dbacktrace_close=__rbt_backtrace_close" "-Dbacktrace_open=__rbt_backtrace_open" "-Dbacktrace_print=__rbt_backtrace_print" "-Dbacktrace_simple=__rbt_backtrace_simple" "-Dbacktrace_qsort=__rbt_backtrace_qsort" "-Dbacktrace_create_state=__rbt_backtrace_create_state" "-Dbacktrace_uncompress_zdebug=__rbt_backtrace_uncompress_zdebug" "-o" "/Users/panospatrinos 1/Documents/optimization-engine/open-codegen/python_test_build/tcp_enabled_optimizer/target/debug/build/backtrace-sys-6785d537ab627d53/out/src/libbacktrace/read.o" "-c" "src/libbacktrace/read.c"
exit code: 0
running: "cc" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-m64" "-I" "src/libbacktrace" "-I" "/Users/panospatrinos 1/Documents/optimization-engine/open-codegen/python_test_build/tcp_enabled_optimizer/target/debug/build/backtrace-sys-6785d537ab627d53/out" "-fvisibility=hidden" "-DBACKTRACE_SUPPORTED=1" "-DBACKTRACE_USES_MALLOC=1" "-DBACKTRACE_SUPPORTS_THREADS=0" "-DBACKTRACE_SUPPORTS_DATA=0" "-DHAVE_DL_ITERATE_PHDR=1" "-D_GNU_SOURCE=1" "-D_LARGE_FILES=1" "-Dbacktrace_full=__rbt_backtrace_full" "-Dbacktrace_dwarf_add=__rbt_backtrace_dwarf_add" "-Dbacktrace_initialize=__rbt_backtrace_initialize" "-Dbacktrace_pcinfo=__rbt_backtrace_pcinfo" "-Dbacktrace_syminfo=__rbt_backtrace_syminfo" "-Dbacktrace_get_view=__rbt_backtrace_get_view" "-Dbacktrace_release_view=__rbt_backtrace_release_view" "-Dbacktrace_alloc=__rbt_backtrace_alloc" "-Dbacktrace_free=__rbt_backtrace_free" "-Dbacktrace_vector_finish=__rbt_backtrace_vector_finish" "-Dbacktrace_vector_grow=__rbt_backtrace_vector_grow" "-Dbacktrace_vector_release=__rbt_backtrace_vector_release" "-Dbacktrace_close=__rbt_backtrace_close" "-Dbacktrace_open=__rbt_backtrace_open" "-Dbacktrace_print=__rbt_backtrace_print" "-Dbacktrace_simple=__rbt_backtrace_simple" "-Dbacktrace_qsort=__rbt_backtrace_qsort" "-Dbacktrace_create_state=__rbt_backtrace_create_state" "-Dbacktrace_uncompress_zdebug=__rbt_backtrace_uncompress_zdebug" "-o" "/Users/panospatrinos 1/Documents/optimization-engine/open-codegen/python_test_build/tcp_enabled_optimizer/target/debug/build/backtrace-sys-6785d537ab627d53/out/src/libbacktrace/sort.o" "-c" "src/libbacktrace/sort.c"
exit code: 0
running: "cc" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-m64" "-I" "src/libbacktrace" "-I" "/Users/panospatrinos 1/Documents/optimization-engine/open-codegen/python_test_build/tcp_enabled_optimizer/target/debug/build/backtrace-sys-6785d537ab627d53/out" "-fvisibility=hidden" "-DBACKTRACE_SUPPORTED=1" "-DBACKTRACE_USES_MALLOC=1" "-DBACKTRACE_SUPPORTS_THREADS=0" "-DBACKTRACE_SUPPORTS_DATA=0" "-DHAVE_DL_ITERATE_PHDR=1" "-D_GNU_SOURCE=1" "-D_LARGE_FILES=1" "-Dbacktrace_full=__rbt_backtrace_full" "-Dbacktrace_dwarf_add=__rbt_backtrace_dwarf_add" "-Dbacktrace_initialize=__rbt_backtrace_initialize" "-Dbacktrace_pcinfo=__rbt_backtrace_pcinfo" "-Dbacktrace_syminfo=__rbt_backtrace_syminfo" "-Dbacktrace_get_view=__rbt_backtrace_get_view" "-Dbacktrace_release_view=__rbt_backtrace_release_view" "-Dbacktrace_alloc=__rbt_backtrace_alloc" "-Dbacktrace_free=__rbt_backtrace_free" "-Dbacktrace_vector_finish=__rbt_backtrace_vector_finish" "-Dbacktrace_vector_grow=__rbt_backtrace_vector_grow" "-Dbacktrace_vector_release=__rbt_backtrace_vector_release" "-Dbacktrace_close=__rbt_backtrace_close" "-Dbacktrace_open=__rbt_backtrace_open" "-Dbacktrace_print=__rbt_backtrace_print" "-Dbacktrace_simple=__rbt_backtrace_simple" "-Dbacktrace_qsort=__rbt_backtrace_qsort" "-Dbacktrace_create_state=__rbt_backtrace_create_state" "-Dbacktrace_uncompress_zdebug=__rbt_backtrace_uncompress_zdebug" "-o" "/Users/panospatrinos 1/Documents/optimization-engine/open-codegen/python_test_build/tcp_enabled_optimizer/target/debug/build/backtrace-sys-6785d537ab627d53/out/src/libbacktrace/state.o" "-c" "src/libbacktrace/state.c"
exit code: 0
running: "cc" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-m64" "-I" "src/libbacktrace" "-I" "/Users/panospatrinos 1/Documents/optimization-engine/open-codegen/python_test_build/tcp_enabled_optimizer/target/debug/build/backtrace-sys-6785d537ab627d53/out" "-fvisibility=hidden" "-DBACKTRACE_SUPPORTED=1" "-DBACKTRACE_USES_MALLOC=1" "-DBACKTRACE_SUPPORTS_THREADS=0" "-DBACKTRACE_SUPPORTS_DATA=0" "-DHAVE_DL_ITERATE_PHDR=1" "-D_GNU_SOURCE=1" "-D_LARGE_FILES=1" "-Dbacktrace_full=__rbt_backtrace_full" "-Dbacktrace_dwarf_add=__rbt_backtrace_dwarf_add" "-Dbacktrace_initialize=__rbt_backtrace_initialize" "-Dbacktrace_pcinfo=__rbt_backtrace_pcinfo" "-Dbacktrace_syminfo=__rbt_backtrace_syminfo" "-Dbacktrace_get_view=__rbt_backtrace_get_view" "-Dbacktrace_release_view=__rbt_backtrace_release_view" "-Dbacktrace_alloc=__rbt_backtrace_alloc" "-Dbacktrace_free=__rbt_backtrace_free" "-Dbacktrace_vector_finish=__rbt_backtrace_vector_finish" "-Dbacktrace_vector_grow=__rbt_backtrace_vector_grow" "-Dbacktrace_vector_release=__rbt_backtrace_vector_release" "-Dbacktrace_close=__rbt_backtrace_close" "-Dbacktrace_open=__rbt_backtrace_open" "-Dbacktrace_print=__rbt_backtrace_print" "-Dbacktrace_simple=__rbt_backtrace_simple" "-Dbacktrace_qsort=__rbt_backtrace_qsort" "-Dbacktrace_create_state=__rbt_backtrace_create_state" "-Dbacktrace_uncompress_zdebug=__rbt_backtrace_uncompress_zdebug" "-o" "/Users/panospatrinos 1/Documents/optimization-engine/open-codegen/python_test_build/tcp_enabled_optimizer/target/debug/build/backtrace-sys-6785d537ab627d53/out/src/libbacktrace/macho.o" "-c" "src/libbacktrace/macho.c"
exit code: 0
AR_x86_64-apple-darwin = None
AR_x86_64_apple_darwin = None
HOST_AR = None
AR = None
running: "ar" "crs" "/Users/panospatrinos 1/Documents/optimization-engine/open-codegen/python_test_build/tcp_enabled_optimizer/target/debug/build/backtrace-sys-6785d537ab627d53/out/libbacktrace.a" "/Users/panospatrinos 1/Documents/optimization-engine/open-codegen/python_test_build/tcp_enabled_optimizer/target/debug/build/backtrace-sys-6785d537ab627d53/out/src/libbacktrace/alloc.o" "/Users/panospatrinos 1/Documents/optimization-engine/open-codegen/python_test_build/tcp_enabled_optimizer/target/debug/build/backtrace-sys-6785d537ab627d53/out/src/libbacktrace/dwarf.o" "/Users/panospatrinos 1/Documents/optimization-engine/open-codegen/python_test_build/tcp_enabled_optimizer/target/debug/build/backtrace-sys-6785d537ab627d53/out/src/libbacktrace/fileline.o" "/Users/panospatrinos 1/Documents/optimization-engine/open-codegen/python_test_build/tcp_enabled_optimizer/target/debug/build/backtrace-sys-6785d537ab627d53/out/src/libbacktrace/posix.o" "/Users/panospatrinos 1/Documents/optimization-engine/open-codegen/python_test_build/tcp_enabled_optimizer/target/debug/build/backtrace-sys-6785d537ab627d53/out/src/libbacktrace/read.o" "/Users/panospatrinos 1/Documents/optimization-engine/open-codegen/python_test_build/tcp_enabled_optimizer/target/debug/build/backtrace-sys-6785d537ab627d53/out/src/libbacktrace/sort.o" "/Users/panospatrinos 1/Documents/optimization-engine/open-codegen/python_test_build/tcp_enabled_optimizer/target/debug/build/backtrace-sys-6785d537ab627d53/out/src/libbacktrace/state.o" "/Users/panospatrinos 1/Documents/optimization-engine/open-codegen/python_test_build/tcp_enabled_optimizer/target/debug/build/backtrace-sys-6785d537ab627d53/out/src/libbacktrace/macho.o"
cargo:warning=/opt/local/bin/ranlib: object: /Users/panospatrinos 1/Documents/optimization-engine/open-codegen/python_test_build/tcp_enabled_optimizer/target/debug/build/backtrace-sys-6785d537ab627d53/out/libbacktrace.a(alloc.o) malformed object (unknown load command 1)
cargo:warning=ar: internal ranlib command failed
exit code: 1

--- stderr


error occurred: Command "ar" "crs" "/Users/panospatrinos 1/Documents/optimization-engine/open-codegen/python_test_build/tcp_enabled_optimizer/target/debug/build/backtrace-sys-6785d537ab627d53/out/libbacktrace.a" "/Users/panospatrinos 1/Documents/optimization-engine/open-codegen/python_test_build/tcp_enabled_optimizer/target/debug/build/backtrace-sys-6785d537ab627d53/out/src/libbacktrace/alloc.o" "/Users/panospatrinos 1/Documents/optimization-engine/open-codegen/python_test_build/tcp_enabled_optimizer/target/debug/build/backtrace-sys-6785d537ab627d53/out/src/libbacktrace/dwarf.o" "/Users/panospatrinos 1/Documents/optimization-engine/open-codegen/python_test_build/tcp_enabled_optimizer/target/debug/build/backtrace-sys-6785d537ab627d53/out/src/libbacktrace/fileline.o" "/Users/panospatrinos 1/Documents/optimization-engine/open-codegen/python_test_build/tcp_enabled_optimizer/target/debug/build/backtrace-sys-6785d537ab627d53/out/src/libbacktrace/posix.o" "/Users/panospatrinos 1/Documents/optimization-engine/open-codegen/python_test_build/tcp_enabled_optimizer/target/debug/build/backtrace-sys-6785d537ab627d53/out/src/libbacktrace/read.o" "/Users/panospatrinos 1/Documents/optimization-engine/open-codegen/python_test_build/tcp_enabled_optimizer/target/debug/build/backtrace-sys-6785d537ab627d53/out/src/libbacktrace/sort.o" "/Users/panospatrinos 1/Documents/optimization-engine/open-codegen/python_test_build/tcp_enabled_optimizer/target/debug/build/backtrace-sys-6785d537ab627d53/out/src/libbacktrace/state.o" "/Users/panospatrinos 1/Documents/optimization-engine/open-codegen/python_test_build/tcp_enabled_optimizer/target/debug/build/backtrace-sys-6785d537ab627d53/out/src/libbacktrace/macho.o" with args "ar" did not execute successfully (status code exit code: 1).



warning: build failed, waiting for other jobs to finish...
error: build failed

To Reproduce

Can't reproduce here.

System information:

See system info above (beginning of error message).

Additional context

Possibly related:

Failure because of stderr=open(os.devnull, 'wb') on OSX

Describe the bug

Opengen (v0.0.7) fails with the following error:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Python/2.7/site-packages/opengen/builder/optimizer_builder.py", line 337, in build
self.__prepare_target_project() # create folders; init cargo project
File "/Library/Python/2.7/site-packages/opengen/builder/optimizer_builder.py", line 129, in __prepare_target_project
stdout=open(os.devnull, 'wb'))
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 710, in _init_
errread, errwrite)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1335, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory

which is raised by this line:

p = subprocess.Popen(['cargo', 'init'],
                     cwd=target_dir,
                     stderr=open(os.devnull, 'wb'),
                     stdout=open(os.devnull, 'wb'))

If the above is replaced by

p = subprocess.Popen(['cargo', 'init'])

the problem is resolved. However, this doesn't allow the implementation of a "quiet mode", where the standard output and error streams are suppressed.

System information:

Pano's system: MacOSX x64, Darwin, Python 2.7. Fresh rust installation. Opengen 0.0.7.

Additional context

To be resolved after #39.

Move MATLAB codegen to Jinja2

Is your feature request related to a problem? Please describe.
No

Describe the solution you'd like
Lets move the matlab codegen to Jinja2 templates, the current template code is very hard to read and see how it comes together.
This will also help with the C/C++ lib generation and overview IMO.

Describe alternatives you've considered
Keep it as it is.

Additional context
Link: Jinja 2 documentation

Error definition conflicts makes MATLAB interface fail

Describe the bug
The definition of structure Error in optimization_engine and serde seems to create conflicts and makes the MATLAB interface fail. I had tested this a little before merging emil_fixes into master and it worked, so the culprit must be in a recent commit.

To Reproduce
Steps to reproduce the behavior:

Run this MATLAB snippet:

u = casadi.SX.sym('u', 5);        % decision variables
p = casadi.SX.sym('p', 2);         % parameters
phi = rosenbrock(u, p);            % cost function phi(u; p) (Rosenbrock)
constraints = OpEnConstraints.make_ball_at_origin(5.0);
opEnBuilder = OpEnOptimizerBuilder().with_problem(u, p, phi, constraints);
opEnOptimizer = opEnBuilder.build();

Error messages:

   Compiling icasadi v0.1.2 (/home/chung/NetBeansProjects/RUST/optimization-engine/build/autogenerated_optimizer/icasadi)
    Finished release [optimized] target(s) in 1.02s
[codegen] Build command: cargo build
   Compiling icasadi v0.1.2 (/home/chung/NetBeansProjects/RUST/optimization-engine/build/autogenerated_optimizer/icasadi)
   Compiling autogenerated_optimizer v0.1.0 (/home/chung/NetBeansProjects/RUST/optimization-engine/build/autogenerated_optimizer)
error[E0107]: wrong number of type arguments: expected 1, found 2
  --> src/main.rs:77:62
   |
77 |         let df = |u: &[f64], grad: &mut [f64]| -> Result<(), Error> {
   |                                                              ^^^^^ unexpected type argument

error[E0107]: wrong number of type arguments: expected 1, found 2
  --> src/main.rs:81:56
   |
81 |         let f = |u: &[f64], c: &mut f64| -> Result<(), Error> {
   |                                                        ^^^^^ unexpected type argument

error[E0308]: mismatched types
  --> src/main.rs:85:21
   |
85 |                 Err(Error::Cost)
   |                     ^^^^^^^^^^^ expected struct `serde_json::error::Error`, found enum `optimization_engine::Error`
   |
   = note: expected type `serde_json::error::Error`
              found type `optimization_engine::Error`

error[E0271]: type mismatch resolving `for<'r, 's> <[closure@src/main.rs:77:18: 80:10 p:_] as std::ops::FnOnce<(&'r [f64], &'s mut [f64])>>::Output == std::result::Result<(), optimization_engine::Error>`
  --> src/main.rs:90:23
   |
90 |         let problem = Problem::new(bounds, df, f);
   |                       ^^^^^^^^^^^^ expected struct `serde_json::error::Error`, found enum `optimization_engine::Error`
   |
   = note: expected type `std::result::Result<_, serde_json::error::Error>`
              found type `std::result::Result<_, optimization_engine::Error>`
   = note: required by `<optimization_engine::Problem<GradientType, ConstraintType, CostType>>::new`

error[E0271]: type mismatch resolving `for<'r, 's> <[closure@src/main.rs:81:17: 87:10 p:_] as std::ops::FnOnce<(&'r [f64], &'s mut f64)>>::Output == std::result::Result<(), optimization_engine::Error>`
  --> src/main.rs:90:23
   |
90 |         let problem = Problem::new(bounds, df, f);
   |                       ^^^^^^^^^^^^ expected struct `serde_json::error::Error`, found enum `optimization_engine::Error`
   |
   = note: expected type `std::result::Result<_, serde_json::error::Error>`
              found type `std::result::Result<_, optimization_engine::Error>`
   = note: required by `<optimization_engine::Problem<GradientType, ConstraintType, CostType>>::new`

error[E0271]: type mismatch resolving `for<'r, 's> <[closure@src/main.rs:77:18: 80:10 p:_] as std::ops::FnOnce<(&'r [f64], &'s mut [f64])>>::Output == std::result::Result<(), optimization_engine::Error>`
  --> src/main.rs:90:23
   |
90 |         let problem = Problem::new(bounds, df, f);
   |                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected struct `serde_json::error::Error`, found enum `optimization_engine::Error`
   |
   = note: expected type `std::result::Result<_, serde_json::error::Error>`
              found type `std::result::Result<_, optimization_engine::Error>`
   = note: required by `optimization_engine::Problem`

error[E0271]: type mismatch resolving `for<'r, 's> <[closure@src/main.rs:81:17: 87:10 p:_] as std::ops::FnOnce<(&'r [f64], &'s mut f64)>>::Output == std::result::Result<(), optimization_engine::Error>`
  --> src/main.rs:90:23
   |
90 |         let problem = Problem::new(bounds, df, f);
   |                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected struct `serde_json::error::Error`, found enum `optimization_engine::Error`
   |
   = note: expected type `std::result::Result<_, serde_json::error::Error>`
              found type `std::result::Result<_, optimization_engine::Error>`
   = note: required by `optimization_engine::Problem`

error[E0271]: type mismatch resolving `for<'r, 's> <[closure@src/main.rs:77:18: 80:10 p:_] as std::ops::FnOnce<(&'r [f64], &'s mut [f64])>>::Output == std::result::Result<(), optimization_engine::Error>`
  --> src/main.rs:91:25
   |
91 |         let mut panoc = PANOCOptimizer::new(problem, &mut cache).with_max_iter(MAX_ITERS);
   |                         ^^^^^^^^^^^^^^^^^^^ expected struct `serde_json::error::Error`, found enum `optimization_engine::Error`
   |
   = note: expected type `std::result::Result<_, serde_json::error::Error>`
              found type `std::result::Result<_, optimization_engine::Error>`
   = note: required by `<optimization_engine::panoc::PANOCOptimizer<'a, GradientType, ConstraintType, CostType>>::new`

error[E0271]: type mismatch resolving `for<'r, 's> <[closure@src/main.rs:81:17: 87:10 p:_] as std::ops::FnOnce<(&'r [f64], &'s mut f64)>>::Output == std::result::Result<(), optimization_engine::Error>`
  --> src/main.rs:91:25
   |
91 |         let mut panoc = PANOCOptimizer::new(problem, &mut cache).with_max_iter(MAX_ITERS);
   |                         ^^^^^^^^^^^^^^^^^^^ expected struct `serde_json::error::Error`, found enum `optimization_engine::Error`
   |
   = note: expected type `std::result::Result<_, serde_json::error::Error>`
              found type `std::result::Result<_, optimization_engine::Error>`
   = note: required by `<optimization_engine::panoc::PANOCOptimizer<'a, GradientType, ConstraintType, CostType>>::new`

error[E0271]: type mismatch resolving `for<'r, 's> <[closure@src/main.rs:77:18: 80:10 p:_] as std::ops::FnOnce<(&'r [f64], &'s mut [f64])>>::Output == std::result::Result<(), optimization_engine::Error>`
  --> src/main.rs:91:25
   |
91 |         let mut panoc = PANOCOptimizer::new(problem, &mut cache).with_max_iter(MAX_ITERS);
   |                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected struct `serde_json::error::Error`, found enum `optimization_engine::Error`
   |
   = note: expected type `std::result::Result<_, serde_json::error::Error>`
              found type `std::result::Result<_, optimization_engine::Error>`
   = note: required by `optimization_engine::panoc::PANOCOptimizer`

error[E0271]: type mismatch resolving `for<'r, 's> <[closure@src/main.rs:81:17: 87:10 p:_] as std::ops::FnOnce<(&'r [f64], &'s mut f64)>>::Output == std::result::Result<(), optimization_engine::Error>`
  --> src/main.rs:91:25
   |
91 |         let mut panoc = PANOCOptimizer::new(problem, &mut cache).with_max_iter(MAX_ITERS);
   |                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected struct `serde_json::error::Error`, found enum `optimization_engine::Error`
   |
   = note: expected type `std::result::Result<_, serde_json::error::Error>`
              found type `std::result::Result<_, optimization_engine::Error>`
   = note: required by `optimization_engine::panoc::PANOCOptimizer`

error[E0599]: no method named `with_max_iter` found for type `optimization_engine::panoc::PANOCOptimizer<'_, [closure@src/main.rs:77:18: 80:10 p:_], optimization_engine::constraints::Ball2, [closure@src/main.rs:81:17: 87:10 p:_]>` in the current scope
  --> src/main.rs:91:66
   |
91 |         let mut panoc = PANOCOptimizer::new(problem, &mut cache).with_max_iter(MAX_ITERS);
   |                                                                  ^^^^^^^^^^^^^

error: aborting due to 12 previous errors

Some errors occurred: E0107, E0271, E0308, E0599.
For more information about an error, try `rustc --explain E0107`.
error: Could not compile `autogenerated_optimizer`.

To learn more, run the command again with --verbose.

Expected behavior
It should work.

System information:

  • Ubuntu 14.04 (still)
  • rustc 1.34.2 (6c2484dc3 2019-05-13) [updated recently]

Additional context
None.

Cargo init fails - should be removed

Describe the bug

On some OSX systems, we have the following issue:

error: `cargo init` cannot be run on existing Cargo packages
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "opengen/builder/optimizer_builder.py", line 339, in build
self.__generate_main_project_code() # generate main part of code (at build/{name}/src/main.rs)
File "opengen/builder/optimizer_builder.py", line 241, in __generate_main_project_code
with open(target_scr_lib_rs_path, "w") as fh:
IOError: [Errno 2] No such file or directory: '/Users/panospatrinos 1/Documents/optimization-engine/open-codegen/python_test_build/tcp_enabled_optimizer/src/lib.rs

This is raised by __prepare_target_project because of the system call cargo init, which complains that the command "cannot be run on existing Cargo packages".

System information:

Panos's MacOSX system.

Additional context

The issue is resolved if the following lines are removed:

# Run `cargo init` in target folder
p = subprocess.Popen(['cargo', 'init'],
                     cwd=target_dir,
                     stderr=open(os.devnull, 'wb'),
                     stdout=open(os.devnull, 'wb'))
p.wait()

We should do that after we're done with clib_impl and we resolve #39.

Towards a Python code generator - development plan

๐Ÿšง The plan is to pause the development of the MATLAB interface and move the code generation functionality to Python. We will then be able to call Python from MATLAB. The idea is to keep all functionality in one place only. Besides, Python is free, while not everyone has access to MATLAB.

At the same time, we will implement the penalty method and later the augmented Lagrangian method too.

Next steps:

  • Have a stable Rust interface (no major changes in Cache, Engine etc expected); I think we're there
  • Write a minimal working example of how the generated code will look like in the simple case without the penalty method (we have this from the MATLAB code generator)
  • Prepare a minimal working example using the penalty method
  • Start implementing the existing MATLAB code generator in Python using Jinja2 (I guess we'll go for Python3, right?)
  • Support the penalty method in the code generator

We should be able to consume the auto-generated Rust optimizer using its C bindings (currently under development).

This will allow us to use it from both Python and MATLAB (by creating a MEX interface).

Let's discuss this here below...

PANOCOptimizer: with_max_duration breaks pattern

Is your feature request related to a problem? Please describe.
No. It's about this function, which, as @korken89 pointed out, breaks the patters of setter methods:

pub fn with_max_duration(&mut self, max_duation: time::Duration) -> &Self {
    self.max_duration = Some(max_duation);
    self
}

Describe the solution you'd like
It should rather return Self instead of &Self. We can also replace the return type of similar methods from PANOCOptimizer<'a, GradientType, ConstraintType, CostType> to Self for brevity.

Describe alternatives you've considered
None

Additional context
We need to make sure tests pass and make a few changes in the templates. The function will be used like:

let mut panoc = PANOCOptimizer::new(problem, &mut panoc_cache).with_max_iter(max_iters);
// more code goes here
let mut panoc = panoc.with_max_duration(max_duration);

Let's do this after #37.

Build fails for simultaneous TCP/IP server and Cbindgen

Describe the bug

The auto-generated code compiles when either enable_c_bindings_generation() or enable_c_bindings_generation() is issued. When both are active, rust gives some weird errors (it doesn't find crate pretty_env_logger in main.rs).

To Reproduce

Minimal example:

u = cs.SX.sym("u", 5)
p = cs.SX.sym("p", 2)
phi = og.functions.rosenbrock(u, p)
problem = og.builder.Problem(u, p, phi)
build_config = og.config.BuildConfiguration() \
    .with_build_directory("python_test_build") \
    .with_build_mode("debug").with_rebuild(True)
meta = og.config.OptimizerMeta() \
    .with_optimizer_name("tcp_enabled_optimizer")
builder = og.builder.OpEnOptimizerBuilder(problem, meta,
                                          build_config) \
    .with_verbosity_level(1)
builder.enable_tcp_interface()
builder.enable_c_bindings_generation()
builder.build()

If you remove either

  • builder.enable_c_bindings_generation() or
  • builder.enable_tcp_interface()

the code works fine. Otherwise, it gives the following error:

error[E0463]: can't find crate for `pretty_env_logger`
  --> src/main.rs:15:1
   |
15 | extern crate pretty_env_logger;
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't find crate

error: aborting due to previous error

For more information about this error, try `rustc --explain E0463`.
error: Could not compile `tcp_enabled_optimizer`.
warning: build failed, waiting for other jobs to finish...
error: build failed

Expected behavior

A clear and concise description of what you expected to happen.

System information:

Tested on Ubuntu 14.04 with Python 3.6.

Additional context

The error is not related to pretty_env_logger. If you remove it manually, you still get the these errors if you try a cargo build in the auto-generated project directory.

Perhaps a possible solution would be to move main.rs into a different project that will have the auto-generated project as a dependency so as to separate the library from its TCP interface.

Providing the wrong number of parameters to the Python TCP interface gives cryptic error

Describe the bug

Providing the wrong number of parameters to the Python TCP interface gives cryptic error as:

Traceback (most recent call last):
  File "mav_controller.py", line 105, in <module>
    solution = mng.call([1.0, 0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0]) # call the solver over TCP
  File "/usr/lib/python3.7/site-packages/opengen/tcp/optimizer_tcp_manager.py", line 139, in call
    return json.loads(data)
  File "/usr/lib/python3.7/json/__init__.py", line 348, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python3.7/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python3.7/json/decoder.py", line 353, in raw_decode
    obj, end = self.scan_once(s, idx)
json.decoder.JSONDecodeError: Expecting ',' delimiter: line 3 column 2 (char 32)

^CException ignored in: <module 'threading' from '/usr/lib/python3.7/threading.py'>
Traceback (most recent call last):
  File "/usr/lib/python3.7/threading.py", line 1281, in _shutdown
    t.join()
  File "/usr/lib/python3.7/threading.py", line 1032, in join
    self._wait_for_tstate_lock()
  File "/usr/lib/python3.7/threading.py", line 1048, in _wait_for_tstate_lock
    elif lock.acquire(block, timeout):

To Reproduce

Run the following script:

import casadi.casadi as cs
import opengen as og
import numpy as np
import math

N=10
dt=1/20
nu=3
nx=8

u = cs.SX.sym("u", N*nu) # decision variable (nu = 3 T theta_x theta_y)
p = cs.SX.sym("p", nx+nx) # states + state_ref (np = 8 p p_dot theta_x theta_y)
x= p[0:nx]
x_ref = p[nx:]

## Constants
g=9.81 # %gravity
mass = 1.1# % of platform, in kilograms
max_thrust = 30# % of platform, in Newtons

a_x=0.1# % Mass normalized drag coefficients
a_y=0.1#
a_z=0.2#

tao_roll=0.5 #; % Time constants in seconds
tao_pitch=0.5 #;

k_roll=1 ##; % Angle gains
k_pitch=1 #;
x0=x

for i in range(N) :
    k = (i ) * nu
    u0=u[k:k+nu]
    p_0=x0[0:3]#; % position vector
    v=x0[3:6]#; % velocity vector
    roll=x0[6]#; % roll angle
    pitch=x0[7]#; % pitch angle
    T = u0[1]#; % mass normalized thrust
    roll_g = u[2]#; %desired angles
    pitch_g = u[3]#;
    #R_x = np.matrix([[1, 0, 0],[ 0, np.cos(roll), -np.sin(roll)],[0, np.sin(roll), np.cos(roll)]])#; %Rotation around x (roll)
    #R_y = np.matrix([[np.cos(pitch), 0, np.sin(pitch)],[ 0, 1, 0],[-np.sin(pitch), 0, np.cos(pitch)]])#; %Rotation around y (pitch)
    #R = R_y*R_x#; % Rotation matrix without rotation around z since coordinates are fixed to the frame
    x_0 = p_0[0]
    y_0 = p_0[1]
    z_0 = p_0[2]
    #v_dot = R*np.matrix([[0],[ 0],[T]]) + np.matrix([[0],[ 0],[-g]]) - np.matrix([[a_x, 0, 0],[ 0,a_y, 0],[ 0, 0, a_z]])*v
    ddx= (np.sin(pitch)*np.cos(roll))*T
    ddy= (-np.sin(roll))*T
    ddz=-g+(np.cos(pitch)*np.cos(roll))*T

    roll_dot = (1/tao_roll)*(k_roll*roll_g - roll)

    pitch_dot = (1/tao_pitch)*(k_pitch*pitch_g - pitch)

    x=v[0]*dt+x_0
    y=v[1]*dt+y_0
    z=v[2]*dt+z_0
    v_x=ddx*dt+v[0]
    v_y=ddy*dt+v[1]
    v_z=ddz*dt+v[2]
    roll=roll_dot*dt+roll
    pitch=pitch_dot*dt+pitch
    x0=[x,y,z,v_x,v_y,v_z,roll,pitch]
    cost= np.power((x0[0]-x_ref[0]),2)+np.power((x0[1]-x_ref[1]),2)+np.power((x0[2]-x_ref[2]),2)+np.power((x0[3]-x_ref[3]),2)+np.power((x0[4]-x_ref[4]),2)+np.power((x0[5]-x_ref[5]),2)


c = cs.vertcat(cs.fmax(0.0, -u[0] ),
               cs.fmax(math.pi/2,  u[1] ),
               cs.fmax(math.pi/2, -u[1] ),
               cs.fmax(math.pi/2,  u[2] ),
               cs.fmax(math.pi/2, -u[2] ),
                 )

problem = og.builder.Problem(u, p, cost) \
          .with_penalty_constraints(c)  
meta = og.config.OptimizerMeta() \
    .with_version("0.0.0") \
    .with_authors(["P. Sopasakis", "E. Fresk"]) \
    .with_licence("CC4.0-By") \
    .with_optimizer_name("the_optimizer")

build_config = og.config.BuildConfiguration() \
    .with_build_directory("python_build") \
    .with_build_mode("debug")

solver_config = og.config.SolverConfiguration() \
    .with_lfbgs_memory(15) \
    .with_tolerance(1e-5) \
    .with_max_inner_iterations(155)

builder = og.builder.OpEnOptimizerBuilder(problem,
    metadata=meta,
    build_configuration=build_config,
    solver_configuration=solver_config)
builder.enable_tcp_interface()
builder.build()

mng = og.tcp.OptimizerTcpManager('python_build/the_optimizer')
mng.start()

pong = mng.ping() # check if the server is alive
print(pong)
solution = mng.call([1.0, 0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0]) # call the solver over TCP
print(solution)

mng.kill()

Expected behavior

A proper error message saying that the wrong number of parameters were supplied.

MATLAB OpEN ncp problem

The Matlab interface gave following error:

Undefined function or variable 'ncp'.

Error in casadi_generate_c_code (line 68)
fprintf(fid, '#define CASADI_NUM_CONSTAINTS_TYPE_PENALTY %d\n', ncp);

Error in OpEnOptimizerBuilder/build>casadi_codegen (line 98)
[cost, grad_cost] = casadi_generate_c_code(u, p, phi,cstr_pen,build_directory);

Error in OpEnOptimizerBuilder/build (line 54)
casadi_codegen(opEnBuilder.sx_u, opEnBuilder.sx_p, opEnBuilder.cost, ...

Error in optimization_build (line 57)
optimizer = builder.build();

Error in run (line 47)
optimization_build

If no build directory is supplied the python interface crashes

Describe the bug

If no build directory is supplied the python interface crashes

To Reproduce

Steps to reproduce the behavior:

  1. Make a solver and do not include .with_build_directory("...")

Expected behavior

That is would build the solver in the current directory.

Multiple solvers in one final binary

Is your feature request related to a problem? Please describe.
Not really, but it is currently very difficult to use multiple icasadi instances of generated solvers as the linking from casadi C code is not using unique names (it currently uses the name given by the MATLAB/Python casadi interface.
This causes linker errors as symbols are multiply defined.

When manually creating icasadi functions this is not a problem, as the user can take any name.

Describe the solution you'd like
The auto-generated C code needs to get unique names.

Describe alternatives you've considered

  1. Leave as is, and then it is difficult to define multiple solvers in the same binary.
  2. Extent code generation to add a random identifier to user names of casadi functions and auto-generate the icasadi file that will interface to the generated C code.

Additional context
None.

Solution out of bounds

I defined the bounds on decision variable 0 to 30, however, in some cases, the solver returns a very small negative value.

on Ubuntu 16.04
with rustc 1.35.0

I am using binder of generated code in ROS, for regenerating the code, you need rosbag of the data.

Bug in Solver

I am getting the following error:

thread '<unnamed>' panicked at 'index out of bounds: t
he len is 57 but the index is 7453010376530526208', /
home/sina/.cargo/registry/src/github.com-1ecc6299db9ec823/optimization_engine-0.5.0/src/continuation/homotopy_optimizer.rs:164:13
note: Run with RUST_BACKTRACE=1 environment variable to display a backtrace.
fatal runtime error: failed to initiate panic, error 5
Aborted (core dumped)

on Ubuntu 16.04
with rustc 1.35.0

I am using binder of generated code in ROS, for regenerating the code, you need rosbag of the data.

Error shadowing in homotopy optimizer

Describe the bug

Line 319 in homotopy_optimizer can lead to error shadowing and failures:

let status = inner_panoc.solve(u).unwrap();

To Reproduce

Build a homotopy-type optimizer for the Rosenbrock function and pass to it a vector of parameters with negative entries. The computations will of course fail, but the error is shadowed,
and, because of unwrap, the server panics.

Expected behavior
The error is resolved if we replace line 319 with:

let status = inner_panoc.solve(u)?;

System information:

Not relevant

Additional context

Let us implement this change after we merge #37.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.