Skip to content

Commit d383660

Browse files
Merge pull request #380 from SciML/ap/formatting
Enable formatting with `join_lines_based_on_source=false`
2 parents c50c21a + c7e10db commit d383660

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+897
-946
lines changed

.JuliaFormatter.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ style = "sciml"
22
format_markdown = true
33
annotate_untyped_fields_with_any = false
44
format_docstrings = true
5+
join_lines_based_on_source = false

docs/make.jl

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,27 @@
11
using Documenter, DocumenterCitations
2-
using NonlinearSolve,
3-
SimpleNonlinearSolve, Sundials, SteadyStateDiffEq, SciMLBase, DiffEqBase
2+
using NonlinearSolve, SimpleNonlinearSolve, Sundials, SteadyStateDiffEq, SciMLBase,
3+
DiffEqBase
44

5-
cp(joinpath(@__DIR__, "Manifest.toml"), joinpath(@__DIR__, "src/assets/Manifest.toml"),
6-
force = true)
7-
cp(joinpath(@__DIR__, "Project.toml"), joinpath(@__DIR__, "src/assets/Project.toml"),
8-
force = true)
5+
cp(joinpath(@__DIR__, "Manifest.toml"),
6+
joinpath(@__DIR__, "src/assets/Manifest.toml"), force = true)
7+
cp(joinpath(@__DIR__, "Project.toml"),
8+
joinpath(@__DIR__, "src/assets/Project.toml"), force = true)
99

1010
include("pages.jl")
1111

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

1414
makedocs(; sitename = "NonlinearSolve.jl",
1515
authors = "Chris Rackauckas",
16-
modules = [NonlinearSolve, SimpleNonlinearSolve, SteadyStateDiffEq, Sundials,
17-
DiffEqBase, SciMLBase],
18-
clean = true, doctest = false, linkcheck = true,
16+
modules = [NonlinearSolve, SimpleNonlinearSolve,
17+
SteadyStateDiffEq, Sundials, DiffEqBase, SciMLBase],
18+
clean = true,
19+
doctest = false,
20+
linkcheck = true,
1921
linkcheck_ignore = ["https://twitter.com/ChrisRackauckas/status/1544743542094020615"],
20-
checkdocs = :exports, warnonly = [:missing_docs], plugins = [bib],
22+
checkdocs = :exports,
23+
warnonly = [:missing_docs],
24+
plugins = [bib],
2125
format = Documenter.HTML(assets = ["assets/favicon.ico", "assets/citations.css"],
2226
canonical = "https://docs.sciml.ai/NonlinearSolve/stable/"),
2327
pages)

docs/pages.jl

Lines changed: 21 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,26 @@
11
# Put in a separate page so it can be used by SciMLDocs.jl
22

