From 9cd83e1d6b72ac84b86332eab0d57d48586e5d33 Mon Sep 17 00:00:00 2001 From: Benoit Pasquier <4486578+briochemc@users.noreply.github.com> Date: Thu, 9 Dec 2021 09:04:53 +1100 Subject: [PATCH] Fix #13 (#14) --- Project.toml | 6 +++--- README.md | 4 ++-- docs/Project.toml | 2 +- docs/make.jl | 2 +- docs/src/index.md | 20 ++++++++++---------- src/F1Method.jl | 2 +- test/diffusion_problem.jl | 22 +++++++++++----------- test/rosenbrock.jl | 16 ++++++++-------- 8 files changed, 37 insertions(+), 37 deletions(-) diff --git a/Project.toml b/Project.toml index 2ce51bf..ad2e411 100644 --- a/Project.toml +++ b/Project.toml @@ -1,16 +1,16 @@ name = "F1Method" uuid = "d5605bae-6d76-11e9-2fd7-71bcf42edbaa" authors = ["Benoit Pasquier "] -version = "0.5.0" +version = "0.5.1" [deps] -DiffEqBase = "2b5f629d-d688-5b77-993f-72d75c75574e" ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" +SciMLBase = "0bca4576-84f4-4d90-8ffe-ffa030f20462" [compat] -DiffEqBase = "6" ForwardDiff = "0.10" +SciMLBase = "1" julia = "1" [extras] diff --git a/README.md b/README.md index def5e54..de6db7b 100644 --- a/README.md +++ b/README.md @@ -70,12 +70,12 @@ A requirement of the F-1 algorithm is that the Jacobian matrix `A = ∇ₓF` can To use the F-1 algorithm, the user must: - Make sure that there is a suitable algorithm `alg` to solve the steady-state equation -- overload the `solve` function and the `SteadyStateProblem` constructor from [DiffEqBase](https://github.com/JuliaDiffEq/DiffEqBase.jl). (An example is given in the CI tests — see, e.g., the [`test/simple_setup.jl`](test/simple_setup.jl) file.) +- overload the `solve` function and the `SteadyStateProblem` constructor from [SciMLBase](https://github.com/JuliaDiffEq/SciMLBase.jl). (An example is given in the CI tests — see, e.g., the [`test/simple_setup.jl`](test/simple_setup.jl) file.) - Provide the derivatives of `f` and `F` with respect to the state, `x`. ## A concrete example -Make sure you have overloaded `solve` from DiffEqBase +Make sure you have overloaded `solve` from SciMLBase (an example of how to do this is given in the [documentation](https://briochemc.github.io/F1Method.jl/stable/)). Once initial values for the state, `x`, and parameters, `p`, are chosen, simply initialize the required memory cache, `mem` via diff --git a/docs/Project.toml b/docs/Project.toml index 9146592..9d83da6 100644 --- a/docs/Project.toml +++ b/docs/Project.toml @@ -1,7 +1,7 @@ [deps] -DiffEqBase = "2b5f629d-d688-5b77-993f-72d75c75574e" Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4" ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210" +SciMLBase = "0bca4576-84f4-4d90-8ffe-ffa030f20462" [compat] Documenter = "~0.27" diff --git a/docs/make.jl b/docs/make.jl index 21f94dc..2ce1889 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -1,5 +1,5 @@ using Documenter, F1Method -using LinearAlgebra, DiffEqBase, ForwardDiff +using LinearAlgebra, SciMLBase, ForwardDiff makedocs( sitename="F1Method Documentation", diff --git a/docs/src/index.md b/docs/src/index.md index 131efe3..4d9fea5 100644 --- a/docs/src/index.md +++ b/docs/src/index.md @@ -14,7 +14,7 @@ In this case, there are a number of shortcuts that can be leveraged. ```@meta DocTestSetup = quote using F1Method - using LinearAlgebra, DiffEqBase, ForwardDiff + using LinearAlgebra, SciMLBase, ForwardDiff end ``` @@ -63,8 +63,8 @@ f(x,p) = state_mismatch(x) + parameter_mismatch(p) ``` Once these are set up, we need to let the F-1 method know how to solve for the steady-state. -We do this by using the [DiffEqBase](https://github.com/SciML/DiffEqBase.jl) API. -For that, we first write a small Newton solver algorithm, we overload the `solve` function from DiffEqBase, and we overload the `SteadyStateProblem` constructor. +We do this by using the [SciMLBase](https://github.com/SciML/SciMLBase.jl) API. +For that, we first write a small Newton solver algorithm, we overload the `solve` function from SciMLBase, and we overload the `SteadyStateProblem` constructor. ```jldoctest usage function newton_solve(F, ∇ₓF, x; Ftol=1e-10) @@ -75,23 +75,23 @@ function newton_solve(F, ∇ₓF, x; Ftol=1e-10) end # Create a type for the solver's algorithm -struct MyAlg <: DiffEqBase.AbstractSteadyStateAlgorithm end +struct MyAlg <: SciMLBase.AbstractSteadyStateAlgorithm end -# Overload DiffEqBase's solve function -function DiffEqBase.solve(prob::DiffEqBase.AbstractSteadyStateProblem, +# Overload SciMLBase's solve function +function SciMLBase.solve(prob::SciMLBase.AbstractSteadyStateProblem, alg::MyAlg; Ftol=1e-10) - # Define the functions according to DiffEqBase.SteadyStateProblem type + # Define the functions according to SciMLBase.SteadyStateProblem type p = prob.p x0 = copy(prob.u0) dx, df = copy(x0), copy(x0) F(x) = prob.f(x, p) ∇ₓF(x) = prob.f.jac(x, p) - # Compute `u_steady` and `resid` as per DiffEqBase using my algorithm + # Compute `u_steady` and `resid` as per SciMLBase using my algorithm x_steady = newton_solve(F, ∇ₓF, x0, Ftol=Ftol) resid = F(x_steady) - # Return the common DiffEqBase solution type - DiffEqBase.build_solution(prob, alg, x_steady, resid; retcode=:Success) + # Return the common SciMLBase solution type + SciMLBase.build_solution(prob, alg, x_steady, resid; retcode=:Success) end # output diff --git a/src/F1Method.jl b/src/F1Method.jl index 7183c4a..4788f6f 100644 --- a/src/F1Method.jl +++ b/src/F1Method.jl @@ -7,7 +7,7 @@ refer to the Equation numbers in the above manuscript. A bibtex citation file is available in the GitHub repository. ======================================================================# -using LinearAlgebra, ForwardDiff, DiffEqBase +using LinearAlgebra, ForwardDiff, SciMLBase """ Mem diff --git a/test/diffusion_problem.jl b/test/diffusion_problem.jl index e7ed824..82fe043 100644 --- a/test/diffusion_problem.jl +++ b/test/diffusion_problem.jl @@ -3,7 +3,7 @@ using Test, FormulaOneMethod #@testset "Testing in a diffusion system" begin - using LinearAlgebra, SparseArrays, SuiteSparse, DiffEqBase, FormulaOneMethod + using LinearAlgebra, SparseArrays, SuiteSparse, SciMLBase, FormulaOneMethod # 2D Laplacian function laplacian_2D(nx, ny, k) @@ -64,31 +64,31 @@ using Test, FormulaOneMethod end # Create a type for the solver's algorithm - struct MyAlg <: DiffEqBase.AbstractSteadyStateAlgorithm end + struct MyAlg <: SciMLBase.AbstractSteadyStateAlgorithm end - # Overload DiffEqBase's solve function - function DiffEqBase.solve(prob::DiffEqBase.AbstractSteadyStateProblem, + # Overload SciMLBase's solve function + function SciMLBase.solve(prob::SciMLBase.AbstractSteadyStateProblem, alg::MyAlg; Ftol=1e-10) - # Define the functions according to DiffEqBase.SteadyStateProblem type + # Define the functions according to SciMLBase.SteadyStateProblem type p = prob.p t = 0 x0 = copy(prob.u0) dx, df = copy(x0), copy(x0) F(x) = prob.f(dx, x, p, t) ∇ₓF(x) = prob.f(df, dx, x, p, t) - # Compute `u_steady` and `resid` as per DiffEqBase using my algorithm + # Compute `u_steady` and `resid` as per SciMLBase using my algorithm x_steady = newton_solve(F, x0, Ftol=Ftol) resid = F(x_steady) - # Return the common DiffEqBase solution type - DiffEqBase.build_solution(prob, alg, x_steady, resid; retcode=:Success) + # Return the common SciMLBase solution type + SciMLBase.build_solution(prob, alg, x_steady, resid; retcode=:Success) end - # Overload DiffEqBase's SteadyStateProblem constructor - function DiffEqBase.SteadyStateProblem(F, x, p) + # Overload SciMLBase's SteadyStateProblem constructor + function SciMLBase.SteadyStateProblem(F, x, p) f(dx, x, p, t) = F(x, p) f(df, dx, x, p, t) = ∇ₓF(x, p) - return DiffEqBase.SteadyStateProblem(f, x, p) + return SciMLBase.SteadyStateProblem(f, x, p) end # Define objective function f(x,p) and ∇ₓf(x,p) diff --git a/test/rosenbrock.jl b/test/rosenbrock.jl index c5fe75c..de99b7e 100644 --- a/test/rosenbrock.jl +++ b/test/rosenbrock.jl @@ -5,7 +5,7 @@ module SubModuleRosenBrock using Test using F1Method using LinearAlgebra -using DiffEqBase +using SciMLBase using ForwardDiff # Set up: @@ -22,23 +22,23 @@ function newton_solve(F, ∇ₓF, x; Ftol=1e-10) end # Create a type for the solver's algorithm -struct MyAlg <: DiffEqBase.AbstractSteadyStateAlgorithm end +struct MyAlg <: SciMLBase.AbstractSteadyStateAlgorithm end -# Overload DiffEqBase's solve function -function DiffEqBase.solve(prob::DiffEqBase.AbstractSteadyStateProblem, +# Overload SciMLBase's solve function +function SciMLBase.solve(prob::SciMLBase.AbstractSteadyStateProblem, alg::MyAlg; Ftol=1e-10) - # Define the functions according to DiffEqBase.SteadyStateProblem type + # Define the functions according to SciMLBase.SteadyStateProblem type p = prob.p x0 = copy(prob.u0) dx, df = copy(x0), copy(x0) F(x) = prob.f(x, p) ∇ₓF(x) = prob.f.jac(x, p) - # Compute `u_steady` and `resid` as per DiffEqBase using my algorithm + # Compute `u_steady` and `resid` as per SciMLBase using my algorithm x_steady = newton_solve(F, ∇ₓF, x0, Ftol=Ftol) resid = F(x_steady) - # Return the common DiffEqBase solution type - DiffEqBase.build_solution(prob, alg, x_steady, resid; retcode=:Success) + # Return the common SciMLBase solution type + SciMLBase.build_solution(prob, alg, x_steady, resid; retcode=:Success) end