diff --git a/docs/Project.toml b/docs/Project.toml index 841750d2..35c2ad9d 100644 --- a/docs/Project.toml +++ b/docs/Project.toml @@ -8,7 +8,7 @@ ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210" ImplicitDifferentiation = "57b37032-215b-411a-8a7c-41a003a55207" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" Literate = "98b081ad-f1c9-55d3-8b20-4c87d4299306" -NLsolve = "2774e3e8-f4cf-5e23-947b-6d7e65073b56" +NonlinearSolve = "8913a72c-1f9b-4ce2-8d82-65094dcecaec" Optim = "429524aa-4258-5aef-a3af-852621145aeb" Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" @@ -23,5 +23,5 @@ FiniteDiff = "2.29.0" ForwardDiff = "1.3.1" ImplicitDifferentiation = "0.9.1" Literate = "2.21.0" -NLsolve = "4.5.1" +NonlinearSolve = "4.17.1" Zygote = "0.7.10" diff --git a/examples/1_basic.jl b/examples/1_basic.jl index dae14007..ee76fb0a 100644 --- a/examples/1_basic.jl +++ b/examples/1_basic.jl @@ -12,7 +12,7 @@ Note that some packages from the [SciML](https://sciml.ai/) ecosystem provide a using ForwardDiff using ImplicitDifferentiation using LinearAlgebra -using NLsolve +import NonlinearSolve as NLS using Optim using Test #src using Zygote @@ -126,22 +126,23 @@ To make verification easy, we solve the following system: ```math c(x, y) = y \odot y - x = 0 ``` -In this case, the optimization problem boils down to the componentwise square root function, but we implement it using a black box solver from [NLsolve.jl](https://github.com/JuliaNLSolvers/NLsolve.jl). +In this case, the optimization problem boils down to the componentwise square root function, but we implement it using a black box solver from [NonlinearSolve.jl](https://github.com/SciML/NonlinearSolve.jl). =# -function forward_nlsolve(x, method) - F!(storage, y) = (storage .= y .^ 2 .- x) +function forward_nlsolve(x) + F!(storage, y, x) = (storage .= y .^ 2 .- x) initial_y = similar(x) initial_y .= 1 - result = nlsolve(F!, initial_y; method) - y = result.zero + prob = NLS.NonlinearProblem(F!, initial_y, x; abstol=1e-10, reltol=1e-10) + sol = NLS.solve(prob) + y = sol.u z = nothing return y, z end; #- -function conditions_nlsolve(x, y, _z, _method) +function conditions_nlsolve(x, y, _z) c = y .^ 2 .- x return c end; @@ -152,27 +153,27 @@ implicit_nlsolve = ImplicitFunction(forward_nlsolve, conditions_nlsolve) #- -first(implicit_nlsolve(x, :newton)) .^ 2 -@test first(implicit_nlsolve(x, :newton)) .^ 2 ≈ x #src +first(implicit_nlsolve(x)) .^ 2 +@test first(implicit_nlsolve(x)) .^ 2 ≈ x #src # Forward mode autodiff -ForwardDiff.jacobian(_x -> first(implicit_nlsolve(_x, :newton)), x) -@test ForwardDiff.jacobian(_x -> first(implicit_nlsolve(_x, :newton)), x) ≈ J #src +ForwardDiff.jacobian(_x -> first(implicit_nlsolve(_x)), x) +@test ForwardDiff.jacobian(_x -> first(implicit_nlsolve(_x)), x) ≈ J #src #- -ForwardDiff.jacobian(_x -> first(forward_nlsolve(_x, :newton)), x) +ForwardDiff.jacobian(_x -> first(forward_nlsolve(_x)), x) # Reverse mode autodiff -Zygote.jacobian(_x -> first(implicit_nlsolve(_x, :newton)), x)[1] -@test Zygote.jacobian(_x -> first(implicit_nlsolve(_x, :newton)), x)[1] ≈ J #src +Zygote.jacobian(_x -> first(implicit_nlsolve(_x)), x)[1] +@test Zygote.jacobian(_x -> first(implicit_nlsolve(_x)), x)[1] ≈ J #src #- try - Zygote.jacobian(_x -> first(forward_nlsolve(_x, :newton)), x)[1] + Zygote.jacobian(_x -> first(forward_nlsolve(_x)), x)[1] catch e e end diff --git a/test/Project.toml b/test/Project.toml index 5bd794f0..5ce2f615 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -13,7 +13,7 @@ ImplicitDifferentiation = "57b37032-215b-411a-8a7c-41a003a55207" JET = "c3a54625-cd67-489e-a8e7-0a5a0ff4e31b" KrylovKit = "0b1a1467-8014-51b9-945f-bf0ae24f4b77" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" -NLsolve = "2774e3e8-f4cf-5e23-947b-6d7e65073b56" +NonlinearSolve = "8913a72c-1f9b-4ce2-8d82-65094dcecaec" Optim = "429524aa-4258-5aef-a3af-852621145aeb" Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" @@ -41,7 +41,7 @@ ImplicitDifferentiation = "0.9.1" JET = "0.9, 0.10, 0.11" KrylovKit = "0.10.2" LinearAlgebra = "1" -NLsolve = "4.5.1" +NonlinearSolve = "4.17.1" Optim = "1.12.0, 2.0" Random = "1" SparseArrays = "1"