-
-
Notifications
You must be signed in to change notification settings - Fork 259
Fix SROCK2 NoiseWrapper and non-square noise (#3188, #3170) #3468
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
Open
singhharsh1708
wants to merge
11
commits into
SciML:master
Choose a base branch
from
singhharsh1708:fix/srock2-noisewrapper-3188
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 all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
695512b
Fix SROCK2 NoiseWrapper and non-square noise (#3188, #3170)
6198009
Fixes
e005580
Fix remaining trailing spaces for runic format check
2a0bed5
Fix init_χ! to be type-correct and GPU-compatible
b705dfd
Fixes
51341d1
some fixes
0069411
Update lib/StochasticDiffEqROCK/test/test_groups.toml
singhharsh1708 87d93ce
Update lib/StochasticDiffEqROCK/test/runtests.jl
singhharsh1708 e43b736
Remove DiffEqNoiseProcess from extras/targets (transitive dep)
0f21faf
Fix derivative_discontinuity compat with registered OrdinaryDiffEqCor…
e7318b8
Revert Project.toml to upstream (Random is stdlib, no declaration nee…
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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
70 changes: 70 additions & 0 deletions
70
lib/StochasticDiffEqROCK/test/convergence/nondiagonal_convergence.jl
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| using StochasticDiffEqROCK, DiffEqDevTools, DiffEqNoiseProcess, Test, Random | ||
|
|
||
| # Non-diagonal SDE: 2-component system driven by 1 Brownian motion (n=2, m=1) | ||
| # du_i = μ u_i dt + σ u_i dW (same scalar Brownian motion for both components) | ||
| # Weak solution: E[u_i(T)] = u_i(0) exp(μ T) | ||
|
|
||
| const μ_test = -0.5 | ||
| const σ_test = 0.1 | ||
|
|
||
| f_nd_oop(u, p, t) = μ_test .* u | ||
| g_nd_oop(u, p, t) = σ_test .* reshape(u, length(u), 1) | ||
|
|
||
| f_nd_iip!(du, u, p, t) = (du .= μ_test .* u) | ||
| function g_nd_iip!(du, u, p, t) | ||
| for i in axes(du, 1) | ||
| du[i, 1] = σ_test * u[i] | ||
| end | ||
| end | ||
|
|
||
| # Analytic (Itô): u_i(t) = u_i(0) exp((μ - σ²/2)t + σ W(t)) | ||
| analytic_nd(u0, p, t, W) = u0 .* exp.((μ_test - σ_test^2 / 2) * t .+ σ_test .* W[1]) | ||
|
|
||
| u0 = [1.0, 1.0] | ||
| tspan = (0.0, 1.0) | ||
|
|
||
| prob_oop = SDEProblem( | ||
| SDEFunction(f_nd_oop, g_nd_oop; analytic = analytic_nd), | ||
| u0, tspan; | ||
| noise_rate_prototype = zeros(2, 1) | ||
| ) | ||
| prob_iip = SDEProblem( | ||
| SDEFunction(f_nd_iip!, g_nd_iip!; analytic = analytic_nd), | ||
| u0, tspan; | ||
| noise_rate_prototype = zeros(2, 1) | ||
| ) | ||
|
|
||
| Random.seed!(100) | ||
| dts = 1 .// 2 .^ (6:-1:2) | ||
|
|
||
| @testset "SROCK2 non-diagonal OOP weak convergence (order ~2)" begin | ||
| sim = test_convergence(dts, prob_oop, SROCK2(), trajectories = Int(5e4), | ||
| save_everystep = false, weak_timeseries_errors = false) | ||
| @test abs(sim.𝒪est[:weak_final] - 2.0) < 0.5 | ||
| end | ||
|
|
||
| @testset "SROCK2 non-diagonal IIP weak convergence (order ~2)" begin | ||
| sim = test_convergence(dts, prob_iip, SROCK2(), trajectories = Int(5e4), | ||
| save_everystep = false, weak_timeseries_errors = false) | ||
| @test abs(sim.𝒪est[:weak_final] - 2.0) < 0.5 | ||
| end | ||
|
|
||
| # KomBurSROCK2 smoke test: non-diagonal noise must not crash with DimensionMismatch | ||
| @testset "KomBurSROCK2 non-diagonal IIP does not crash" begin | ||
| prob_smoke = SDEProblem(f_nd_iip!, g_nd_iip!, u0, tspan; | ||
| noise_rate_prototype = zeros(2, 1)) | ||
| sol = solve(prob_smoke, KomBurSROCK2(), dt = 0.01) | ||
| @test sol.retcode == ReturnCode.Success | ||
| end | ||
|
|
||
| # Smoke test: NoiseWrapper must not crash | ||
| @testset "SROCK2 NoiseWrapper does not crash" begin | ||
| prob_base = SDEProblem(f_nd_iip!, g_nd_iip!, u0, tspan; | ||
| noise_rate_prototype = zeros(2, 1)) | ||
| sol_base = solve(prob_base, SROCK2(), dt = 0.01, save_noise = true) | ||
| W_wrap = NoiseWrapper(sol_base.W) | ||
| prob_wrap = SDEProblem(f_nd_iip!, g_nd_iip!, u0, tspan; | ||
| noise = W_wrap, noise_rate_prototype = zeros(2, 1)) | ||
| sol_wrap = solve(prob_wrap, SROCK2(), dt = 0.01) | ||
| @test sol_wrap.retcode == ReturnCode.Success | ||
| end |
This file contains hidden or 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
Oops, something went wrong.
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.
why is this removed?