DiffOpt.jl is a package for differentiating convex optimization programs with respect to the program parameters. DiffOpt currently supports linear, quadratic, and conic programs.
DiffOpt.jl is licensed under the MIT License.
Install DiffOpt using
import Pkg Pkg.add("DiffOpt")
The documentation for DiffOpt.jl includes a detailed description of the theory behind the package, along with examples, tutorials, and an API reference.
Use DiffOpt with JuMP by following this brief example:
using JuMP, DiffOpt, HiGHS # Create a model using the wrapper model = Model(() -> DiffOpt.diff_optimizer(HiGHS.Optimizer)) # Define your model and solve it @variable(model, x) @constraint(model, cons, x >= 3) @objective(model, Min, 2x) optimize!(model) # Choose the problem parameters to differentiate with respect to, and set their # perturbations. MOI.set(model, DiffOpt.ReverseVariablePrimal(), x, 1.0) # Differentiate the model DiffOpt.reverse_differentiate!(model) # fetch the gradients grad_exp = MOI.get(model, DiffOpt.ReverseConstraintFunction(), cons) # -3 x - 1 constant(grad_exp) # -1 coefficient(grad_exp, x) # -3
DiffOpt began as a NumFOCUS sponsored Google Summer of Code (2020) project