-
-
Notifications
You must be signed in to change notification settings - Fork 209
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: detect observed variables and dependent parameters dependent on discrete parameters #3106
base: master
Are you sure you want to change the base?
fix: detect observed variables and dependent parameters dependent on discrete parameters #3106
Conversation
tests fail |
It's 1.11 + #3094 causing the failures. Though the docstring error is something I haven't been able to reproduce on 1.11 either, that's just the only thing that changed between CI runs |
@testset "Observed variables dependent on discrete parameters" begin | ||
@variables x(t) obs(t) | ||
@parameters c(t) | ||
@mtkbuild sys = ODESystem( | ||
[D(x) ~ c * cos(x), obs ~ c], t, [x], [c]; discrete_events = [1.0 => [c ~ c + 1]]) | ||
prob = ODEProblem(sys, [x => 0.0], (0.0, 2pi), [c => 1.0]) | ||
sol = solve(prob, Tsit5()) | ||
@test sol[obs] ≈ 1:7 | ||
end |
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 think this MWE I provided in the issue is not a sufficient testcase. I'd propose the following
@variables x1(t)=0 x2(t)=0 obs1(t) obs2(t)
@parameters c1(t)=1 c2=1
@mtkbuild sys = ODESystem(
[D(x1) ~ c1,
D(x2) ~ c2,
obs1 ~ x1*c1,
obs2 ~ x2*c2], t; discrete_events = [[1.0] => [c1 ~ 0, c2 ~ 0]])
prob = ODEProblem(sys, [x1=>0, x2=>0], (0.0, 2))
sol = solve(prob, Tsit5())
# tests that should pass (?)
@test sol([0,2], idxs=c1) == [1.0, 0.0]
@test sol([0,0.9,1.1,2], idxs=obs1) ≈ [0, 0.9, 0, 0]
@test sol[obs1] == sol(sol.t, idxs=obs1) # errors because of mixed timeseries
# the following tests check an observable which depends on a parameter which is not declared time dependent, which is done in the docs on discrete events
# i don't know how this should be handled. Personally, as a user i'd expect all parameters to be discrete timeseries implicitly
# Depending on your API design, those failures might be by design and don't need fixing.
@test sol([0,2], idxs=c2) == [1.0, 0.0]
@test sol([0,0.9,1.1,2], idxs=obs2) ≈ [0, 0.9, 0, 0]
@test sol[obs2] == sol(sol.t, idxs=obs2)
Rebase this for LTS tests? |
I'll quote something I wrote earlier so that everyone tracking this PR is aware of the state of our discrete variable support:
Also worth noting is @hexaeder's example in #3106 (comment). |
4a67046
to
0c015c9
Compare
1fdb294
to
a126bf9
Compare
Close SciML/SciMLBase.jl#786
Checklist
contributor guidelines, in particular the SciML Style Guide and
COLPRAC.
Additional context
Add any other context about the problem here.