-
-
Notifications
You must be signed in to change notification settings - Fork 74
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
Species' order is not defined by @species #649
Comments
I have noticed that one can specify the order of species when defining the @parameters α[1:n,1:n], η[1:n]
@variables t
@species (x(t))[1:n] Note the fact that ps = [α, η] #Raises ERROR: MethodError: no method matching nameof(::Vector{Symbolics.Num})
ps = vcat([collect(z) for z in [α, η]]) #Raises ERROR: MethodError: no method matching nameof(::Vector{Symbolics.Num}) Is there a way to provide the (order of) species without providing the parameters? Or is there a way multiple parameters should be presented in order for the |
@isaacsas Is the one of us most familiar with creating The using Catalyst
rs = @reaction_network begin
@species Y(t) X(t)
p1, ∅ → X
p2, ∅ → Y
end
species(rs) returns |
Makes sense. I was just confused as I did not anticipate the order change before. For now, I just change the order of the reactions when defining the |
I agree that setting these independently would be useful. Also, I think it is a general policy of https://github.com/SciML/ModelingToolkit.jl that one should not depend on the order of variables and parameters (which then transfers to Catalyst). Generally, you should be able to use e.g |
I am not sure what you mean by this. If I have |
E.g here you can use the species to fetch what you want from e.g. a solution object:
if that make sense? |
Ah that makes sense. I did not know that you could index the solution with the species -- now I see what you mean. This is indeed another good way of doing things. I do not need to preserve the order as long as I use the index in the solution. Thanks for that insight! |
This will give you a vector of all the parameters you should be able to use with ps = vcat([vec(collect(z)) for z in [α, η]]...)
or just loop and ps_to_merge = @parameters α[1:n,1:n], η[1:n], a
ps = Num[]
for p in ps_to_merge
pv = vec(collect(p))
append!(ps, pv)
end |
This gives some examples of places where you might want to inference with stuff like problems: https://docs.sciml.ai/Catalyst/dev/catalyst_applications/simulation_structure_interfacing/ If you find any edge cases where you cannot use species, do tell us! |
@johannesnauta I'm going to close as I think we've answered your questions, but feel free to reopen if there are further problems. |
I knew there must have been a way to define the initial state |
I completely forgot probably the easiest way: reduce(vcat, vec(collect(z)) for z in [α, η]) I should have said, the call to |
See also the first tutorial's section on the repressilator, which shows how to use symbolic pairs for the parameter and initial condition maps: |
Yeah I should've used the |
You can also specify an initial condition / parameter value vector/matrix using default values in using Catalyst
n = 2
@parameters α[1:n,1:n]=rand(n,n) η[1:n]=rand(n)
@variables t
@species (x(t))[1:n]=rand(n)
@named rx = ReactionSystem(Reaction[], t, collect(x), vcat(vec(collect(α)), collect(η))) giving
|
That might also be useful, at least for the species (in my case). Thanks for all the help! |
I encountered a problem where the order of species is not defined by
@species
. This lead to problem when creating/defining theODEProblem
, as I expected the order of the initial state to follow the order as in@species
. More specifically, consider the following example with 2 species:Note the symbolic definition as the systems I am working with are in general of some length
n
. In the example, I create the growth/replication reactions with some rateα
. When creating theODEProblem
from the reaction you need to provide initial conditionsu0
, but these of course depend on the actual order ofspecies(rs)
. As I expected the species to be ordered as[x(t)[1], x(t)[2]]
the solutions to the system of ODEs was nonsensical.Is this behavior intended? Is there a way to pre-define the order of the species using
@species x[1:n]
(or something similar)?The text was updated successfully, but these errors were encountered: