DifferentiableTrajectoryOptimization

Differentiable trajectory optimization in Julia.

https://github.com/lassepe/differentiabletrajectoryoptimization.jl

Science Score: 67.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
    Found 1 DOI reference(s) in README
  • Academic publication links
    Links to: arxiv.org, springer.com
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (12.4%) to scientific vocabulary

Keywords

differentiable julia trajectory-optimization
Last synced: 6 months ago · JSON representation ·

Repository

Differentiable trajectory optimization in Julia.

Basic Info
  • Host: GitHub
  • Owner: lassepe
  • License: mit
  • Language: Julia
  • Default Branch: main
  • Homepage:
  • Size: 113 KB
Statistics
  • Stars: 64
  • Watchers: 6
  • Forks: 3
  • Open Issues: 5
  • Releases: 9
Topics
differentiable julia trajectory-optimization
Created over 3 years ago · Last pushed 6 months ago
Metadata Files
Readme License Citation

README.md

DifferentiableTrajectoryOptimization.jl (Dito)

CI codecov License

DifferentiableTrajectoryOptimization.jl (Dito for short) is a package for Differentiable Trajetory Optimization in Julia. It supports both forward and reverse mode differentiation via ForwardDiff.jl and ChainRulesCore.jl and therefore integrates seamlessly with machine learning frameworks such as Flux.jl.


A substantial part of machine learning (ML) algorithms relies upon the ability to propagate gradient signals through the entire learning pipeline. Traditionally, such models have been mostly limited to artificial neural networks and "simple" analytic functions. Recent work has focused on extending the class of admissible models for gradient-based learning by making all sorts of procedures differentiable. These efforts range from differentiable physics engines over differentiable rendering to differentiable optimization.

Dito focuses on a special case of the latter category, differentiable trajectory optimization. As such, Dito algorithmically provides a (local) answer to the question:

"How does the optimal solution of an inequality constrained trajectory optimization problem change if the problem changes?".

