I am trying to optimise Catalyst
code by omitting many reactions as their rates will, eventually, be put to zero. Briefly, I am considering systems of which many possible reactions will have a rate of 0. To avoid creating these reactions and thereby including (potentially many) reactions/terms that do not change the system dynamics, I check if their numerical value is non-zero and only create the Reaction
if it is.
However, when inserting the parameter values when creating the ODEProblem
from the ReactionSystem
, I now have the issue that the variables are “hard-coded”. This is because, in general, one does not know beforehand (as in, when writing the function) what rates will be 0. As a result, the main issue is that I would like to @unpack
the symbols, but that the symbols now do not exist as they will have a rate of 0 and are thus left out.
To illustrate this, consider a super simple system with (logarithmic) growth and death, i.e.
where \eta and \mu the growth and death rate. Now let us say that the death rate is 0, and thus the reaction x \rightarrow_\mu 0 is left out. However, when I now do
julia> @unpack η, μ = reaction_system
ERROR: ArgumentError: System reaction_system: variable ÎĽ does not exist
I obviously get the error that the variable ÎĽ
does not exist; as expected. However, is it possible to “conditionally” @unpack
, only if the variable exists? As in, can I create a macro/function to do something like:
julia> @unpack_ifexists η, μ = reaction_system; η
η
I know that the @unpack
macro can be customized, but I could not find a customization that only unpacks when the variable actually exists.
If I could, then I can write a very general function that, depending on if variables exist in the ReactionSystem
or not, assigns them a (non-zero) value when defining the ODEProblem
.
I hope my problem and question are clear.