Skip to content

Commit 63f5228

Browse files
committed
ups
1 parent 37215a9 commit 63f5228

File tree

4 files changed

+39
-12
lines changed

4 files changed

+39
-12
lines changed

src/reactionsystem.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,11 @@ struct ReactionSystem{V <: NetworkProperties} <:
546546
name, systems, defaults, connection_type, nps, cls, cevs, devs,
547547
metadata = nothing, complete = false; checks::Bool = true)
548548

549+
# Checks that all parameters have the appropriate Symbolics type.
550+
for p in ps
551+
(p isa Symbolics.BasicSymbolic) || error("Parameter $p is not a `BasicSymbolic`. This is required.")
552+
end
553+
549554
# unit checks are for ODEs and Reactions only currently
550555
nonrx_eqs = Equation[eq for eq in eqs if eq isa Equation]
551556
if checks && isempty(sivs)

src/spatial_reaction_systems/spatial_reactions.jl

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,29 +92,38 @@ function check_spatial_reaction_validity(rs::ReactionSystem, tr::TransportReacti
9292
end
9393

9494
# Checks that the species does not exist in the system with different metadata.
95-
if any([isequal(tr.species, s) && !isequivalent(tr.species, s) for s in species(rs)])
95+
if any(isequal(tr.species, s) && !isequivalent(tr.species, s) for s in species(rs))
9696
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 used in transport reaction creation.")
9797
end
98-
if any([isequal(rs_p, tr_p) && !isequivalent(rs_p, tr_p)
99-
for rs_p in parameters(rs), tr_p in Symbolics.get_variables(tr.rate)])
98+
if any(isequal(rs_p, tr_p) && !isequivalent(rs_p, tr_p)
99+
for rs_p in parameters(rs), tr_p in Symbolics.get_variables(tr.rate))
100100
error("A transport reaction used a parameter with metadata not matching its lattice reaction system. Please fetch this parameter from the reaction system and used in transport reaction creation.")
101101
end
102102

103103
# Checks that no edge parameter occur among rates of non-spatial reactions.
104-
if any([!isempty(intersect(Symbolics.get_variables(r.rate), edge_parameters)) for r in reactions(rs)])
104+
if any(!isempty(intersect(Symbolics.get_variables(r.rate), edge_parameters)) for r in reactions(rs))
105105
error("Edge paramter(s) were found as a rate of a non-spatial reaction.")
106106
end
107107
end
108108

109109
# Since MTK's "isequal" ignores metadata, we have to use a special function that accounts for this.
110110
# This is important because whether something is an edge parameter is defined in metadata.
111+
const ep_metadata = [Catalyst.EdgeParameter => true]
111112
function isequivalent(sym1, sym2)
112113
isequal(sym1, sym2) || (return false)
113-
(ignore_ep_metadata(sym1.metadata) != ignore_ep_metadata(sym2.metadata)) && (return false)
114+
in_skip_ep_metadata(md1, md2) || (return false)
115+
in_skip_ep_metadata(md2, md1) || (return false)
114116
(typeof(sym1) != typeof(sym2)) && (return false)
115117
return true
116118
end
117-
ignore_ep_metadata(metadata) = setdiff(metadata, [Catalyst.EdgeParameter => true])
119+
# Checks if metadata 1 is in metadata 2 (but always return true if md1 is the edge parameter metadata.
120+
function in_skip_ep_metadata(md1, md2)
121+
(md1 == ep_metadata) && (return true)
122+
for md1 in sym1.metadata
123+
(md1 in md2) || return false
124+
end
125+
return true
126+
end
118127

119128
# Implements custom `==`.
120129
"""

test/dsl/dsl_options.jl

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,7 @@ end
347347

348348
# Tests that parameter type designation works.
349349
let
350+
# Creates a model.
350351
rn = @reaction_network begin
351352
@parameters begin
352353
k1
@@ -366,7 +367,8 @@ let
366367
(k4,l4), X4 <--> Y4
367368
(k5,l5), X5 <--> Y5
368369
end
369-
370+
371+
# Checks parameter types.
370372
@test unwrap(rn.k1) isa SymbolicUtils.BasicSymbolic{Real}
371373
@test unwrap(rn.l1) isa SymbolicUtils.BasicSymbolic{Real}
372374
@test unwrap(rn.k2) isa SymbolicUtils.BasicSymbolic{Float64}
@@ -377,6 +379,14 @@ let
377379
@test unwrap(rn.l4) isa SymbolicUtils.BasicSymbolic{Float32}
378380
@test unwrap(rn.k5) isa SymbolicUtils.BasicSymbolic{Rational{Int64}}
379381
@test unwrap(rn.l5) isa SymbolicUtils.BasicSymbolic{Rational{Int64}}
382+
383+
# Checks that other parameter properties are assigned properly.
384+
@test !ModelingToolkit.hasdefault(unwrap(rn.k1))
385+
@test ModelingToolkit.getdefault(unwrap(rn.k2)) == 2.0
386+
@test ModelingToolkit.getdefault(unwrap(rn.k3)) == 2
387+
@test ModelingToolkit.getdescription(unwrap(rn.k3)) == "A parameter"
388+
@test ModelingToolkit.getdescription(unwrap(rn.k4)) == "Another parameter"
389+
@test !ModelingToolkit.hasdescription(unwrap(rn.k5))
380390
end
381391

382392
### Observables ###

test/miscellaneous_tests/symbolic_stoichiometry.jl

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ include("../test_functions.jl")
1919

2020
# Checks that systems with symbolic stoichiometries, created using different approaches, are identical.
2121
let
22-
@parameters p k d n1 n2 n3
22+
@parameters p k d::Float64 n1::Int64 n2 n3
2323
@species X(t) Y(t)
2424
rxs1 = [
2525
Reaction(p, nothing, [X], nothing, [n1])
@@ -29,13 +29,14 @@ let
2929
rs1 = ReactionSystem(rxs1, t; name = :rs)
3030

3131
rxs2 = [
32-
@reaction p, 0 --> n1*X
32+
@reaction p, 0 --> $n1*X
3333
@reaction k, n2*X --> n3*Y
34-
@reaction d, Y --> 0
34+
@reaction $d, Y --> 0
3535
]
3636
rs2 = ReactionSystem(rxs2, t; name = :rs)
3737

3838
rs3 = @reaction_network rs begin
39+
@parameters d::Float64 n1::Int64
3940
p, 0 --> n1*X
4041
k, n2*X --> n3*Y
4142
d, Y --> 0
@@ -44,15 +45,17 @@ let
4445
@test rs1 == rs2 == rs3
4546
@test issetequal(unknowns(rs1), [X, Y])
4647
@test issetequal(parameters(rs1), [p, k, d, n1, n2, n3])
48+
@test unwrap(d) isa SymbolicUtils.BasicSymbolic{Float64}
49+
@test unwrap(n1) isa SymbolicUtils.BasicSymbolic{Int64}
4750
end
4851

4952
# Declares a network, parameter values, and initial conditions, to be used for the next couple of tests.
5053
begin
5154
# Prepares parameters and species and their values.
5255
@parameters k α::Int64
5356
@species A(t), B(t), C(t), D(t)
54-
u0_1 = [A => 3.0, B => 2.0, C => 3.0, D => 5.0]
55-
ps_1 = [k => 5.0, α => 2.0]
57+
u0_1 = (A => 3.0, B => 2.0, C => 3.0, D => 5.0)
58+
ps_1 = (k => 5.0, α => 2)
5659
u0_2 = [Int64(u[2]) for u in u0_1]
5760
ps_2 = [Int64(p[2]) for p in ps_1]
5861
τ = 1.5

0 commit comments

Comments
 (0)