Skip to content
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

feat: add discrete saving feature to ODESolution #645

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

AayushSabharwal
Copy link
Member

Checklist

  • Appropriate tests were added
  • Any code changes were done in a way that does not break public API
  • All documentation related to code changes were updated
  • The new code follows the
    contributor guidelines, in particular the SciML Style Guide and
    COLPRAC.
  • Any new documentation only uses public API

Additional context

Add any other context about the problem here.

return ps
end
t = A.t[tidx]
idx = searchsortedfirst(discretes.t, t)
Copy link
Contributor

Choose a reason for hiding this comment

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

searchsortedfirst returns the first index greater than or equivalent to t, that means that the case where there is an exact match t has to be handled separately, since then you should return discretes.u[idx] instead of discretes.u[idx - 1]?

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for pointing that out! I'll fix it

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed in 1533e0f

t = A.t[tidx]
idx = searchsortedfirst(discretes.t, t)
if idx == firstindex(discretes.t)
error("This should never happen: there is no discrete parameter value before the current time")
Copy link
Contributor

Choose a reason for hiding this comment

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

the same for this error, I should be able to get the value exactly at the first index.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed in 1533e0f

Copy link

codecov bot commented Mar 7, 2024

Codecov Report

Attention: Patch coverage is 0% with 116 lines in your changes missing coverage. Please review.

Project coverage is 0.00%. Comparing base (9185795) to head (ea9d214).

Files Patch % Lines
src/solutions/ode_solutions.jl 0.00% 104 Missing ⚠️
ext/SciMLBaseZygoteExt.jl 0.00% 8 Missing ⚠️
src/integrator_interface.jl 0.00% 2 Missing ⚠️
src/solutions/solution_interface.jl 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #645       +/-   ##
==========================================
- Coverage   41.53%   0.00%   -41.54%     
==========================================
  Files          55      55               
  Lines        4582    4591        +9     
==========================================
- Hits         1903       0     -1903     
- Misses       2679    4591     +1912     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@AayushSabharwal
Copy link
Member Author

Requires SciML/RecursiveArrayTools.jl#372 to merge and SciML/DiffEqBase.jl#1019 to work

ps = parameter_values(sol)
# NOTE: This is basically SII.parameter_values_at_time but that isn't public API
# and once we move interpolation to SII, there's no reason for it to be
if is_parameter_timeseries(sol) == Timeseries()
Copy link
Contributor

Choose a reason for hiding this comment

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

I had expected a function with the name is_parameter_timeseries to return a boolean, answering the question of the function name.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, it's actually a trait function necessary for dispatching which is why it returns a singleton object

Copy link
Contributor

Choose a reason for hiding this comment

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

In that case, parameter_timeseries_trait would perhaps be better?

A function starting with is but not returning a bool is very confusing

Copy link
Member Author

@AayushSabharwal AayushSabharwal May 23, 2024

Choose a reason for hiding this comment

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

Yeah that work work. I initially chose is_parameter_timeseries because we already have is_timeseries which (unfortunately) is also a trait function for the IsTimeseriesTrait, which is_parameter_timeseries also leveranges.

masked_discs = map(sol.discretes) do disc
mini = searchsortedfirst(disc.t, mint)
maxi = searchsortedlast(disc.t, maxt)
disc[mini:maxi]
Copy link
Contributor

Choose a reason for hiding this comment

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

this implementation is only correct if I is a unit range? Should the argument type of I be restricted so that this method cannot be called with, say, I = [1, 2, 4]?

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed in bb65e2d

@AayushSabharwal AayushSabharwal force-pushed the as/discrete-save branch 2 times, most recently from ab153bd to ea9d214 Compare June 4, 2024 09:25
@AayushSabharwal AayushSabharwal marked this pull request as ready for review June 17, 2024 08:50
@AayushSabharwal AayushSabharwal marked this pull request as draft June 18, 2024 05:55
@AayushSabharwal AayushSabharwal force-pushed the as/discrete-save branch 2 times, most recently from 95682ad to 1afed50 Compare July 2, 2024 07:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants