Skip to content

Commit

Permalink
Fix #13 (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
briochemc authored Dec 8, 2021
1 parent 3c41182 commit 9cd83e1
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 37 deletions.
6 changes: 3 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
name = "F1Method"
uuid = "d5605bae-6d76-11e9-2fd7-71bcf42edbaa"
authors = ["Benoit Pasquier <[email protected]>"]
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]
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion docs/Project.toml
Original file line number Diff line number Diff line change
@@ -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"
2 changes: 1 addition & 1 deletion docs/make.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Documenter, F1Method
using LinearAlgebra, DiffEqBase, ForwardDiff
using LinearAlgebra, SciMLBase, ForwardDiff

makedocs(
sitename="F1Method Documentation",
Expand Down
20 changes: 10 additions & 10 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/F1Method.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 11 additions & 11 deletions test/diffusion_problem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
16 changes: 8 additions & 8 deletions test/rosenbrock.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module SubModuleRosenBrock
using Test
using F1Method
using LinearAlgebra
using DiffEqBase
using SciMLBase
using ForwardDiff

# Set up:
Expand All @@ -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


Expand Down

2 comments on commit 9cd83e1

@briochemc
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/50203

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.5.1 -m "<description of version>" 9cd83e1d6b72ac84b86332eab0d57d48586e5d33
git push origin v0.5.1

Please sign in to comment.