3-
pages = [
4-
"index.md",
3+
pages = ["index.md",
54
"Getting Started with Nonlinear Rootfinding in Julia" => "tutorials/getting_started.md",
6-
"Tutorials" => Any["tutorials/code_optimization.md",
7-
"tutorials/large_systems.md",
8-
"tutorials/modelingtoolkit.md",
9-
"tutorials/small_compile.md",
10-
"tutorials/iterator_interface.md",
11-
"tutorials/optimizing_parameterized_ode.md"],
12-
"Basics" => Any["basics/nonlinear_problem.md",
13-
"basics/nonlinear_functions.md",
14-
"basics/solve.md",
15-
"basics/nonlinear_solution.md",
16-
"basics/autodiff.md",
17-
"basics/termination_condition.md",
18-
"basics/diagnostics_api.md",
19-
"basics/sparsity_detection.md",
20-
"basics/faq.md"],
5+
"Tutorials" => Any["tutorials/code_optimization.md", "tutorials/large_systems.md",
6+
"tutorials/modelingtoolkit.md", "tutorials/small_compile.md",
7+
"tutorials/iterator_interface.md", "tutorials/optimizing_parameterized_ode.md"],
8+
"Basics" => Any["basics/nonlinear_problem.md", "basics/nonlinear_functions.md",
9+
"basics/solve.md", "basics/nonlinear_solution.md", "basics/autodiff.md",
10+
"basics/termination_condition.md", "basics/diagnostics_api.md",
11+
"basics/sparsity_detection.md", "basics/faq.md"],
2112
"Solver Summaries and Recommendations" => Any["solvers/nonlinear_system_solvers.md",
22-
"solvers/bracketing_solvers.md",
23-
"solvers/steady_state_solvers.md",
24-
"solvers/nonlinear_least_squares_solvers.md",
25-
"solvers/fixed_point_solvers.md"],
26-
"Native Functionalities" => Any["native/solvers.md",
27-
"native/simplenonlinearsolve.md",
28-
"native/steadystatediffeq.md",
29-
"native/descent.md",
30-
"native/globalization.md",
31-
"native/diagnostics.md"],
32-
"Wrapped Solver APIs" => Any["api/fastlevenbergmarquardt.md",
33-
"api/fixedpointacceleration.md",
34-
"api/leastsquaresoptim.md",
35-
"api/minpack.md",
36-
"api/nlsolve.md",
37-
"api/siamfanlequations.md",
38-
"api/speedmapping.md",
39-
"api/sundials.md"],
40-
"Development Documentation" => ["devdocs/internal_interfaces.md",
41-
"devdocs/linear_solve.md",
42-
"devdocs/jacobian.md",
43-
"devdocs/operators.md",
44-
"devdocs/algorithm_helpers.md"],
13+
"solvers/bracketing_solvers.md", "solvers/steady_state_solvers.md",
14+
"solvers/nonlinear_least_squares_solvers.md", "solvers/fixed_point_solvers.md"],
15+
"Native Functionalities" => Any["native/solvers.md", "native/simplenonlinearsolve.md",
16+
"native/steadystatediffeq.md", "native/descent.md",
17+
"native/globalization.md", "native/diagnostics.md"],
18+
"Wrapped Solver APIs" => Any[
19+
"api/fastlevenbergmarquardt.md", "api/fixedpointacceleration.md",
20+
"api/leastsquaresoptim.md", "api/minpack.md", "api/nlsolve.md",
21+
"api/siamfanlequations.md", "api/speedmapping.md", "api/sundials.md"],
22+
"Development Documentation" => [
23+
"devdocs/internal_interfaces.md", "devdocs/linear_solve.md",
24+
"devdocs/jacobian.md", "devdocs/operators.md", "devdocs/algorithm_helpers.md"],
4525
"Release Notes" => "release_notes.md",
46-
"References" => "references.md"
47-
]
26+
"References" => "references.md"]

docs/src/basics/diagnostics_api.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,7 @@ using ModelingToolkit, NonlinearSolve
3333
@parameters σ ρ β
3434
3535
# Define a nonlinear system
36-
eqs = [0 ~ σ * (y - x),
37-
0 ~ x * (ρ - z) - y,
38-
0 ~ x * y - β * z]
36+
eqs = [0 ~ σ * (y - x), 0 ~ x * (ρ - z) - y, 0 ~ x * y - β * z]
3937
@named ns = NonlinearSystem(eqs, [x, y, z], [σ, ρ, β])
4038
4139
u0 = [x => 1.0, y => 0.0, z => 0.0]

docs/src/basics/faq.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,16 @@ myfun(x, lv) = x * sin(x) - lv
1616
function f(out, levels, u0)
1717
for i in 1:N
1818
out[i] = solve(
19-
IntervalNonlinearProblem{false}(IntervalNonlinearFunction{false}(myfun),
20-
u0, levels[i]),
19+
IntervalNonlinearProblem{false}(
20+
IntervalNonlinearFunction{false}(myfun), u0, levels[i]),
2121
Falsi()).u
2222
end
2323
end
2424
2525
function f2(out, levels, u0)
2626
for i in 1:N
2727
out[i] = solve(
28-
NonlinearProblem{false}(NonlinearFunction{false}(myfun),
29-
u0, levels[i]),
28+
NonlinearProblem{false}(NonlinearFunction{false}(myfun), u0, levels[i]),
3029
SimpleNewtonRaphson()).u
3130
end
3231
end
@@ -75,8 +74,8 @@ be a Dual number. This causes the error. To fix it:
7574
1. Specify the `autodiff` to be `AutoFiniteDiff`
7675

7776
```@example dual_error_faq
78-
sol = solve(prob_oop, LevenbergMarquardt(; autodiff = AutoFiniteDiff()); maxiters = 10000,
79-
abstol = 1e-8)
77+
sol = solve(prob_oop, LevenbergMarquardt(; autodiff = AutoFiniteDiff());
78+
maxiters = 10000, abstol = 1e-8)
8079
```
8180

8281
This worked but, Finite Differencing is not the recommended approach in any scenario.

docs/src/basics/sparsity_detection.md

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,10 @@ Now you can help the solver further by providing the color vector. This can be d
2323

2424
```julia
2525
prob = NonlinearProblem(
26-
NonlinearFunction(nlfunc; sparsity = jac_prototype,
27-
colorvec = colorvec), x0)
26+
NonlinearFunction(nlfunc; sparsity = jac_prototype, colorvec = colorvec), x0)
2827
# OR
2928
prob = NonlinearProblem(
30-
NonlinearFunction(nlfunc; jac_prototype = jac_prototype,
31-
colorvec = colorvec), x0)
29+
NonlinearFunction(nlfunc; jac_prototype = jac_prototype, colorvec = colorvec), x0)
3230
```
3331

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

