-
-
Notifications
You must be signed in to change notification settings - Fork 35
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
Fix saveat plotting #430
Merged
Merged
Fix saveat plotting #430
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e406f25
dispatch isdenseplot to make linear plots when not saving every step
isaacsas c147b40
format
isaacsas d4f3317
add tests
isaacsas cbb6452
format
isaacsas 85c89e9
a few more tests
isaacsas 9902ecc
Update Project.toml
ChrisRackauckas 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,59 @@ | ||
using JumpProcesses, OrdinaryDiffEq, Test | ||
using JumpProcesses, OrdinaryDiffEq, Test, SciMLBase | ||
using StableRNGs | ||
rng = StableRNG(12345) | ||
|
||
# test that we only save when a jump occurs | ||
for alg in (Coevolve(),) | ||
u0 = [0] | ||
tspan = (0.0, 30.0) | ||
let | ||
for alg in (Coevolve(),) | ||
u0 = [0] | ||
tspan = (0.0, 30.0) | ||
|
||
dprob = DiscreteProblem(u0, tspan) | ||
# set the rate to 0, so that no jump ever occurs; but urate is positive so | ||
# Coevolve will consider many candidates before the end of the simmulation. | ||
# None of these points should be saved. | ||
jump = VariableRateJump((u, p, t) -> 0, (integrator) -> integrator.u[1] += 1; | ||
urate = (u, p, t) -> 1.0, rateinterval = (u, p, t) -> 5.0) | ||
jumpproblem = JumpProblem(dprob, alg, jump; dep_graph = [[1]], | ||
save_positions = (false, true)) | ||
sol = solve(jumpproblem, SSAStepper()) | ||
@test sol.t == [0.0, 30.0] | ||
dprob = DiscreteProblem(u0, tspan) | ||
# set the rate to 0, so that no jump ever occurs; but urate is positive so | ||
# Coevolve will consider many candidates before the end of the simmulation. | ||
# None of these points should be saved. | ||
jump = VariableRateJump((u, p, t) -> 0, (integrator) -> integrator.u[1] += 1; | ||
urate = (u, p, t) -> 1.0, rateinterval = (u, p, t) -> 5.0) | ||
jumpproblem = JumpProblem(dprob, alg, jump; dep_graph = [[1]], | ||
save_positions = (false, true), rng) | ||
sol = solve(jumpproblem, SSAStepper()) | ||
@test sol.t == [0.0, 30.0] | ||
|
||
oprob = ODEProblem((du, u, p, t) -> 0, u0, tspan) | ||
jump = VariableRateJump((u, p, t) -> 0, (integrator) -> integrator.u[1] += 1; | ||
urate = (u, p, t) -> 1.0, rateinterval = (u, p, t) -> 5.0) | ||
jumpproblem = JumpProblem(oprob, alg, jump; dep_graph = [[1]], | ||
save_positions = (false, true)) | ||
sol = solve(jumpproblem, Tsit5(); save_everystep = false) | ||
@test sol.t == [0.0, 30.0] | ||
oprob = ODEProblem((du, u, p, t) -> 0, u0, tspan) | ||
jump = VariableRateJump((u, p, t) -> 0, (integrator) -> integrator.u[1] += 1; | ||
urate = (u, p, t) -> 1.0, rateinterval = (u, p, t) -> 5.0) | ||
jumpproblem = JumpProblem(oprob, alg, jump; dep_graph = [[1]], | ||
save_positions = (false, true), rng) | ||
sol = solve(jumpproblem, Tsit5(); save_everystep = false) | ||
@test sol.t == [0.0, 30.0] | ||
end | ||
end | ||
|
||
# test isdenseplot gives correct values for SSAStepper and non-SSAStepper models | ||
let | ||
rate(u, p, t) = max(u[1],0.0) | ||
affect!(integ) = (integ.u[1] -= 1; nothing) | ||
crj = ConstantRateJump(rate, affect!) | ||
u0 = [10.0] | ||
tspan = (0.0, 10.0) | ||
dprob = DiscreteProblem(u0, tspan) | ||
sps = ((true, true), (true, false), (false, true), (false, false)) | ||
|
||
# for pure jump problems dense = save_everystep | ||
vals = (true, true, true, false) | ||
for (sp,val) in zip(sps, vals) | ||
jprob = JumpProblem(dprob, Direct(), crj; save_positions = sp, rng) | ||
sol = solve(jprob, SSAStepper()) | ||
@test SciMLBase.isdenseplot(sol) == val | ||
end | ||
|
||
# for mixed problems sol.dense currently ignores save_positions | ||
oprob = ODEProblem((du,u,p,t) -> du[1] = .1, u0, tspan) | ||
for sp in sps | ||
jprob = JumpProblem(oprob, Direct(), crj; save_positions = sp, rng) | ||
sol = solve(jprob, Tsit5()) | ||
@test sol.dense == true | ||
@test SciMLBase.isdenseplot(sol) == true | ||
end | ||
|
||
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.
Currently with PDMPs or jump-diffusions
sol.dense == true
always, irregardless ofsave_positions
. I'm not sure if this should be considered an issue or not.