Skip to content

Commit

Permalink
Merge pull request #380 from SciML/ap/formatting
Browse files Browse the repository at this point in the history
Enable formatting with `join_lines_based_on_source=false`
  • Loading branch information
ChrisRackauckas authored Feb 18, 2024
2 parents c50c21a + c7e10db commit d383660
Show file tree
Hide file tree
Showing 60 changed files with 897 additions and 946 deletions.
1 change: 1 addition & 0 deletions .JuliaFormatter.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ style = "sciml"
format_markdown = true
annotate_untyped_fields_with_any = false
format_docstrings = true
join_lines_based_on_source = false
24 changes: 14 additions & 10 deletions docs/make.jl
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
using Documenter, DocumenterCitations
using NonlinearSolve,
SimpleNonlinearSolve, Sundials, SteadyStateDiffEq, SciMLBase, DiffEqBase
using NonlinearSolve, SimpleNonlinearSolve, Sundials, SteadyStateDiffEq, SciMLBase,
DiffEqBase

cp(joinpath(@__DIR__, "Manifest.toml"), joinpath(@__DIR__, "src/assets/Manifest.toml"),
force = true)
cp(joinpath(@__DIR__, "Project.toml"), joinpath(@__DIR__, "src/assets/Project.toml"),
force = true)
cp(joinpath(@__DIR__, "Manifest.toml"),
joinpath(@__DIR__, "src/assets/Manifest.toml"), force = true)
cp(joinpath(@__DIR__, "Project.toml"),
joinpath(@__DIR__, "src/assets/Project.toml"), force = true)

include("pages.jl")

bib = CitationBibliography(joinpath(@__DIR__, "src", "refs.bib"))

makedocs(; sitename = "NonlinearSolve.jl",
authors = "Chris Rackauckas",
modules = [NonlinearSolve, SimpleNonlinearSolve, SteadyStateDiffEq, Sundials,
DiffEqBase, SciMLBase],
clean = true, doctest = false, linkcheck = true,
modules = [NonlinearSolve, SimpleNonlinearSolve,
SteadyStateDiffEq, Sundials, DiffEqBase, SciMLBase],
clean = true,
doctest = false,
linkcheck = true,
linkcheck_ignore = ["https://twitter.com/ChrisRackauckas/status/1544743542094020615"],
checkdocs = :exports, warnonly = [:missing_docs], plugins = [bib],
checkdocs = :exports,
warnonly = [:missing_docs],
plugins = [bib],
format = Documenter.HTML(assets = ["assets/favicon.ico", "assets/citations.css"],
canonical = "https://docs.sciml.ai/NonlinearSolve/stable/"),
pages)
Expand Down
63 changes: 21 additions & 42 deletions docs/pages.jl
Original file line number Diff line number Diff line change
@@ -1,47 +1,26 @@
# Put in a separate page so it can be used by SciMLDocs.jl

