Coder Social home page Coder Social logo

ml-casadi's Introduction

ML-CasADi CI

ML-CasADi

This is the underlying framework enabling Neural-MPC in our paper

Neural-MPC: Deep Learning Model Predictive Control for Quadrotors and Agile Robotic Platforms

Arxiv Link

This framework enables PyTorch Models to be used as CasADi functions and subsequently in Acados optimal control problems.

Examples

Arbitrary PyTorch Model as first- or second order approximation

import ml_casadi.torch as mc
import casadi as cs

model = mc.TorchMLCasadiModuleWrapper(
    torch_module,
    input_size=size_in,
    output_size=size_out)
    
casadi_sym_inp = cs.MX.sym('inp', size_in)
casadi_sym_out = model.approx(casadi_sym_inp, order=1)  # order=2

casadi_func = cs.Function('model_approx_wrapper',
                          [casadi_sym_inp, model.sym_approx_params(order=1)],
                          [casadi_sym_out])

casadi_param = model.approx_params(input, order=1)  # order=2
casadi_out = casadi_func(input, casadi_param)

Using Acados, the approximation parameters can be passed to the optimal control problem via acados_ocp_solver.set(n, 'p', casadi_param).

Specific PyTorch Model without approximation

import ml_casadi.torch as mc
import casadi as cs

model = mc.MultiLayerPerceptron(
    input_size=size_in,
    hidden_size=hidden_size,
    output_size=size_out,
    n_hidden=n_hidden,
    activation='relu')
    
casadi_sym_inp = cs.MX.sym('inp', size_in)
casadi_sym_out = model(casadi_sym_inp)

casadi_func = cs.Function('model_approx_wrapper',
                          [casadi_sym_inp],
                          [casadi_sym_out])

casadi_out = casadi_func(input, casadi_param)

Citing

If you use our work please cite our paper

@article{salzmann2022neural,
  title={Neural-MPC: Deep Learning Model Predictive Control for Quadrotors and Agile Robotic Platforms},
  author={Salzmann, Tim and Kaufmann, Elia and Pavone, Marco and Scaramuzza, Davide and Ryll, Markus},
  journal={arXiv preprint arXiv:2203.07747},
  year={2022}
}

ml-casadi's People

Contributors

tim-salzmann avatar

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.