-
-
Notifications
You must be signed in to change notification settings - Fork 76
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 modelling integration planning #659
Comments
@TorkelE, I will describe what kind of input is expected for spatial solvers in JumpProcesses.
where
If a I will now describe how to build a
Let's focus on the most general case when all reaction rates vary in space so that we use Also, let's not focus too much on keeping allocations low. Let's just get something working first and then iterate to make it better. Feel free to continue this thread if anything is unclear! Tagging @isaacsas for visibility. |
Potential roadmap:
The constant and variable rate jumps will require changes in |
So, for a starter what I think we need to do is to create a dispatch for when you call JumpProblem(lrs::LatticeReactionSystem, prob::DiscreteProblem, alg) so that the
is made. If possible, the As long as we decide how we want parameters to be given when creating For now, would it be ok to limit ourselves to |
If it helps, we can only work with graphs for now and extend to Cartesian grids later. Graphs are more general but use more memory. Do you want any help with this? I'm not familiar with the internals of catalyst though. |
Good point, yes, let's start with graphs and take it from there. |
I was going to make a connection from Catalyst to LatticeReactionSystem's to JumpProblem, for spatial simulations, I think I should be able to do that and we can move from there. I think right now the most important point is opinions really, what kind of inputs should we allow and not, and then I know what to limit myself to. However, we probably need Sam's opinion here as well. @isaacsas you are busy right now though? |
Hi both, feel free to go ahead without me. I'll take a look and give feedback next week or when you open a PR. I unfortunately don't have time at the moment. |
I've done another revamp of the SPatial ODE code, started on building a link from Lattice Reaction NEtworks to the spatial Jump stuff. Would it make sense to have the Currently if you have a diffusion reaction of species |
Relating this last issue, I don't think solving it is urgent, but something we could have a think about. |
Also, am I correct in that for spatial JumpProcesses, rather than having the hopping constants/diffusion rates (whatever we call them) tied to a edge (or a combination of edges and compartment), it depends on the compartment only. That is the rate to make a jump [comp_1 -> comp_2] and [comp_1 -> comp_3] are the same? This might be implicitly stated in your previous message @Vilin97 , but I was a bit unsure about the D and L notation on what index meant what) |
There are different forms of hopping constants (btw, I do not call them diffusion rate because that is kind of an established term for the constant D in the heat equation, which depends on mesh size). Let's first get rates of form The notation |
Got it, will integrate this as well. Basically:
You are probably right we use different terminology. In this case I image the spatial system to be e.g. a plant where we have a rigid grid of cells (compartments), each with a well-mixed system within it. Then, if you have undirected movement between neighbouring cells (compartment) I call that a diffusion reaction (and for something more fancy, a transportation reaction). |
Ok, that clarification is good. I will implement this and push today. |
I have added support for converting Uniform diffusion rates# Uniform diffusion.
using Catalyst, JumpProcesses, Graphs
rs = @reaction_network begin
(k1,k2), A + B <--> C
end
srs = diffusion_reactions([(:D, :A),(:D, :B)])
lattice = Graphs.grid([5,5])
lrs = LatticeReactionSystem(rs, srs, lattice)
u0 = [:A => [25; fill(0, 24)], :B => [fill(0, 24); 25], :C =>0]
tspan = (0.0, 3.0)
p = [:k1 => 6.0, :k2 => 0.05, :D => 1.0]
prob = DiscreteProblem(lrs, u0, tspan, p)
jprob = JumpProblem(lrs, prob, NSM())
sol = solve(jprob, SSAStepper()) Non-uniform diffusion rates (only diffusion up and right)using Catalyst, JumpProcesses, Graphs
rs = @reaction_network begin
(k1,k2), A + B <--> C
end
srs = diffusion_reactions([(:D, :A),(:D, :B)])
lattice = DiGraph(Graphs.grid([5,5]))
lrs = LatticeReactionSystem(rs, srs, lattice)
u0 = [:A => [25; fill(0, 24)], :B => [fill(0, 24); 25], :C =>0]
tspan = (0.0, 3.0)
D_values = [(e.dst>e.src) ? 1.0 : 0.0 for e in edges(lattice)]
p = [:k1 => 6.0, :k2 => 0.05, :D => 1.0]
prob = DiscreteProblem(lrs, u0, tspan, p)
jprob = JumpProblem(lrs, prob, NSM())
sol = solve(jprob, SSAStepper()) DetailsCurrently, I am using the same interface for defining parameters and initial conditions as for the ODE system (with these being passed into the Generally, you won't have to worry about this, I am happy to maintain the link for converting this internal format to whatever your spatial jump algorithms want in
I think this is intuitive, and also means that these cases will not appear as specific cases to the end-user. This currently works well, however, I will have to think of which cases your notation allows more compact storage. In the internal representation, things are compact, but it might be that I expand this unnecessarily when the JumpProblem is created. If this is the case, my proposal is that we have a special routine that checks when a rate is given in this form, and then uses your internal more compact representation. That way we won't have to worry about how the user inputs things. |
@Vilin97 Do you want to meet sometime Monday-Wednesday and discuss through again? Except for the slowdown for large ODEs we are mostly done. If you are happy with the current internal formats for initial conditions and parameters in the JumpProblems, then I think I can handle all conversions to them. You shouldn't need do do anything more. On the Jump side I think the biggest issues is supporting more general forms of systems (as you mentioned, e.g. mass action jumps with rates depending on the compartment and constant rate jumps). One small inconsistency we have (which need not matter, but we might wish to coordinate) is that the output solution, at each time point, is given as a nxm matrix for |
@TorkelE and I met offline today. Some notes:
|
(Simple) spatial models are currently possible. I have also created an issue for gathering future steps for improving spatial implementations at: #726. Would it make sense to close this and gather future spatial discussions there? |
Stuff from here is now intergrated to https://github.com/SciML/CatalyStuff from here is now intergrated to https://github.com/SciML/Catalyst.jl/issues/726st.jl/issues/726 |
Basically, I think there are 3 things we need to coordinate so the same stuff is used across spatial ODE/Jump simulations:
LatticeReactionNetwork
needs to be.DiffusionReaction
structure needs to be.u0
andp
to theODEProblem
s andDiscreteProblem
s.Lattice reaction system
The
LatticeReactionNetwork
I think we were happy with. It currently contains:rs
: the CatalystReactionSystem
.spatial_reactions
: A vector ofDiffusionReaction
s.lattice
: A directed graph (over which we wish to simulate the system). If an undirected graph is provided as the lattice, it is converted to a directed one (with edges in both directions).It also contains some auxiliary information (which can be derived from those above), such as the number of compartments or edges, or whenever the lattice was initially provided as a directed or undirected graph. Potentially we might want to give some additional information (such as if the lattice has a special structure, like being a grid, would this be useful for jump simulators?)
Diffusion reactions
Currently have the following fields:
rate
: aNum
. Can potentially be a number (e.g.1.0
), a single parameter (e.g.dX
), or an algebraic expression of parameters (e.g.dE*dX
).species
: The species transported in this diffusion reaction (a singleNum
).It also contains some auxiliary information (e.g. the
Symbol
representation of the transported species, since this is easier to compare to variousu0
inputs). I think the main discussion here is how to do with therate
, when to store it in what form and when to convert it into what etc.Initial condition inputs
I will start with this one since it is easier than the parameters. For each species, it can either have an initial condition that is the same across all compartments, or a vector (with one value for each compartment). Consider a system with species
[X, Y]
, and 3 lattice points. We can have the following possible types inputs:Parameter inputs
Parameters are messier for two reasons:
u
vector and can then forget about it. For parameters we must figure out what is the best ways to store the values (and potentially update them due to callbacks). We might want to consider several storage alternatives as well (could have different for ODEs and Jumps). However, storage is internal, so less important now.Currently, parameters can either be given as a single vector:
or as a as a tuple, containing the compartment and edge parameters separately:
let us consider our previous system (
X
andY
spread across 3 compartments). If the compartments are on a line (with connections between the first and second and second and third), we have two compartment parameters (A
andB
) and a single edge parameter (D
). Using the first parameter input we have the following options (for simplicity I do not split the edges into edges into two directions here):Using the second version (
p = (pC, pE)
) the advantage is that we can input values inMatrix
for as well (pC
andpE
being separate matrices). If it wasn't because of this, I'd contemplate not allowing this form (simplifies things).Next, when we consider that each edge might have different values in both directions, that adds another layer of complication
Currently, internally, everything is converted to the
p = [1.0, [10.0, 20.0, 30.0], [0.1, 0.2]] # Vector of scalars and vectors.
form (because it is the most compact, but as discussed other storage forms might be desired).On a general note, I am thinking of adding metadata to parameters whenever they a compartment or edge parameter. As default all parameters that appear in the reaction system will be compartment ones. Those only appearing in
DiffusionReactions
s, or specified as edge parameters in the reaction system, will be edge parameters.The text was updated successfully, but these errors were encountered: