-
-
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
Spatial constant rate jump #343
base: master
Are you sure you want to change the base?
Conversation
Just use ConstantRateJump with `rate(u,p,t,site)`.
Conflicts: src/spatial/reaction_rates.jl test/spatial/reaction_rates.jl
Pull Request Test Coverage Report for Build 6180688297
💛 - Coveralls |
…to spatial-constant-rate-jump-2
…to spatial-constant-rate-jump-2
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.
Instead of passing the site into the affect
and rate
functions, we could store it in the aggregator and make an interface for users to access it via the integrator (which stores the aggregator). Something like get_current_site(integrator)
. Then this would work with old-style constant rate jump signatures. I don't know if we want that though.
The other big issue is I think there are going to be type stability issues without using FunctionWrappers on the rate and affect functions (since each function is its own type, every crj will be a different type).
@@ -39,6 +39,9 @@ function DirectCRDirectJumpAggregation(nj::SpatialJump{J}, njt::T, et::T, rx_rat | |||
|
|||
# a dependency graph is needed | |||
if dep_graph === nothing | |||
if length(rx_rates.cr_jumps) != 0 |
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.
if length(rx_rates.cr_jumps) != 0 | |
if !isempty(rx_rates.cr_jumps) |
@@ -54,6 +57,9 @@ function DirectCRDirectJumpAggregation(nj::SpatialJump{J}, njt::T, et::T, rx_rat | |||
end | |||
|
|||
if jumptovars_map === nothing | |||
if length(rx_rates.cr_jumps) != 0 |
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.
if length(rx_rates.cr_jumps) != 0 | |
if !isempty(rx_rates.cr_jumps) |
@@ -32,6 +32,9 @@ function NSMJumpAggregation(nj::SpatialJump{J}, njt::T, et::T, rx_rates::RX, hop | |||
|
|||
# a dependency graph is needed | |||
if dep_graph === nothing | |||
if length(rx_rates.cr_jumps) != 0 |
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.
same as above
@@ -47,6 +50,9 @@ function NSMJumpAggregation(nj::SpatialJump{J}, njt::T, et::T, rx_rates::RX, hop | |||
end | |||
|
|||
if jumptovars_map === nothing | |||
if length(rx_rates.cr_jumps) != 0 |
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.
same as above
""" | ||
|
||
### spatial rx rates ### | ||
struct RxRates{F, M} | ||
struct RxRates{F, M, C} |
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.
For future consideration, do you know if storing the jumps in RxRates
instead of within the aggregator directly results in an extra layer of indirection when accessing them (i.e. an extra pointer call)? If so, we might want to consider moving them up a level if that shows any performance benefit.
end | ||
RxRates(num_sites::Int, ma_jumps::M) where {M<:AbstractMassActionJump} = RxRates(num_sites, ma_jumps, ConstantRateJump[]) | ||
RxRates(num_sites::Int, cr_jumps::C) where {C} = RxRates(num_sites, SpatialMassActionJump(), cr_jumps) |
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.
RxRates(num_sites::Int, cr_jumps::C) where {C} = RxRates(num_sites, SpatialMassActionJump(), cr_jumps) | |
RxRates(num_sites::Int, cr_jumps::C) where {C} = RxRates(num_sites, SpatialMassActionJump(), cr_jumps) |
I'd specify a type for C
here or not include C
at all. Generally a generic type like this would be suggested to just be dropped since it isn't being used (it may even give a warning in tests).
cr_jump = rx_rates.cr_jumps[rx - get_num_majumps(ma_jumps)] | ||
set_rx_rate_at_site!(rx_rates, site, rx, cr_jump.rate(u, integrator.p, integrator.t, site)) |
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.
This isn't type stable is it? That is why we split the ConstantRateJump rates and affects in the non-spatial solvers and wrap them inside FunctionWrapper
s.
cr_jump = rx_rates.cr_jumps[rx - get_num_majumps(rx_rates.ma_jumps)] | ||
cr_jump.affect!(integrator, site) |
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.
This isn't type stable is it? That is why we split the ConstantRateJump rates and affects in the non-spatial solvers and wrap them inside FunctionWrappers.
Add spatial constant rate jump support.
NB: I have not implemented flattening for constant rate jumps, because it's unclear how to flatten constant rate jumps.
Implementation details:
In order to use constant rate jumps, the user is expected to pass in a
JumpSet
and two dependency graphs (reaction-reaction and reaction-species). The syntax is as follows: