GithubHelp home page GithubHelp logo

grishabh147 / diffopt.jl Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jump-dev/diffopt.jl

0.0 0.0 0.0 8.65 MB

Differentiating convex optimization programs w.r.t. program parameters

Home Page: https://jump.dev/DiffOpt.jl/stable

License: MIT License

Julia 100.00%

diffopt.jl's Introduction

DiffOpt.jl

Stable Dev Build Status Coverage

DiffOpt is a package for differentiating convex optimization programs with respect to the program parameters. It currently supports linear, quadratic and conic programs. Refer to the documentation for examples. Powered by JuMP.jl, DiffOpt allows creating a differentiable optimization model from many existing optimizers.

Installation

DiffOpt can be installed via the Julia package manager:

julia> ]
(v1.7) pkg> add DiffOpt

Example

  1. Create a model using the wrapper.
using JuMP
import DiffOpt
import HiGHS

model = JuMP.Model(() -> DiffOpt.diff_optimizer(HiGHS.Optimizer))
  1. Define your model and solve it a single line.
@variable(model, x)
@constraint(
  model,
  cons,
  x >= 3,
)
@objective(
  model,
  Min,
  2x,
)

optimize!(model) # solve
  1. Choose the problem parameters to differentiate with and set their perturbations.
MOI.set.(  # set pertubations / gradient inputs
    model, 
    DiffOpt.ReverseVariablePrimal(),
    x,
    1.0,
)
  1. Differentiate the model (primal, dual variables specifically) and fetch the gradients
DiffOpt.reverse_differentiate!(model) # differentiate

grad_exp = MOI.get(   # -3 x - 1
    model,
    DiffOpt.ReverseConstraintFunction(),
    cons
)
JuMP.constant(grad_exp)  # -1
JuMP.coefficient(grad_exp, x)  # -3

Note

diffopt.jl's People

Contributors

matbesancon avatar akshay326 avatar joaquimg avatar blegat avatar jinraekim avatar github-actions[bot] avatar vfegger avatar alexrobson avatar guilhermebodin avatar oxinabox avatar niklasschmitz avatar traversaro avatar willtebbutt 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.