-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
99 additions
and
304 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
name: Documentation | ||
|
||
on: | ||
push: | ||
branches: | ||
- master # update to match your development branch (master, main, dev, trunk, ...) | ||
tags: '*' | ||
pull_request: | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: julia-actions/setup-julia@latest | ||
with: | ||
version: '1.9' | ||
- name: Install dependencies | ||
run: julia --project=docs/ docs/install.jl | ||
- name: Build and deploy | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # If authenticating with GitHub Actions token | ||
DOCUMENTER_KEY: ${{ secrets.DOCUMENTER_KEY }} # If authenticating with SSH deploy key | ||
run: julia --project=docs/ docs/make.jl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# MadDiffCore | ||
# SIMDiff | ||
```@autodocs | ||
Modules = [MadDiffCore] | ||
Modules = [SIMDiff] | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,41 @@ | ||
# # Getting Started | ||
# SIMDiff provides a built-in API for creating nonlinear prgogramming models and allows solving the created models using NLP solvers (in particular, those that are interfaced with `NLPModels`, such as [NLPModelsIpopt](https://github.com/JuliaSmoothOptimizers/NLPModelsIpopt.jl). We now use `SIMDiff`'s bulit-in API to model the following nonlinear program: | ||
# SIMDiff can create nonlinear prgogramming models and allows solving the created models using NLP solvers (in particular, those that are interfaced with `NLPModels`, such as [NLPModelsIpopt](https://github.com/JuliaSmoothOptimizers/NLPModelsIpopt.jl). We now use `SIMDiff` to model the following nonlinear program: | ||
# ```math | ||
# \begin{aligned} | ||
# \min_{\{x_i\}_{i=0}^N} &\sum_{i=2}^N 100(x_{i-1}^2-x_i)^2+(x_{i-1}-1)^2\\ | ||
# \text{s.t.} & 3x_{i+1}^3+2x_{i+2}-5+\sin(x_{i+1}-x_{i+2})\sin(x_{i+1}+x_{i+2})+4x_{i+1}-x_i e^{x_i-x_{i+1}}-3 = 0 | ||
# \end{aligned} | ||
# ``` | ||
# We model the problem with: | ||
using SIMDiff | ||
|
||
# We set | ||
N = 10000 | ||
|
||
# First, we create a `SIMDiffModel`. | ||
m = SIMDiffModel() | ||
# First, we create a `SIMDiff.Core`. | ||
c = SIMDiff.Core() | ||
|
||
# The variables can be created as follows: | ||
x = [variable(m; start = mod(i,2)==1 ? -1.2 : 1.) for i=1:N]; | ||
|
||
x = SIMDiff.variable( | ||
c, N; | ||
start = (mod(i,2)==1 ? -1.2 : 1. for i=1:N) | ||
) | ||
|
||
# The objective can be set as follows: | ||
objective(m, sum(100(x[i-1]^2-x[i])^2+(x[i-1]-1)^2 for i=2:N)); | ||
SIMDiff.objective(c, 100*(x[i-1]^2-x[i])^2+(x[i-1]-1)^2 for i in 2:N) | ||
|
||
# The constraints can be set as follows: | ||
for i=1:N-2 | ||
constraint(m, 3x[i+1]^3+2*x[i+2]-5+sin(x[i+1]-x[i+2])sin(x[i+1]+x[i+2])+4x[i+1]-x[i]exp(x[i]-x[i+1])-3 == 0); | ||
end | ||
SIMDiff.constraint( | ||
c, | ||
3x[i+1]^3+2*x[i+2]-5+sin(x[i+1]-x[i+2])sin(x[i+1]+x[i+2])+4x[i+1]-x[i]exp(x[i]-x[i+1])-3 | ||
for i in 1:N-2) | ||
|
||
# The important last step is instantiating the model. This step must be taken before calling optimizers. | ||
instantiate!(m) | ||
# Finally, we create an NLPModel. | ||
m = SIMDiff.Model(c) | ||
|
||
# To solve the problem with `Ipopt`, | ||
using NLPModelsIpopt | ||
sol = ipopt(m); | ||
|
||
# The solution `sol` contains the field `sol.solution` holding the optimized parameters. | ||
|
||
# ### SIMDiff as an AD backend of JuMP | ||
# SIMDiff can be used as an automatic differentiation backend of JuMP. The problem above can be modeled in `JuMP` and solved with `Ipopt` along with `SIMDiff` | ||
|
||
using JuMP, Ipopt | ||
|
||
m = JuMP.Model(Ipopt.Optimizer) | ||
|
||
@variable(m, x[i=1:N], start=mod(i,2)==1 ? -1.2 : 1.) | ||
@NLobjective(m, Min, sum(100(x[i-1]^2-x[i])^2+(x[i-1]-1)^2 for i=2:N)) | ||
@NLconstraint(m, [i=1:N-2], 3x[i+1]^3+2*x[i+2]-5+sin(x[i+1]-x[i+2])sin(x[i+1]+x[i+2])+4x[i+1]-x[i]exp(x[i]-x[i+1])-3 == 0) | ||
|
||
optimize!(m; differentiation_backend = SIMDiffAD()) |
Large diffs are not rendered by default.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.