pages = [
"index.md",
pages = ["index.md",
"Getting Started with Nonlinear Rootfinding in Julia" => "tutorials/getting_started.md",
"Tutorials" => Any["tutorials/code_optimization.md",
"tutorials/large_systems.md",
"tutorials/modelingtoolkit.md",
"tutorials/small_compile.md",
"tutorials/iterator_interface.md",
"tutorials/optimizing_parameterized_ode.md"],
"Basics" => Any["basics/nonlinear_problem.md",
"basics/nonlinear_functions.md",
"basics/solve.md",
"basics/nonlinear_solution.md",
"basics/autodiff.md",
"basics/termination_condition.md",
"basics/diagnostics_api.md",
"basics/sparsity_detection.md",
"basics/faq.md"],
"Tutorials" => Any["tutorials/code_optimization.md", "tutorials/large_systems.md",
"tutorials/modelingtoolkit.md", "tutorials/small_compile.md",
"tutorials/iterator_interface.md", "tutorials/optimizing_parameterized_ode.md"],
"Basics" => Any["basics/nonlinear_problem.md", "basics/nonlinear_functions.md",
"basics/solve.md", "basics/nonlinear_solution.md", "basics/autodiff.md",
"basics/termination_condition.md", "basics/diagnostics_api.md",
"basics/sparsity_detection.md", "basics/faq.md"],
"Solver Summaries and Recommendations" => Any["solvers/nonlinear_system_solvers.md",
"solvers/bracketing_solvers.md",
"solvers/steady_state_solvers.md",
"solvers/nonlinear_least_squares_solvers.md",
"solvers/fixed_point_solvers.md"],
"Native Functionalities" => Any["native/solvers.md",
"native/simplenonlinearsolve.md",
"native/steadystatediffeq.md",
"native/descent.md",
"native/globalization.md",
"native/diagnostics.md"],
"Wrapped Solver APIs" => Any["api/fastlevenbergmarquardt.md",
"api/fixedpointacceleration.md",
"api/leastsquaresoptim.md",
"api/minpack.md",
"api/nlsolve.md",
"api/siamfanlequations.md",
"api/speedmapping.md",
"api/sundials.md"],
"Development Documentation" => ["devdocs/internal_interfaces.md",
"devdocs/linear_solve.md",
"devdocs/jacobian.md",
"devdocs/operators.md",
"devdocs/algorithm_helpers.md"],
"solvers/bracketing_solvers.md", "solvers/steady_state_solvers.md",
"solvers/nonlinear_least_squares_solvers.md", "solvers/fixed_point_solvers.md"],
"Native Functionalities" => Any["native/solvers.md", "native/simplenonlinearsolve.md",
"native/steadystatediffeq.md", "native/descent.md",
"native/globalization.md", "native/diagnostics.md"],
"Wrapped Solver APIs" => Any[
"api/fastlevenbergmarquardt.md", "api/fixedpointacceleration.md",
"api/leastsquaresoptim.md", "api/minpack.md", "api/nlsolve.md",
"api/siamfanlequations.md", "api/speedmapping.md", "api/sundials.md"],
"Development Documentation" => [
"devdocs/internal_interfaces.md", "devdocs/linear_solve.md",
"devdocs/jacobian.md", "devdocs/operators.md", "devdocs/algorithm_helpers.md"],
"Release Notes" => "release_notes.md",
"References" => "references.md"
]
"References" => "references.md"]
4 changes: 1 addition & 3 deletions docs/src/basics/diagnostics_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ using ModelingToolkit, NonlinearSolve
@parameters σ ρ β
# Define a nonlinear system
eqs = [0 ~ σ * (y - x),
0 ~ x * (ρ - z) - y,
0 ~ x * y - β * z]
eqs = [0 ~ σ * (y - x), 0 ~ x * (ρ - z) - y, 0 ~ x * y - β * z]
@named ns = NonlinearSystem(eqs, [x, y, z], [σ, ρ, β])
u0 = [x => 1.0, y => 0.0, z => 0.0]
Expand Down
11 changes: 5 additions & 6 deletions docs/src/basics/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,16 @@ myfun(x, lv) = x * sin(x) - lv
function f(out, levels, u0)
for i in 1:N
out[i] = solve(
IntervalNonlinearProblem{false}(IntervalNonlinearFunction{false}(myfun),
u0, levels[i]),
IntervalNonlinearProblem{false}(
IntervalNonlinearFunction{false}(myfun), u0, levels[i]),
Falsi()).u
end
end
function f2(out, levels, u0)
for i in 1:N
out[i] = solve(
NonlinearProblem{false}(NonlinearFunction{false}(myfun),
u0, levels[i]),
NonlinearProblem{false}(NonlinearFunction{false}(myfun), u0, levels[i]),
SimpleNewtonRaphson()).u
end
end
Expand Down Expand Up @@ -75,8 +74,8 @@ be a Dual number. This causes the error. To fix it:
1. Specify the `autodiff` to be `AutoFiniteDiff`

```@example dual_error_faq
sol = solve(prob_oop, LevenbergMarquardt(; autodiff = AutoFiniteDiff()); maxiters = 10000,
abstol = 1e-8)
sol = solve(prob_oop, LevenbergMarquardt(; autodiff = AutoFiniteDiff());
maxiters = 10000, abstol = 1e-8)
```

This worked but, Finite Differencing is not the recommended approach in any scenario.
Expand Down
13 changes: 5 additions & 8 deletions docs/src/basics/sparsity_detection.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,10 @@ Now you can help the solver further by providing the color vector. This can be d

```julia
prob = NonlinearProblem(
NonlinearFunction(nlfunc; sparsity = jac_prototype,
colorvec = colorvec), x0)
NonlinearFunction(nlfunc; sparsity = jac_prototype, colorvec = colorvec), x0)
# OR
prob = NonlinearProblem(
NonlinearFunction(nlfunc; jac_prototype = jac_prototype,
colorvec = colorvec), x0)
NonlinearFunction(nlfunc; jac_prototype = jac_prototype, colorvec = colorvec), x0)
```

If the `colorvec` is not provided, then it is computed on demand.
Expand All @@ -46,12 +44,11 @@ If you don't have a Sparse Jacobian Prototype, but you know the which sparsity d
algorithm you want to use, then you can create your problem as follows:

