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

C++ Hybrid Solver: Events #594

Merged
merged 22 commits into from
Jan 7, 2022
Merged

C++ Hybrid Solver: Events #594

merged 22 commits into from
Jan 7, 2022

Conversation

jtcooper10
Copy link
Collaborator

@jtcooper10 jtcooper10 commented Aug 5, 2021

Adds features of SBML Event objects (and their related objects, including EventTriggers and EventAssignments) to the C++ hybrid solver, as referenced in SBML Language Specification v3.2.

Major Changes

  • Added Event, EventList, EventExecution classes to C++ back end
  • Updated Python template generation functions to define Event features in compiled simulation
  • Modified propensity evaluations to accept parameters as arrays rather than global variables
    • Replaced IPropensityFunction interface with static call to map_propensity
    • Any model with events is, by definition, treated as a variable model
  • Added test_hybrid_c_events.py for unit testing the hybrid solver's event triggers
  • Added root-finding for both Event triggers and direct reactions (only when Events are found)

Closes #628

- Added `Event` class
- Added basic macros for event parameters and their associated static methods
In order to accommodate for SBML features, parameters must be vectorized instead of global variables.
- Added `get_parameters` and `get_constants` template functions
  - Heap-allocates data for each type of variable
- Replaced all references in C++ solver to parameters with vectorized equivalents
- Replaced call to `sanitized_parameter_names` with manual sanitization in Python model
  - Instead of `P0, P1, etc` parameters are `P[0], P[1], etc` for variables and `C[0], C[1], etc` for constants
- Modified rate rules to accept vectorized parameters
- Removed `IPropensityFunction` and replaced with static `propensity` method
  - Static member of the `Reaction` class
- Added `execute` member methods to assign variables to state vecs
- Added `use_state` member method to save the current state for later execution
- Implemented rule of 5 for `Event` class
- Implemented template injection functions
  - Added new implementation of `use_events`, no longer uses lambdas
  - Added new `assign` static method to dispatch event assignments
- Added `species_id` and `param_id` dicts to `SanitizedModel` class
  - Maps un-sanitized species/parameter names to their IDs
- Modified `TauHybridCSolver` options to provide definitions
  - Defs for: events, # of events, assignments, # of event assignments
- Modified `TauHybridCSolver` template option generation to use a globally unique assignment ID
- Added a (currently useless) call to `use_events` just to test
- Updated template to determine `use_trigger_state` and `persistent` flags
- Updated event eval functions (`trigger`, `delay`, `priority`) to support expressions
- Added `EventExecution` object to represent execution state of event
  - Call `Even#get_execution` to use, saves state automatically
- Added `execution_time` property to execution state
- Moved persistent state from `Event` to `EventExecution`
- Removed `Event` as "unsupported SBML feature" in Python solver
Still missing trigger state memory (currently executes constantly)
- Added events vector to solver function signature
- Added priority queues to Hybrid solver iteration
- Added comparison operators to `EventExecution` object
- Moved `priority` method from `Event` to `EventExecution`
- Added copy of assignments list on copy/move constructors
- Fixed sizing issue for event template
- Fixed off-by-1 error when generating assignment IDs in Python
- Added `is_persistent()` method to `Event` class
- Added `volatile_queue` list for events that need to be re-checked
  continuously
- Added methods to `Integrator` class to enable root-finding
- Modified trigger pipeline to fire detected events without using trigger calls directly
Base automatically changed from feature/cpp-hybrid-rate-rules to develop September 23, 2021 16:21
All triggers are evaluated at the end of every iteration. No root-finding is performed.
- Removed calls to `use_events()` in integrator.cpp
- Added `trigger_state` to track transition state of each trigger
@briandrawert briandrawert added this to the 1.6.5 milestone Oct 21, 2021
@briandrawert briandrawert linked an issue Oct 21, 2021 that may be closed by this pull request
@briandrawert briandrawert modified the milestones: 1.6.5, 1.6.6 Oct 21, 2021
jtcooper10 and others added 7 commits November 3, 2021 23:40
Goal is to use new layout where root-finder can search for both events and reactions.
- Added `Integrator#use_events` and `Integrator#use_reactions`
- Updated `Integrator#integrate` to use new layout
- Added "trigger pool" data set to track event trigger state
- Added "roots found" return parameters to `integrate()` method
Parameter bug was caused by parameters never been templated as variable (always constants).
- Fixed bug where parameter assignments are ignored
  - Added `variable` member to `SanitizedModel`
  - Removed `variable` param from `SanitizedModel#get_template`, instead pulls from `self`
- Updated docstrings in new integrator methods
- Updated root-finder return to apply direct reactions
- Fixed parameter overrides not applying
  - Added array to track which parameters have overrides
- Added comprehensive test cases for event features
- Fixed non-persistent triggers by reordering volatile trigger checks
- Fixed delay time checks
- Fixed calls to `memcpy` in `EventExecution`'s copy constructor
- Added `initial_value` handling to template gen
- Added initial value as macro parameter for `EVENT`
Comp
- Moved event execution code to separate `EventList` class
  - Contains exact same code, just abstracted away
- Added check to trigger state at beginning of trajectory
  - Moved first trajectory value to be after events have been processed
@jtcooper10 jtcooper10 marked this pull request as ready for review November 20, 2021 04:52
@jtcooper10 jtcooper10 added the enhancement New feature or request label Nov 20, 2021
@briandrawert briandrawert modified the milestones: 1.6.6, 1.6.7 Dec 2, 2021
- Bug occurred when stochastic event fired
  - Root-finder list was never cleared
  - Errant `continue` skipped over state update code
- Bug occurred when array is not zero-initialized
  - Caused compiler-specific bug where stochastic events were impossible to find
@briandrawert briandrawert merged commit 6249b32 into develop Jan 7, 2022
@briandrawert briandrawert deleted the feature/cpp-hybrid-events branch January 7, 2022 20:40
@seanebum seanebum mentioned this pull request Jan 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Events in the C++ hybrid solver
4 participants