Skip to content

Commit ea38a83

Browse files
committed
spatial reactions fix
1 parent bb374d7 commit ea38a83

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

Diff for: src/spatial_reaction_systems/spatial_reactions.jl

+11-7
Original file line numberDiff line numberDiff line change
@@ -103,28 +103,32 @@ function check_spatial_reaction_validity(rs::ReactionSystem, tr::TransportReacti
103103
if any(isequal(tr.species, s) && !isequivalent(tr.species, s) for s in species(rs))
104104
error("A transport reaction used a species, $(tr.species), with metadata not matching its lattice reaction system. Please fetch this species from the reaction system and use it during transport reaction creation.")
105105
end
106-
# No `for` loop, just weird formatting by the formatter.
107106
if any(isequal(rs_p, tr_p) && !isequivalent(rs_p, tr_p)
108-
for rs_p in parameters(rs), tr_p in Symbolics.get_variables(tr.rate))
107+
for rs_p in parameters(rs), tr_p in Symbolics.get_variables(tr.rate))
109108
error("A transport reaction used a parameter with metadata not matching its lattice reaction system. Please fetch this parameter from the reaction system and use it during transport reaction creation.")
110109
end
111110

112111
# Checks that no edge parameter occurs among rates of non-spatial reactions.
113-
# No `for` loop, just weird formatting by the formatter.
114112
if any(!isempty(intersect(Symbolics.get_variables(r.rate), edge_parameters))
115-
for r in reactions(rs))
113+
for r in reactions(rs))
116114
error("Edge parameter(s) were found as a rate of a non-spatial reaction.")
117115
end
118116
end
119117

120118
# Since MTK's "isequal" ignores metadata, we have to use a special function that accounts for this.
121119
# This is important because whether something is an edge parameter is defined in metadata.
120+
# MTK potentially start adding there own metadata to system symbolic variables, to prevent breakage
121+
# for this we now also have al list of `ignored_metadata` (which MTK will add to `ReactionSystem`)
122+
# metadata. Long-term the solution is to permit the creation of spatial reactions within
123+
# a `ReactionSystem` when it is created.
122124
const ep_metadata = Catalyst.EdgeParameter => true
123-
function isequivalent(sym1, sym2)
125+
function isequivalent(sym1, sym2; ignored_metadata = [MT.SymScope])
124126
isequal(sym1, sym2) || (return false)
125-
if any((md1 != ep_metadata) && !(md1 in sym2.metadata) for md1 in sym1.metadata)
127+
if any((md1 != ep_metadata) && (md1[1] ignored_metadata) && (md1 sym2.metadata)
128+
for md1 in sym1.metadata)
126129
return false
127-
elseif any((md2 != ep_metadata) && !(md2 in sym1.metadata) for md2 in sym2.metadata)
130+
elseif any((md2 != ep_metadata) && (md2[1] ignored_metadata) && (md2 sym1.metadata)
131+
for md2 in sym2.metadata)
128132
return false
129133
elseif typeof(sym1) != typeof(sym2)
130134
return false

0 commit comments

Comments
 (0)