-
-
Notifications
You must be signed in to change notification settings - Fork 71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dynamical integrators #545
Open
HadrienNU
wants to merge
16
commits into
SciML:master
Choose a base branch
from
HadrienNU:dynamical_integrators
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 13 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
a6347c4
Allow Dynamical problem to have non diagonal noise
d078c4c
Allow Dynamical problem to have non diagonal noise
18c09a2
Add ABOBA, start implement OBABO, check to be done on weak order
e10ebfa
Implement OBABO, remains some error on weak order
6423413
change variable name
52beb4c
correct weak order
f43249b
Actually OBABO need 2 noise processes
9a80b47
update new SDEProblem interface
508edf7
tests are now passing
f836738
even more trajectories to pass the test
9783fbd
add a testset to test consistency between iip and oop implementations
frankschae f03a017
Change variable names and split test into interface and convergence t…
84f2e9e
Merge branch 'SciML:master' into dynamical_integrators
HadrienNU cb25c7c
move tests and add convergence test to buildkite queue
3ac8f46
Missing "
0b3baf1
remove info message about number of montecarlo iterations
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,188 @@ | ||
abstract type StochasticDynamicalEqConstantCache <: StochasticDiffEqConstantCache end # Pourquoi faire ça, Si c'est pour avoir une seul function de check dans initialize! | ||
abstract type StochasticDynamicalEqMutableCache <: StochasticDiffEqMutableCache end | ||
|
||
mutable struct BAOABConstantCache{uType,uEltypeNoUnits} <: StochasticDiffEqConstantCache | ||
|
||
mutable struct BAOABConstantCache{uType,uEltypeNoUnits,uCoeffType, uCoeffMType} <: StochasticDynamicalEqConstantCache | ||
k::uType | ||
half::uEltypeNoUnits | ||
c1::uEltypeNoUnits | ||
c2::uEltypeNoUnits | ||
c2::uCoeffType | ||
σ::uCoeffMType | ||
end | ||
@cache struct BAOABCache{uType,uEltypeNoUnits,rateNoiseType,uTypeCombined} <: StochasticDiffEqMutableCache | ||
@cache struct BAOABCache{uType,uEltypeNoUnits,rateNoiseType,uCoeffType, uCoeffMType,uTypeCombined} <: StochasticDynamicalEqMutableCache | ||
utmp::uType | ||
dumid::uType | ||
dutmp::uType | ||
dunoise::uType | ||
k::uType | ||
gtmp::uType | ||
noise::rateNoiseType | ||
gtmp::rateNoiseType | ||
noise::uType | ||
half::uEltypeNoUnits | ||
c1::uEltypeNoUnits | ||
c2::uEltypeNoUnits | ||
c2::uCoeffType | ||
σ::uCoeffMType | ||
tmp::uTypeCombined | ||
end | ||
|
||
function alg_cache(alg::BAOAB,prob,u,ΔW,ΔZ,p,rate_prototype,noise_rate_prototype,jump_rate_prototype,::Type{uEltypeNoUnits},::Type{uBottomEltypeNoUnits},::Type{tTypeNoUnits},uprev,f,t,dt,::Type{Val{false}}) where {uEltypeNoUnits,uBottomEltypeNoUnits,tTypeNoUnits} | ||
k = zero(rate_prototype.x[1]) | ||
c1 = exp(-alg.gamma*dt) | ||
c2 = sqrt(1 - alg.scale_noise*c1^2) # if scale_noise == false, c2 = 1 | ||
BAOABConstantCache(k, uEltypeNoUnits(1//2), uEltypeNoUnits(c1), uEltypeNoUnits(c2)) | ||
if typeof(alg.gamma) <: AbstractMatrix | ||
c2 = exp(-alg.gamma*dt) | ||
σ = cholesky(I - alg.scale_noise*c2*transpose(c2)).U# if scale_noise == false, c2 = 1 | ||
else | ||
c2 = exp.(-alg.gamma*dt) | ||
σ = sqrt.(1 .- alg.scale_noise*c2.^2)# if scale_noise == false, c2 = 1 | ||
end | ||
BAOABConstantCache(k, uEltypeNoUnits(1//2),c2, c2) | ||
end | ||
|
||
function alg_cache(alg::BAOAB,prob,u,ΔW,ΔZ,p,rate_prototype,noise_rate_prototype,jump_rate_prototype,::Type{uEltypeNoUnits},::Type{uBottomEltypeNoUnits},::Type{tTypeNoUnits},uprev,f,t,dt,::Type{Val{true}}) where {uEltypeNoUnits,uBottomEltypeNoUnits,tTypeNoUnits} | ||
dumid = zero(u.x[1]) | ||
dutmp = zero(u.x[1]) | ||
dunoise = zero(u.x[1]) | ||
utmp = zero(u.x[2]) | ||
k = zero(rate_prototype.x[1]) | ||
|
||
gtmp = zero(noise_rate_prototype) | ||
noise = zero(rate_prototype.x[1]) | ||
|
||
half = uEltypeNoUnits(1//2) | ||
|
||
if typeof(alg.gamma) <: AbstractMatrix | ||
c2 = exp(-alg.gamma*dt) | ||
σ = cholesky(I - alg.scale_noise*c2*transpose(c2)).U# if scale_noise == false, c2 = 1 | ||
else | ||
c2 = exp.(-alg.gamma*dt) | ||
σ = sqrt.(1 .- alg.scale_noise*c2.^2)# if scale_noise == false, c2 = 1 | ||
end | ||
|
||
tmp = zero(u) | ||
|
||
BAOABCache(utmp, dumid, dutmp, dunoise, k, gtmp, noise, half, c2, σ, tmp) | ||
end | ||
|
||
|
||
|
||
mutable struct ABOBAConstantCache{uType,uEltypeNoUnits, uCoeffType, uCoeffMType} <: StochasticDynamicalEqConstantCache | ||
k::uType | ||
half::uEltypeNoUnits | ||
c2::uCoeffType | ||
σ::uCoeffMType | ||
end | ||
@cache struct ABOBACache{uType,uEltypeNoUnits,rateNoiseType,uCoeffType, uCoeffMType,uTypeCombined} <: StochasticDynamicalEqMutableCache | ||
utmp::uType | ||
dumid::uType | ||
dutmp::uType | ||
dunoise::uType | ||
k::uType | ||
gtmp::rateNoiseType | ||
noise::uType | ||
half::uEltypeNoUnits | ||
c2::uCoeffType | ||
σ::uCoeffMType | ||
tmp::uTypeCombined | ||
end | ||
|
||
function alg_cache(alg::ABOBA,prob,u,ΔW,ΔZ,p,rate_prototype,noise_rate_prototype,jump_rate_prototype,::Type{uEltypeNoUnits},::Type{uBottomEltypeNoUnits},::Type{tTypeNoUnits},uprev,f,t,dt,::Type{Val{false}}) where {uEltypeNoUnits,uBottomEltypeNoUnits,tTypeNoUnits} | ||
k = zero(rate_prototype.x[1]) | ||
|
||
if typeof(alg.gamma) <: AbstractMatrix | ||
c2 = exp(-alg.gamma*dt) | ||
σ = cholesky(I - alg.scale_noise*c2*transpose(c2)).U | ||
else | ||
c2 = exp.(-alg.gamma*dt) | ||
σ = sqrt.(1 .- alg.scale_noise*c2.^2) | ||
end | ||
# if scale_noise == false, c2 = 1 | ||
ABOBAConstantCache(k, uEltypeNoUnits(1//2), c2, σ) | ||
end | ||
|
||
function alg_cache(alg::ABOBA,prob,u,ΔW,ΔZ,p,rate_prototype, noise_rate_prototype,jump_rate_prototype,::Type{uEltypeNoUnits},::Type{uBottomEltypeNoUnits},::Type{tTypeNoUnits},uprev,f,t,dt,::Type{Val{true}}) where {uEltypeNoUnits,uBottomEltypeNoUnits,tTypeNoUnits} | ||
dutmp = zero(u.x[1]) | ||
dumid = zero(u.x[1]) | ||
dunoise = zero(u.x[1]) | ||
utmp = zero(u.x[2]) | ||
k = zero(rate_prototype.x[1]) | ||
|
||
gtmp = zero(rate_prototype.x[1]) | ||
gtmp = zero(noise_rate_prototype) | ||
noise = zero(rate_prototype.x[1]) | ||
|
||
half = uEltypeNoUnits(1//2) | ||
c1 = exp(-alg.gamma*dt) | ||
c2 = sqrt(1 - alg.scale_noise*c1^2) # if scale_noise == false, c2 = 1 | ||
|
||
if typeof(alg.gamma) <: AbstractMatrix | ||
c2 = exp(-alg.gamma*dt) | ||
σ = cholesky(I - alg.scale_noise*c2*transpose(c2)).U | ||
else | ||
c2 = exp.(-alg.gamma*dt) | ||
σ = sqrt.(1 .- alg.scale_noise*c2.^2) | ||
end | ||
|
||
tmp = zero(u) | ||
|
||
ABOBACache(utmp, dumid, dutmp, dunoise, k, gtmp, noise, half, c2, σ, tmp) | ||
end | ||
|
||
|
||
|
||
|
||
mutable struct OBABOConstantCache{uType,rateNoiseType, uEltypeNoUnits, uCoeffType, uCoeffMType} <: StochasticDynamicalEqConstantCache | ||
k::uType | ||
gt::rateNoiseType | ||
half::uEltypeNoUnits | ||
c2::uCoeffType | ||
σ::uCoeffMType | ||
end | ||
|
||
@cache struct OBABOCache{uType,uEltypeNoUnits,rateNoiseType,uCoeffType, uCoeffMType,uTypeCombined} <: StochasticDynamicalEqMutableCache | ||
utmp::uType | ||
dumid::uType | ||
dutmp::uType | ||
dunoise::uType | ||
k::uType | ||
gtmp::rateNoiseType | ||
noise::uType | ||
half::uEltypeNoUnits | ||
c2::uCoeffType | ||
σ::uCoeffMType | ||
tmp::uTypeCombined | ||
end | ||
|
||
function alg_cache(alg::OBABO,prob,u,ΔW,ΔZ,p,rate_prototype,noise_rate_prototype,jump_rate_prototype,::Type{uEltypeNoUnits},::Type{uBottomEltypeNoUnits},::Type{tTypeNoUnits},uprev,f,t,dt,::Type{Val{false}}) where {uEltypeNoUnits,uBottomEltypeNoUnits,tTypeNoUnits} | ||
k = zero(rate_prototype.x[1]) | ||
gt = zero(noise_rate_prototype) | ||
half=uEltypeNoUnits(1//2) | ||
|
||
if typeof(alg.gamma) <: AbstractMatrix | ||
c2 = exp(-alg.gamma*half*dt) | ||
σ = cholesky(I - alg.scale_noise*c2*transpose(c2)).U | ||
else | ||
c2 = exp.(-alg.gamma*half*dt) | ||
σ = sqrt.(1 .- alg.scale_noise*c2.^2) | ||
end | ||
# if scale_noise == false, c2 = 1 | ||
OBABOConstantCache(k, gt, half, c2, σ) | ||
end | ||
|
||
function alg_cache(alg::OBABO,prob,u,ΔW,ΔZ,p,rate_prototype, noise_rate_prototype,jump_rate_prototype,::Type{uEltypeNoUnits},::Type{uBottomEltypeNoUnits},::Type{tTypeNoUnits},uprev,f,t,dt,::Type{Val{true}}) where {uEltypeNoUnits,uBottomEltypeNoUnits,tTypeNoUnits} | ||
dutmp = zero(u.x[1]) | ||
dumid = zero(u.x[1]) | ||
dunoise = zero(u.x[1]) | ||
utmp = zero(u.x[2]) | ||
k = zero(rate_prototype.x[1]) | ||
|
||
gtmp = zero(noise_rate_prototype) | ||
noise = zero(rate_prototype.x[1]) | ||
|
||
|
||
half = uEltypeNoUnits(1//2) | ||
|
||
if typeof(alg.gamma) <: AbstractMatrix | ||
c2 = exp(-alg.gamma*half*dt) | ||
σ = cholesky(I - alg.scale_noise*c2*transpose(c2)).U | ||
else | ||
c2 = exp.(-alg.gamma*half*dt) | ||
σ = sqrt.(1 .- alg.scale_noise*c2.^2) | ||
end | ||
|
||
tmp = zero(u) | ||
|
||
BAOABCache(utmp, dutmp, k, gtmp, noise, half, uEltypeNoUnits(c1), uEltypeNoUnits(c2), tmp) | ||
OBABOCache(utmp, dumid, dutmp, dunoise, k, gtmp, noise, half, c2, σ, tmp) | ||
end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe add a docstring that contains the SDE form:

(or to the SDE solver docs https://docs.sciml.ai/DiffEqDocs/stable/solvers/sde_solve/ given that it doesn't match our common diagonal/non-diagonal noise classification exactly?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or maybe it needs a different problem type?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is already the DynamicalSDEProblem (was introduced by the previous implementation of BAOAB) that is supposed to be solved by those integrators
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should I add some alg_compatible() functions to allow only DynamicalSDEProblem to be solved by Dynamical integrators?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes that would be helpful in order to gate it to the right form.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just realize that the DynamicalSDEProblem constructor actually return a SDEProblem so alg_comptable functions won't be useful here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But it can dispatch on
prob.problem_type
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah I think we should use
DynamicalSDEProblem
and it's a good idea to usealg_compatible
to make sure that only BAOAB, ABOBA, etc. can be used to solve it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure to understand, SDEProblem does not have a field problem_type.