4846
```julia
49-
prob = NonlinearProblem(NonlinearFunction(nlfunc; sparsity = SymbolicsSparsityDetection()),
50-
x0) # Remember to have Symbolics.jl loaded
47+
prob = NonlinearProblem(
48+
NonlinearFunction(nlfunc; sparsity = SymbolicsSparsityDetection()), x0) # Remember to have Symbolics.jl loaded
5149
# OR
5250
prob = NonlinearProblem(
53-
NonlinearFunction(nlfunc; sparsity = ApproximateJacobianSparsity()),
54-
x0)
51+
NonlinearFunction(nlfunc; sparsity = ApproximateJacobianSparsity()), x0)
5552
```
5653

5754
These Detection Algorithms are from [SparseDiffTools.jl](https://github.com/JuliaDiff/SparseDiffTools.jl),

docs/src/index.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,15 @@ using TOML
8484
using Markdown
8585
version = TOML.parse(read("../../Project.toml", String))["version"]
8686
name = TOML.parse(read("../../Project.toml", String))["name"]
87-
link_manifest = "https://github.com/SciML/" * name * ".jl/tree/gh-pages/v" * version *
87+
link_manifest = "https://github.com/SciML/" *
88+
name *
89+
".jl/tree/gh-pages/v" *
90+
version *
8891
"/assets/Manifest.toml"
89-
link_project = "https://github.com/SciML/" * name * ".jl/tree/gh-pages/v" * version *
92+
link_project = "https://github.com/SciML/" *
93+
name *
94+
".jl/tree/gh-pages/v" *
95+
version *
9096
"/assets/Project.toml"
9197
Markdown.parse("""You can also download the
9298
[manifest]($link_manifest)

docs/src/tutorials/getting_started.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,8 @@ be skipped for out of place problems):
180180

181181
```@example 1
182182
u0 = [0.0, 0.0]
183-
prob = NonlinearLeastSquaresProblem(NonlinearFunction(nlls!, resid_prototype = zeros(3)),
184-
u0)
183+
prob = NonlinearLeastSquaresProblem(
184+
NonlinearFunction(nlls!, resid_prototype = zeros(3)), u0)
185185
186186
solve(prob)
187187
```

docs/src/tutorials/large_systems.md

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,10 @@ function brusselator_2d_loop(du, u, p)
7878
limit(j - 1, N)
7979
du[i, j, 1] = alpha * (u[im1, j, 1] + u[ip1, j, 1] + u[i, jp1, 1] + u[i, jm1, 1] -
8080
4u[i, j, 1]) +
81-
B + u[i, j, 1]^2 * u[i, j, 2] - (A + 1) * u[i, j, 1] +
82-
brusselator_f(x, y)
81+
B +
82+
u[i, j, 1]^2 * u[i, j, 2] - (A + 1) * u[i, j, 1] + brusselator_f(x, y)
8383
du[i, j, 2] = alpha * (u[im1, j, 2] + u[ip1, j, 2] + u[i, jp1, 2] + u[i, jm1, 2] -
84-
4u[i, j, 2]) +
85-
A * u[i, j, 1] - u[i, j, 1]^2 * u[i, j, 2]
84+
4u[i, j, 2]) + A * u[i, j, 1] - u[i, j, 1]^2 * u[i, j, 2]
8685
end
8786
end
8887
p = (3.4, 1.0, 10.0, step(xyd_brusselator))
@@ -100,8 +99,8 @@ function init_brusselator_2d(xyd)
10099
end
101100
102101
u0 = init_brusselator_2d(xyd_brusselator)
103-
prob_brusselator_2d = NonlinearProblem(brusselator_2d_loop, u0, p; abstol = 1e-10,
104-
reltol = 1e-10)
102+
prob_brusselator_2d = NonlinearProblem(
103+
brusselator_2d_loop, u0, p; abstol = 1e-10, reltol = 1e-10)
105104
```
106105

107106
## Choosing Jacobian Types
@@ -140,11 +139,11 @@ using BenchmarkTools # for @btime
140139
@btime solve(prob_brusselator_2d,
141140
NewtonRaphson(; autodiff = AutoSparseForwardDiff(; chunksize = 32)));
142141
@btime solve(prob_brusselator_2d,
143-
NewtonRaphson(; autodiff = AutoSparseForwardDiff(; chunksize = 32),
144-
linsolve = KLUFactorization()));
142+
NewtonRaphson(;
143+
autodiff = AutoSparseForwardDiff(; chunksize = 32), linsolve = KLUFactorization()));
145144
@btime solve(prob_brusselator_2d,
146-
NewtonRaphson(; autodiff = AutoSparseForwardDiff(; chunksize = 32),
147-
linsolve = KrylovJL_GMRES()));
145+
NewtonRaphson(;
146+
autodiff = AutoSparseForwardDiff(; chunksize = 32), linsolve = KrylovJL_GMRES()));
148147
nothing # hide
149148
```
150149

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

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

@@ -286,8 +285,8 @@ or with a Jacobi smoother:
286285
function algebraicmultigrid2(W, du, u, p, t, newW, Plprev, Prprev, solverdata)
287286
if newW === nothing || newW
288287
A = convert(AbstractMatrix, W)
289-
Pl = AlgebraicMultigrid.aspreconditioner(AlgebraicMultigrid.ruge_stuben(A,
290-
presmoother = AlgebraicMultigrid.Jacobi(rand(size(A, 1))),
288+
Pl = AlgebraicMultigrid.aspreconditioner(AlgebraicMultigrid.ruge_stuben(
289+
A, presmoother = AlgebraicMultigrid.Jacobi(rand(size(A, 1))),
291290
postsmoother = AlgebraicMultigrid.Jacobi(rand(size(A, 1)))))
292291
else
293292
Pl = Plprev
@@ -296,8 +295,8 @@ function algebraicmultigrid2(W, du, u, p, t, newW, Plprev, Prprev, solverdata)
296295
end
297296
298297
@btime solve(prob_brusselator_2d_sparse,
299-
NewtonRaphson(linsolve = KrylovJL_GMRES(), precs = algebraicmultigrid2,
300-
concrete_jac = true));
298+
NewtonRaphson(
299+
linsolve = KrylovJL_GMRES(), precs = algebraicmultigrid2, concrete_jac = true));
301300
nothing # hide
302301
```
303302

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

310309
```@example ill_conditioned_nlprob
311310
prob_brusselator_2d_exact = NonlinearProblem(
312-
NonlinearFunction(brusselator_2d_loop;
313-
sparsity = SymbolicsSparsityDetection()),
311+
NonlinearFunction(brusselator_2d_loop; sparsity = SymbolicsSparsityDetection()),
314312
u0, p; abstol = 1e-10, reltol = 1e-10)
315313
prob_brusselator_2d_approx = NonlinearProblem(
316-
NonlinearFunction(brusselator_2d_loop;
317-
sparsity = ApproximateJacobianSparsity()),
314+
NonlinearFunction(brusselator_2d_loop; sparsity = ApproximateJacobianSparsity()),
318315
u0, p; abstol = 1e-10, reltol = 1e-10)
319316
320317
@btime solve(prob_brusselator_2d_exact, NewtonRaphson());

docs/src/tutorials/modelingtoolkit.md

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,10 @@ using ModelingToolkit, NonlinearSolve
1212
@parameters σ ρ β
1313
1414
# Define a nonlinear system
15-
eqs = [0 ~ σ * (y - x),
16-
0 ~ x * (ρ - z) - y,
17-
0 ~ x * y - β * z]
15+
eqs = [0 ~ σ * (y - x), 0 ~ x * (ρ - z) - y, 0 ~ x * y - β * z]
1816
@named ns = NonlinearSystem(eqs, [x, y, z], [σ, ρ, β])
1917
20-
u0 = [x => 1.0,
21-
y => 0.0,
22-
z => 0.0]
18+
u0 = [x => 1.0, y => 0.0, z => 0.0]
2319
2420
ps = [σ => 10.0
2521
ρ => 26.0
@@ -60,13 +56,8 @@ solved more simply. Let's take a look at a quick system:
6056

6157
```@example mtk
6258
@variables u1 u2 u3 u4 u5
63-
eqs = [
64-
0 ~ u1 - sin(u5),
65-
0 ~ u2 - cos(u1),
66-
0 ~ u3 - hypot(u1, u2),
67-
0 ~ u4 - hypot(u2, u3),
68-
0 ~ u5 - hypot(u4, u1)
69-
]
59+
eqs = [0 ~ u1 - sin(u5), 0 ~ u2 - cos(u1), 0 ~ u3 - hypot(u1, u2),
60+
0 ~ u4 - hypot(u2, u3), 0 ~ u5 - hypot(u4, u1)]
7061
@named sys = NonlinearSystem(eqs, [u1, u2, u3, u4, u5], [])
7162
```
7263

0 commit comments

Comments
 (0)