This implementation was originally developed as part of our research on Learning Mixed Strategies in Trajectory Games: bibtex @inproceedings{peters2022rss, title = {Learning Mixed Strategies in Trajectory Games}, author = {Peters, Lasse and Fridovich-Keil, David and Ferranti, Laura and Stachniss, Cyrill and Alonso-Mora, Javier and Laine, Forrest}, booktitle = {Proc.~of Robotics: Science and Systems (RSS)}, year = {2022}, url = {https://arxiv.org/abs/2205.00291} } There, Dito allowed us to efficiently train a neural network pipeline that rapidly generate feasible equilibrium trajectories in multi-player non-cooperative dynamic games. Since this component has proven to be very useful in that context, we have since decided to factor it out into a stand-alone package.

Installation

To install Dito, simply add it via Julia's package manager from the REPL:

```julia

hit ] to enter "pkg"-mode of the REPL

pkg> add DifferentiableTrajectoryOptimization ```

Usage

Below we construct a parametric optimization problem for a 2D integrator with 2 states, 2 inputs over a horizon of 10 stages with box constraints on states and inputs.

Please consult the documentation for each of the types below for further information. For example, just type ?ParametricTrajectoryOptimizationProblem to learn more about the problem setup. You can also consult the tests as an additional source of implicit documentation.

1. Problem Setup

The entry-point for getting started with this package is to set up you problem of choice as an ParametricTrajectoryOptimizationProblem.

```julia using DifferentiableTrajectoryOptimization

horizon = 10 statedim = controldim = parameterdim = 2 cost = (xs, us, params) -> sum(sum((x - params).^2) + sum(u.^2) for (x, u) in zip(xs, us)) dynamics = (x, u, t) -> x + u inequalityconstraints = let stateconstraints = state -> [state .+ 0.1; -state .+ 0.1] controlconstraints = control -> control .+ 0.1; -control .+ 0.1 -> [ mapreduce(stateconstraints, vcat, xs) mapreduce(controlconstraints, vcat, us) ] end

problem = ParametricTrajectoryOptimizationProblem( cost, dynamics, inequalityconstraints, statedim, controldim, parameterdim, horizon )

```

2. Optimizer Setup

Given an instance of the ParametricTrajectoryOptimizationProblem, you can construct an Optimizer for the problem.

julia backend = QPSolver() optimizer = Optimizer(problem, backend)

Currently, Dito supports the following optimization backends:

  • MCPSolver: Casts trajectory optimization problem as a mixed complementarity problem (MCP) and solves it via PATH.
    • This is the best option for nonlinear, non-convex problems. Even for QPs this solver is often as fast as the specialized QP solver.
    • The PATH solver is not open source but provides a free license. Without setting a license key, this backend only works for small problems. Please consult the documentation of PATHSolver.jl to learn about loading the license key.
  • QPSolver: Treats the problem as convex QP by linearizing the constraints and quadraticizing the cost a priori.
    • If the true problem is not a QP, this solution will not be exact.
  • NLPSolver: Solves the trajectory optimization problem as NLP using Ipopt.
    • This solver is mostely here for historic reasons to provide a fully open-source backend for NLPs. However, for many problems the MCPSolver backend using PATH is much faster.

3. Solving the Problem

Given an optimizer, we can solve a problem instance for a given initial state x0 and parameter values params.

```julia x0 = zeros(state_dim) params = randn(2)

the solution has fields for

xs: the state sequence

us: the control sequence

λs: the constriant multipliers

info: additional "low-level" solver info

(; xs, us, λs, info) = solution = optimizer(x0, params) ```

4. Computing Gradients

Since we provide gradient rules for the optimizer(x0, params) call, you can directly differentiate through it using your favorite autodiff framework. Here is a toy example of how this could look like:

```julia using Zygote: Zygote

an objective function that maps from parameters to a scalar performance index

function objective(params) (; xs, λs) = optimizer(x0, params) sum(sum(x .^ 2) for x in xs) + sum(sum(λ .^ 2) for λ in λs) end

the gradient of objective evalauted at the randomly sampled params from step 3 above

Zygote.gradient(objective, params) ```

Background

Dito achieves differentiable trajectory optimization by augmenting existing optimization routines with custom derivative rules that apply the implicit function theorem (IFT) to the resulting KKT-system. Through this formulation, Dito avoids differentiation of the entire (potentially iterative) algorithm, leading to substantially accelerated derivative computation and facilitating differentiation of optimization backends that are not written in pure Julia.

The following body of work provides more information about this IFT-based differentiation approach:

Citation (CITATION.cff)

# This CITATION.cff file was generated with cffinit.
# Visit https://bit.ly/cffinit to generate yours today!

cff-version: 1.2.0
title: Dito.jl
message: >-
  If you use this software, please cite it using the
  metadata from this file.
type: software
authors:
  - given-names: Lasse
    family-names: Peters
    email: l.peters@tudelft.nl
    affiliation: Delft University of Technology
    orcid: 'https://orcid.org/0000-0001-9008-7127'
  - given-names: Forrest
    family-names: Laine
    email: forrest.laine@vanderbilt.edu
    affiliation: Vanderbilt University
    orcid: 'https://orcid.org/0000-0003-3982-3920'
  - given-names: David
    family-names: Fridovich-Keil
    email: dfk@utexas.edu
    affiliation: University of Texas at Austin
    orcid: 'https://orcid.org/0000-0002-5866-6441'

GitHub Events

Total
  • Create event: 8
  • Commit comment event: 2
  • Release event: 1
  • Issues event: 1
  • Watch event: 6
  • Delete event: 8
  • Issue comment event: 4
  • Push event: 21
  • Pull request review event: 5
  • Pull request event: 17
Last Year
  • Create event: 8
  • Commit comment event: 2
  • Release event: 1
  • Issues event: 1
  • Watch event: 6
  • Delete event: 8
  • Issue comment event: 4
  • Push event: 21
  • Pull request review event: 5
  • Pull request event: 17

Issues and Pull Requests

Last synced: 6 months ago

All Time
  • Total issues: 6
  • Total pull requests: 22
  • Average time to close issues: about 7 hours
  • Average time to close pull requests: 7 days
  • Total issue authors: 2
  • Total pull request authors: 4
  • Average comments per issue: 1.67
  • Average comments per pull request: 0.64
  • Merged pull requests: 20
  • Bot issues: 0
  • Bot pull requests: 7
Past Year
  • Issues: 1
  • Pull requests: 9
  • Average time to close issues: N/A
  • Average time to close pull requests: 13 days
  • Issue authors: 1
  • Pull request authors: 3
  • Average comments per issue: 0.0
  • Average comments per pull request: 0.33
  • Merged pull requests: 8
  • Bot issues: 0
  • Bot pull requests: 6
Top Authors
Issue Authors
  • lassepe (5)
  • github-actions[bot] (1)
  • JuliaTagBot (1)
Pull Request Authors
  • lassepe (17)
  • dependabot[bot] (9)
  • github-actions[bot] (3)
  • xinjie-liu (2)
Top Labels
Issue Labels
enhancement (1)
Pull Request Labels
dependencies (9) github_actions (1)

Packages

  • Total packages: 1
  • Total downloads:
    • julia 2 total
  • Total dependent packages: 1
  • Total dependent repositories: 0
  • Total versions: 9
juliahub.com: DifferentiableTrajectoryOptimization

Differentiable trajectory optimization in Julia.

  • Versions: 9
  • Dependent Packages: 1
  • Dependent Repositories: 0
  • Downloads: 2 Total
Rankings
Dependent repos count: 9.9%
Stargazers count: 16.0%
Average: 20.5%
Dependent packages count: 23.0%
Forks count: 33.3%
Last synced: 6 months ago