Skip to content

Commit 35bea3e

Browse files
committed
chore: apply suggestions from code review
1 parent 607f5c4 commit 35bea3e

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

docs/src/basics/sparsity_detection.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ If the `colorvec` is not provided, then it is computed on demand.
3737

3838
Previously you could provide a `sparsity` argument to `NonlinearFunction` to specify
3939
the jacobian prototype. However, to avoid confusion, this is now deprecated. Instead,
40-
use the `jac_prototype` argument.
40+
use the `jac_prototype` argument. `sparsity` must be used to exclusively specify the
41+
sparsity detection algorithm.
4142

4243
## Case II: Sparsity Detection algorithm is provided
4344

@@ -46,14 +47,14 @@ algorithm you want to use, then you can create your problem as follows:
4647

4748
```julia
4849
prob = NonlinearProblem(
49-
NonlinearFunction(nlfunc; sparsity = SymbolicsSparsityDetection()), x0) # Remember to have Symbolics.jl loaded
50+
NonlinearFunction(nlfunc; sparsity = SymbolicsSparsityDetector()), x0) # Remember to have Symbolics.jl loaded
5051
# OR
5152
prob = NonlinearProblem(
5253
NonlinearFunction(nlfunc; sparsity = TracerSparsityDetector()), x0) # From SparseConnectivityTracer.jl
5354
```
5455

55-
Refer to the documentation of DifferentiationInterface.jl for more information on
56-
sparsity detection algorithms.
56+
Refer to the documentation of DifferentiationInterface.jl and SparseConnectivityTracer.jl
57+
for more information on sparsity detection algorithms.
5758

5859
## Case III: Sparse AD Type is being Used
5960

src/NonlinearSolve.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ using SparseConnectivityTracer: TracerSparsityDetector # This can be dropped in
5757
using SparseDiffTools: SparseDiffTools, JacPrototypeSparsityDetection,
5858
PrecomputedJacobianColorvec, init_jacobian, sparse_jacobian,
5959
sparse_jacobian!, sparse_jacobian_cache
60-
using SparseMatrixColorings: ConstantColoringAlgorithm, GreedyColoringAlgorithm
60+
using SparseMatrixColorings: ConstantColoringAlgorithm, GreedyColoringAlgorithm,
61+
LargestFirst
6162

6263
@reexport using SciMLBase, SimpleNonlinearSolve
6364

src/internal/jacobian.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ function JacobianCache(prob, alg, f::F, fu_, u, p; stats, autodiff = nothing,
6464
if !has_analytic_jac && needs_jac
6565
autodiff = construct_concrete_adtype(f, autodiff)
6666
using_sparsedifftools = autodiff isa StructuredMatrixAutodiff
67-
# DI can't handle structured matrices
67+
# SparseMatrixColorings can't handle structured matrices
6868
if using_sparsedifftools
6969
di_extras = nothing
7070
uf = JacobianWrapper{iip}(f, p)
@@ -249,7 +249,7 @@ function construct_concrete_adtype(f::NonlinearFunction, ad::AbstractADType)
249249
return AutoSparse(
250250
ad;
251251
sparsity_detector,
252-
coloring_algorithm = GreedyColoringAlgorithm()
252+
coloring_algorithm = GreedyColoringAlgorithm(LargestFirst())
253253
)
254254
else
255255
if ArrayInterface.isstructured(f.jac_prototype)
@@ -304,7 +304,7 @@ function select_fastest_structured_matrix_autodiff(
304304
JacPrototypeSparsityDetection(; jac_prototype = prototype)
305305
end
306306
end
307-
return StructuredMatrixAutodiff(ad, sparsity_detection)
307+
return StructuredMatrixAutodiff(AutoSparse(ad), sparsity_detection)
308308
end
309309

310310
function select_fastest_coloring_algorithm(
@@ -314,7 +314,7 @@ function select_fastest_coloring_algorithm(
314314
ADTypes.mode(ad) isa ADTypes.ReverseMode, :row, :column)}(
315315
prototype, f.colorvec)
316316
end
317-
return GreedyColoringAlgorithm()
317+
return GreedyColoringAlgorithm(LargestFirst())
318318
end
319319

320320
function construct_concrete_adtype(f::NonlinearFunction, ad::AutoSparse)

0 commit comments

Comments
 (0)