Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enable strict doctesting #622

Merged
merged 4 commits into from
Jun 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ OptimizationFlux = "253f991c-a7b2-45f8-8852-8b9a9df78a86"
OptimizationOptimJL = "36348300-93cb-4f02-beb5-3c3902f8871e"
OptimizationPolyalgorithms = "500b13db-7e66-49ce-bda4-eed966be6282"
QuadGK = "1fd47b50-473d-5c70-9696-f719f8f3bcdc"
ReverseDiff = "37e2e3b7-166d-5795-8a7a-e32c996b4267"
Tracker = "9f7883ad-71c0-57eb-9f7f-b5c9e6d3789c"
Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f"

Expand Down
13 changes: 13 additions & 0 deletions docs/make.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
using Documenter, DiffEqSensitivity

# Make sure that plots don't throw a bunch of warnings / errors!
ENV["GKSwstype"] = "100"
using Plots

include("pages.jl")

makedocs(
Expand All @@ -9,6 +13,15 @@ makedocs(
doctest = false,
modules = [DiffEqSensitivity],

strict = [
:doctest,
:linkcheck,
:parse_error,
:example_block,
# Other available options are
# :autodocs_block, :cross_references, :docs_block, :eval_block, :example_block, :footnote, :meta_block, :missing_docs, :setup_block
],

format = Documenter.HTML(#analytics = "",
assets = ["assets/favicon.ico"],
canonical="https://sensitivity.sciml.ai/stable/"),
Expand Down
7 changes: 4 additions & 3 deletions docs/src/ad_examples/adjoint_continuous_functional.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,10 @@ end

To get the adjoint sensitivities, we call:

```julia
res = adjoint_sensitivities(sol,Vern9(),g,nothing,dg,abstol=1e-8,
reltol=1e-8,iabstol=1e-8,ireltol=1e-8)
```@example continuousadjoint
prob = ODEProblem(f,[1.0;1.0],(0.0,10.0),p)
sol = solve(prob,DP8())
res = adjoint_sensitivities(sol,Vern9(),g,nothing,dg,abstol=1e-8,reltol=1e-8)
```

Notice that we can check this against autodifferentiation and numerical
Expand Down
2 changes: 1 addition & 1 deletion docs/src/ad_examples/direct_sensitivity.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ and computation time. We can check this almost exactly matches the
autodifferentiation and numerical differentiation results:

```@example directsense
using ForwardDiff,Calculus,Tracker
using ForwardDiff,Calculus,ReverseDiff,Tracker
function G(p)
tmp_prob = remake(prob,u0=convert.(eltype(p),prob.u0),p=p)
sol = solve(tmp_prob,Vern9(),abstol=1e-14,reltol=1e-14,saveat=ts,
Expand Down
2 changes: 1 addition & 1 deletion docs/src/neural_ode/GPUs.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,6 @@ optprob = Optimization.OptimizationProblem(optf, Lux.ComponentArray(p))

result_neuralode = Optimization.solve(optfunc,
ADAM(0.05),
cb = callback,
callback = callback,
maxiters = 300)
```
4 changes: 2 additions & 2 deletions docs/src/neural_ode/neural_ode_flux.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,14 @@ optprob = GalacticOptim.OptimizationProblem(optfunc, prob_neuralode.p)

result_neuralode = GalacticOptim.solve(optprob,
ADAM(0.05),
cb = callback,
callback = callback,
maxiters = 300)

optprob2 = remake(optprob,u0 = result_neuralode.u)

result_neuralode2 = GalacticOptim.solve(optprob2,
LBFGS(),
cb = callback,
callback = callback,
allow_f_increases = false)
```

Expand Down
8 changes: 4 additions & 4 deletions docs/src/neural_ode/neural_ode_galacticoptim.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,14 @@ optprob = GalacticOptim.OptimizationProblem(optfunc, prob_neuralode.p)

result_neuralode = GalacticOptim.solve(optprob,
ADAM(0.05),
cb = callback,
callback = callback,
maxiters = 300)

optprob2 = remake(optprob,u0 = result_neuralode.u)

result_neuralode2 = GalacticOptim.solve(optprob2,
LBFGS(),
cb = callback,
callback = callback,
allow_f_increases = false)
```

Expand Down Expand Up @@ -181,7 +181,7 @@ optprob = GalacticOptim.OptimizationProblem(optfunc, prob_neuralode.p)

result_neuralode = GalacticOptim.solve(optprob,
ADAM(0.05),
cb = callback,
callback = callback,
maxiters = 300)
# output
* Status: success
Expand All @@ -205,7 +205,7 @@ optprob2 = remake(optprob,u0 = result_neuralode.u)

result_neuralode2 = GalacticOptim.solve(optprob2,
LBFGS(),
cb = callback,
callback = callback,
allow_f_increases = false)
# output
* Status: success
Expand Down
21 changes: 5 additions & 16 deletions docs/src/ode_fitting/optimization_ode.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
If you want to just get things running, try the following! Explanation will
follow.

```@example optode
```@example optode_cp
using DifferentialEquations, Optimization, OptimizationPolyalgorithms, OptimizationOptimJL, Plots

function lotka_volterra!(du, u, p, t)
Expand Down Expand Up @@ -54,9 +54,8 @@ optf = Optimization.OptimizationFunction((x,p)->loss(x), adtype)
optprob = Optimization.OptimizationProblem(optf, p)

result_ode = Optimization.solve(optprob, PolyOpt(),
cb = callback,
maxiters = 100)
# result_ode = Optimization.solve(optprob, ADAM(0.1), cb = callback)
callback = callback,
maxiters = 100)
```

## Explanation
Expand Down Expand Up @@ -145,8 +144,8 @@ optf = Optimization.OptimizationFunction((x,p)->loss(x), adtype)
optprob = Optimization.OptimizationProblem(optf, p)

result_ode = Optimization.solve(optprob, PolyOpt(),
cb = callback,
maxiters = 100)
callback = callback,
maxiters = 100)
```

In just seconds we found parameters which give a relative loss of `1e-16`! We can
Expand All @@ -162,13 +161,3 @@ plot(remade_solution, ylim = (0, 6))
```

![Final plot](https://user-images.githubusercontent.com/1814174/51399500-1f4dd080-1b14-11e9-8c9d-144f93b6eac2.gif)

Note that this was done with the default optimizer. One can also pass an
optimization method, like `ADAM(0.1)`, and tweak settings like set `maxiters=100`
to force at most 100 iterations of the optimization. This looks like:

```@example optode
result_ode = Optimization.solve(optprob, ADAM(0.1),
cb = callback,
maxiters = 100)
```
2 changes: 1 addition & 1 deletion docs/src/optimal_control/feedback_control.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,5 +89,5 @@ adtype = Optimization.AutoZygote()
optf = Optimization.OptimizationFunction((x,p)->loss_univ(x), adtype)
optprob = Optimization.OptimizationProblem(optf, θ)
result_univ = Optimization.solve(optprob, PolyOpt(),
cb = callback)
callback = callback)
```
4 changes: 2 additions & 2 deletions docs/src/sde_fitting/neural_sde.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ adtype = Optimization.AutoZygote()
optf = Optimization.OptimizationFunction((x,p) -> loss_neuralsde(x, n=10), adtype)
optprob = Optimization.OptimizationProblem(optf, p)
result1 = Optimization.solve(optprob, opt,
cb = callback, maxiters = 100)
callback = callback, maxiters = 100)
```

We resume the training with a larger `n`. (WARNING - this step is a couple of
Expand All @@ -185,7 +185,7 @@ orders of magnitude longer than the previous one).
optf2 = Optimization.OptimizationFunction((x,p) -> loss_neuralsde(x, n=100), adtype)
optprob2 = Optimization.OptimizationProblem(optf2, result1.u)
result2 = Optimization.solve(optprob2, opt,
cb = callback, maxiters = 100)
callback = callback, maxiters = 100)
```

And now we plot the solution to an ensemble of the trained neural SDE:
Expand Down
2 changes: 1 addition & 1 deletion docs/src/sde_fitting/optimization_sde.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ optf = Optimization.OptimizationFunction((x,p) -> loss_sde(x), adtype)

optprob = Optimization.OptimizationProblem(optf, p)
result_sde = Optimization.solve(optprob, ADAM(0.1),
cb = callback, maxiters = 100)
callback = callback, maxiters = 100)
```

![](https://user-images.githubusercontent.com/1814174/51399524-2c6abf80-1b14-11e9-96ae-0192f7debd03.gif)
8 changes: 4 additions & 4 deletions docs/src/training_tips/local_minima.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ optf = Optimization.OptimizationFunction((x,p) -> loss_neuralode(x), adtype)

optprob = Optimization.OptimizationProblem(optf, Lux.ComponentArray(pinit))
result_neuralode = Optimization.solve(optprob,
ADAM(0.05), cb = callback,
ADAM(0.05), callback = callback,
maxiters = 300)

callback(result_neuralode.u,loss_neuralode(result_neuralode.u)...;doplot=true)
Expand All @@ -110,7 +110,7 @@ optf = Optimization.OptimizationFunction((x,p) -> loss_neuralode(x), adtype)

optprob = Optimization.OptimizationProblem(optf, ComponentArray(pinit))
result_neuralode2 = Optimization.solve(optprob,
ADAM(0.05), cb = callback,
ADAM(0.05), callback = callback,
maxiters = 300)

callback(result_neuralode2.u,loss_neuralode(result_neuralode2.u)...;doplot=true)
Expand All @@ -128,7 +128,7 @@ prob_neuralode = NeuralODE(dudt2, (0.0,3.0), Tsit5(), saveat = tsteps[tsteps .<=
optprob = Optimization.OptimizationProblem(optf, result_neuralode.u)
result_neuralode3 = Optimization.solve(optprob,
ADAM(0.05), maxiters = 300,
cb = callback)
callback = callback)
callback(result_neuralode3.u,loss_neuralode(result_neuralode3.u)...;doplot=true)
savefig("shortplot2.png")
```
Expand All @@ -143,7 +143,7 @@ prob_neuralode = NeuralODE(dudt2, (0.0,5.0), Tsit5(), saveat = tsteps)
optprob = Optimization.OptimizationProblem(optf, result_neuralode3.u)
result_neuralode4 = Optimization.solve(optprob,
ADAM(0.01), maxiters = 300,
cb = callback)
callback = callback)
callback(result_neuralode4.u,loss_neuralode(result_neuralode4.u)...;doplot=true)
savefig("fullplot.png")
```
Expand Down