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

Handle events occuring at fixed timepoints without root-finding #2227

Merged
merged 19 commits into from
Dec 11, 2023

Conversation

dweindl
Copy link
Member

@dweindl dweindl commented Dec 4, 2023

A first attempt towards #2185

For events that occur at known timepoints, we don't need sundials' root-finding. We can just stop the solver at the respective timepoints and handle the events.

Here, events are sorted such that the ne_solver events that require root-finding by the solver come first and the other ne - ne_solver events come after that. The solver only tracks ne_solver roots.

To be extended to parameterized but state-independent trigger functions at some point.

A first attempt towards AMICI-dev#2185

For events that occur at known timepoints, we don't need sundials'
root-finding. We can just stop the solver at the respective timepoints
and handle the events.

To be extended to parameterized but state-independent trigger functions.
Copy link

codecov bot commented Dec 4, 2023

Codecov Report

Merging #2227 (8a04f7f) into develop (ad8eeb9) will increase coverage by 0.15%.
The diff coverage is 88.88%.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #2227      +/-   ##
===========================================
+ Coverage    76.50%   76.66%   +0.15%     
===========================================
  Files           91       91              
  Lines        15041    15109      +68     
===========================================
+ Hits         11507    11583      +76     
+ Misses        3534     3526       -8     
Flag Coverage Δ
cpp 73.11% <81.53%> (+0.03%) ⬆️
cpp_python 37.08% <69.23%> (+0.04%) ⬆️
petab 53.74% <44.00%> (-0.06%) ⬇️
python 77.49% <100.00%> (+0.36%) ⬆️
sbmlsuite ∅ <ø> (∅)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
include/amici/forwardproblem.h 100.00% <100.00%> (ø)
include/amici/model.h 61.11% <ø> (ø)
include/amici/model_dae.h 0.00% <ø> (ø)
python/sdist/amici/de_export.py 91.88% <100.00%> (+0.12%) ⬆️
python/sdist/amici/de_model.py 93.28% <100.00%> (+0.42%) ⬆️
src/solver.cpp 76.66% <100.00%> (ø)
src/forwardproblem.cpp 91.11% <97.14%> (+0.47%) ⬆️
src/model.cpp 80.47% <90.90%> (+0.06%) ⬆️
src/exception.cpp 71.79% <0.00%> (-3.89%) ⬇️
src/solver_cvodes.cpp 70.20% <63.63%> (-0.15%) ⬇️

... and 4 files with indirect coverage changes

@dweindl dweindl marked this pull request as ready for review December 5, 2023 08:30
@dweindl dweindl requested a review from a team as a code owner December 5, 2023 08:30
@dweindl dweindl marked this pull request as draft December 5, 2023 08:43
@dweindl dweindl marked this pull request as ready for review December 5, 2023 10:43
Copy link
Member

@FFroehlich FFroehlich left a comment

Choose a reason for hiding this comment

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

👍


def triggers_at_fixed_timepoint(self) -> bool:
"""Check whether the event triggers at a (single) fixed time-point."""
t_root = sp.solve(self.get_val(), amici_time_symbol)
Copy link
Member

Choose a reason for hiding this comment

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

Does it make sense to cache the value of t_root at initialization? get_trigger_time alone computes this twice. Would also reduce some redundancy.

Copy link
Member Author

Choose a reason for hiding this comment

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

Can be done. I don't think computing it twice matters performance-wise, but the redundancy is not so nice, agreed.

if (is_next_t_too_close(t_, next_t_out)) {
// next timepoint is too close to current timepoint
// update `t_`, required by `handleDataPoint`
t_ = next_t_out;
Copy link
Member

Choose a reason for hiding this comment

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

isnt the value of t_ always overwritten by solver->writeSolution?

Copy link
Member Author

Choose a reason for hiding this comment

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

Correct. But solver->writeSolution is only called for the next timepoint once handleDataPoint finishes. By then it's fine that it gets overwritten.

Copy link
Member

Choose a reason for hiding this comment

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

That‘s not evident from the code here though

discs_.push_back(t_);

/* extract and store which events occurred */
Copy link
Member

Choose a reason for hiding this comment

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

Why was this removed?

Copy link
Member Author

Choose a reason for hiding this comment

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

I lifted that up into ForwardProblem::workForwardProblem. This is the only place where handleEvent is called with !seflag && !initial_event. We need it out there, because we need to modify roots_found_ after calling getRootInfo.

Copy link
Member Author

@dweindl dweindl Dec 7, 2023

Choose a reason for hiding this comment

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

I might change that to just directly passing the timepoint to handleDataPoint, I think that's clearer. (EDIT: oops, that belongs to #2227 (comment))

@dweindl dweindl merged commit ecbae3f into AMICI-dev:develop Dec 11, 2023
25 checks passed
@dweindl dweindl deleted the feature_2185_rootless_events branch December 11, 2023 08:47
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.

2 participants