```julia
prob = NonlinearProblem(NonlinearFunction(nlfunc; sparsity = SymbolicsSparsityDetection()),
x0) # Remember to have Symbolics.jl loaded
prob = NonlinearProblem(
NonlinearFunction(nlfunc; sparsity = SymbolicsSparsityDetection()), x0) # Remember to have Symbolics.jl loaded
# OR
prob = NonlinearProblem(
NonlinearFunction(nlfunc; sparsity = ApproximateJacobianSparsity()),
x0)
NonlinearFunction(nlfunc; sparsity = ApproximateJacobianSparsity()), x0)
```

These Detection Algorithms are from [SparseDiffTools.jl](https://github.com/JuliaDiff/SparseDiffTools.jl),
Expand Down
10 changes: 8 additions & 2 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,15 @@ using TOML
using Markdown
version = TOML.parse(read("../../Project.toml", String))["version"]
name = TOML.parse(read("../../Project.toml", String))["name"]
link_manifest = "https://github.com/SciML/" * name * ".jl/tree/gh-pages/v" * version *
link_manifest = "https://github.com/SciML/" *
name *
".jl/tree/gh-pages/v" *
version *
"/assets/Manifest.toml"
link_project = "https://github.com/SciML/" * name * ".jl/tree/gh-pages/v" * version *
link_project = "https://github.com/SciML/" *
name *
".jl/tree/gh-pages/v" *
version *
"/assets/Project.toml"
Markdown.parse("""You can also download the
[manifest]($link_manifest)
Expand Down
4 changes: 2 additions & 2 deletions docs/src/tutorials/getting_started.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@ be skipped for out of place problems):

```@example 1
u0 = [0.0, 0.0]
prob = NonlinearLeastSquaresProblem(NonlinearFunction(nlls!, resid_prototype = zeros(3)),
u0)
prob = NonlinearLeastSquaresProblem(
NonlinearFunction(nlls!, resid_prototype = zeros(3)), u0)
solve(prob)
```
Expand Down
41 changes: 19 additions & 22 deletions docs/src/tutorials/large_systems.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,10 @@ function brusselator_2d_loop(du, u, p)
limit(j - 1, N)
du[i, j, 1] = alpha * (u[im1, j, 1] + u[ip1, j, 1] + u[i, jp1, 1] + u[i, jm1, 1] -
4u[i, j, 1]) +
B + u[i, j, 1]^2 * u[i, j, 2] - (A + 1) * u[i, j, 1] +
brusselator_f(x, y)
B +
u[i, j, 1]^2 * u[i, j, 2] - (A + 1) * u[i, j, 1] + brusselator_f(x, y)
du[i, j, 2] = alpha * (u[im1, j, 2] + u[ip1, j, 2] + u[i, jp1, 2] + u[i, jm1, 2] -
4u[i, j, 2]) +
A * u[i, j, 1] - u[i, j, 1]^2 * u[i, j, 2]
4u[i, j, 2]) + A * u[i, j, 1] - u[i, j, 1]^2 * u[i, j, 2]
end
end
p = (3.4, 1.0, 10.0, step(xyd_brusselator))
Expand All @@ -100,8 +99,8 @@ function init_brusselator_2d(xyd)
end
u0 = init_brusselator_2d(xyd_brusselator)
prob_brusselator_2d = NonlinearProblem(brusselator_2d_loop, u0, p; abstol = 1e-10,
reltol = 1e-10)
prob_brusselator_2d = NonlinearProblem(
brusselator_2d_loop, u0, p; abstol = 1e-10, reltol = 1e-10)
```

## Choosing Jacobian Types
Expand Down Expand Up @@ -140,11 +139,11 @@ using BenchmarkTools # for @btime
@btime solve(prob_brusselator_2d,
NewtonRaphson(; autodiff = AutoSparseForwardDiff(; chunksize = 32)));
@btime solve(prob_brusselator_2d,
NewtonRaphson(; autodiff = AutoSparseForwardDiff(; chunksize = 32),
linsolve = KLUFactorization()));
NewtonRaphson(;
autodiff = AutoSparseForwardDiff(; chunksize = 32), linsolve = KLUFactorization()));
@btime solve(prob_brusselator_2d,
NewtonRaphson(; autodiff = AutoSparseForwardDiff(; chunksize = 32),
linsolve = KrylovJL_GMRES()));
NewtonRaphson(;
autodiff = AutoSparseForwardDiff(; chunksize = 32), linsolve = KrylovJL_GMRES()));
nothing # hide
```

Expand All @@ -164,8 +163,8 @@ kick out a sparse matrix with our pattern, that we can turn into our `jac_protot
```@example ill_conditioned_nlprob
using Symbolics
du0 = copy(u0)
jac_sparsity = Symbolics.jacobian_sparsity((du, u) -> brusselator_2d_loop(du, u, p),
du0, u0)
jac_sparsity = Symbolics.jacobian_sparsity(
(du, u) -> brusselator_2d_loop(du, u, p), du0, u0)
```

Notice that Julia gives a nice print out of the sparsity pattern. That's neat, and would be
Expand Down Expand Up @@ -275,8 +274,8 @@ function algebraicmultigrid(W, du, u, p, t, newW, Plprev, Prprev, solverdata)
end
@btime solve(prob_brusselator_2d_sparse,
NewtonRaphson(linsolve = KrylovJL_GMRES(), precs = algebraicmultigrid,
concrete_jac = true));
NewtonRaphson(
linsolve = KrylovJL_GMRES(), precs = algebraicmultigrid, concrete_jac = true));
nothing # hide
```

Expand All @@ -286,8 +285,8 @@ or with a Jacobi smoother:
function algebraicmultigrid2(W, du, u, p, t, newW, Plprev, Prprev, solverdata)
if newW === nothing || newW
A = convert(AbstractMatrix, W)
Pl = AlgebraicMultigrid.aspreconditioner(AlgebraicMultigrid.ruge_stuben(A,
presmoother = AlgebraicMultigrid.Jacobi(rand(size(A, 1))),
Pl = AlgebraicMultigrid.aspreconditioner(AlgebraicMultigrid.ruge_stuben(
A, presmoother = AlgebraicMultigrid.Jacobi(rand(size(A, 1))),
postsmoother = AlgebraicMultigrid.Jacobi(rand(size(A, 1)))))
else
Pl = Plprev
Expand All @@ -296,8 +295,8 @@ function algebraicmultigrid2(W, du, u, p, t, newW, Plprev, Prprev, solverdata)
end
@btime solve(prob_brusselator_2d_sparse,
NewtonRaphson(linsolve = KrylovJL_GMRES(), precs = algebraicmultigrid2,
concrete_jac = true));
NewtonRaphson(
linsolve = KrylovJL_GMRES(), precs = algebraicmultigrid2, concrete_jac = true));
nothing # hide
```

Expand All @@ -309,12 +308,10 @@ sparsity detection. Let's compare the two by setting the sparsity detection algo

```@example ill_conditioned_nlprob
prob_brusselator_2d_exact = NonlinearProblem(
NonlinearFunction(brusselator_2d_loop;
sparsity = SymbolicsSparsityDetection()),
NonlinearFunction(brusselator_2d_loop; sparsity = SymbolicsSparsityDetection()),
u0, p; abstol = 1e-10, reltol = 1e-10)
prob_brusselator_2d_approx = NonlinearProblem(
NonlinearFunction(brusselator_2d_loop;
sparsity = ApproximateJacobianSparsity()),
NonlinearFunction(brusselator_2d_loop; sparsity = ApproximateJacobianSparsity()),
u0, p; abstol = 1e-10, reltol = 1e-10)
@btime solve(prob_brusselator_2d_exact, NewtonRaphson());
Expand Down
17 changes: 4 additions & 13 deletions docs/src/tutorials/modelingtoolkit.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,10 @@ using ModelingToolkit, NonlinearSolve
@parameters σ ρ β
# Define a nonlinear system
eqs = [0 ~ σ * (y - x),
0 ~ x * (ρ - z) - y,
0 ~ x * y - β * z]
eqs = [0 ~ σ * (y - x), 0 ~ x * (ρ - z) - y, 0 ~ x * y - β * z]
@named ns = NonlinearSystem(eqs, [x, y, z], [σ, ρ, β])
u0 = [x => 1.0,
y => 0.0,
z => 0.0]
u0 = [x => 1.0, y => 0.0, z => 0.0]
ps = [σ => 10.0
ρ => 26.0
Expand Down Expand Up @@ -60,13 +56,8 @@ solved more simply. Let's take a look at a quick system:

```@example mtk
@variables u1 u2 u3 u4 u5
eqs = [
0 ~ u1 - sin(u5),
0 ~ u2 - cos(u1),
0 ~ u3 - hypot(u1, u2),
0 ~ u4 - hypot(u2, u3),
0 ~ u5 - hypot(u4, u1)
]
eqs = [0 ~ u1 - sin(u5), 0 ~ u2 - cos(u1), 0 ~ u3 - hypot(u1, u2),
0 ~ u4 - hypot(u2, u3), 0 ~ u5 - hypot(u4, u1)]
@named sys = NonlinearSystem(eqs, [u1, u2, u3, u4, u5], [])
```

Expand Down
Loading

0 comments on commit d383660

Please sign in to comment.