Skip to content

Commit 45ad1d8

Browse files
committed
updates test
1 parent 68c22c1 commit 45ad1d8

File tree

13 files changed

+148
-146
lines changed

13 files changed

+148
-146
lines changed

src/expression_utils.jl

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -94,18 +94,6 @@ function is_escaped_expr(expr)
9494
end
9595

9696

97-
### Generic Expression Handling ###
98-
99-
# Convert an expression that is a vector with symbols that have values assigned using `=`
100-
# (e.g. :([a=1.0, b=2.0])) to a vector where the assignment instead uses symbols and pairs
101-
# (e.g. :([a=>1.0, b=>2.0])). Used to e.g. convert default reaction metadata to a form that can be
102-
# evaluated as actual code.
103-
function expr_equal_vector_to_pairs(expr_vec)
104-
pair_vector = :([])
105-
foreach(arg -> push!(pair_vector.args, arg.args[1] => arg.args[2]), expr_vec.args)
106-
return pair_vector
107-
end
108-
10997
### Old Stuff ###
11098

11199
#This will be called whenever a function stored in funcdict is called.

src/reaction_network.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,6 @@ function make_reaction_system(ex::Expr; name = :(gensym(:ReactionSystem)))
360360
check_default_noise_scaling!(default_reaction_metadata, options)
361361
compound_expr, compound_species = read_compound_options(options)
362362
check_default_noise_scaling!(default_reaction_metadata, options)
363-
default_reaction_metadata = expr_equal_vector_to_pairs(default_reaction_metadata)
364363

365364
# Parses reactions, species, and parameters.
366365
reactions = get_reactions(reaction_lines)
@@ -806,7 +805,7 @@ function check_default_noise_scaling!(default_reaction_metadata, options)
806805
if (length(options[:default_noise_scaling].args) != 3) # Becasue of how expressions are, 3 is used.
807806
error("@default_noise_scaling should only have a single input, this appears not to be the case: \"$(options[:default_noise_scaling])\"")
808807
end
809-
push!(default_reaction_metadata.args, :(noise_scaling=$(options[:default_noise_scaling].args[3])))
808+
push!(default_reaction_metadata.args, :(:noise_scaling => $(options[:default_noise_scaling].args[3])))
810809
end
811810
end
812811

src/reactionsystem.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1538,7 +1538,7 @@ function Base.convert(::Type{<:NonlinearSystem}, rs::ReactionSystem; name = name
15381538
kwargs...)
15391539
iscomplete(rs) || error(COMPLETENESS_ERROR)
15401540
spatial_convert_err(rs::ReactionSystem, NonlinearSystem)
1541-
fullrs = Catalyst.flatten(rs; complete = true)
1541+
fullrs = Catalyst.flatten(rs)
15421542
remove_conserved && conservationlaws(fullrs)
15431543
ists, ispcs = get_indep_sts(fullrs, remove_conserved)
15441544
eqs = assemble_drift(fullrs, ispcs; combinatoric_ratelaws, remove_conserved,
@@ -1582,7 +1582,7 @@ function Base.convert(::Type{<:SDESystem}, rs::ReactionSystem;
15821582
iscomplete(rs) || error(COMPLETENESS_ERROR)
15831583
spatial_convert_err(rs::ReactionSystem, SDESystem)
15841584

1585-
flatrs = Catalyst.flatten(rs; complete = true)
1585+
flatrs = Catalyst.flatten(rs)
15861586
error_if_constraints(SDESystem, flatrs)
15871587

15881588
remove_conserved && conservationlaws(flatrs)
@@ -1636,7 +1636,7 @@ function Base.convert(::Type{<:JumpSystem}, rs::ReactionSystem; name = nameof(rs
16361636
(remove_conserved !== nothing) &&
16371637
error("Catalyst does not support removing conserved species when converting to JumpSystems.")
16381638

1639-
flatrs = Catalyst.flatten(rs; complete = true)
1639+
flatrs = Catalyst.flatten(rs)
16401640
error_if_constraints(JumpSystem, flatrs)
16411641

16421642
(length(MT.continuous_events(flatrs)) > 0) &&
@@ -1821,7 +1821,7 @@ function MT.flatten(rs::ReactionSystem; name = nameof(rs))
18211821
balanced_bc_check = false,
18221822
spatial_ivs = get_sivs(rs),
18231823
continuous_events = MT.continuous_events(rs),
1824-
discrete_events = MT.discre)
1824+
discrete_events = MT.continuous_events(rs))
18251825
end
18261826

18271827
"""

test/dsl/custom_functions.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ let
5555
mm(X, v, K), 0 --> X2
5656
mm(X, v, K), 0 --> X3
5757
end
58-
f_mm = ODEFunction(convert(ODESystem, mm_network), jac = true)
58+
f_mm = ODEFunction(complete(convert(ODESystem, mm_network)), jac = true)
5959

6060
u0 = 10 * rand(rng, length(get_unknowns(mm_network)))
6161
p = 10 * rand(rng, length(get_ps(mm_network)))
@@ -75,7 +75,7 @@ let
7575
mmr(X, v, K), 0 --> X2
7676
mmr(X, v, K), 0 --> X3
7777
end
78-
f_mmr = ODEFunction(convert(ODESystem, mmr_network), jac = true)
78+
f_mmr = ODEFunction(complete(convert(ODESystem, mmr_network)), jac = true)
7979

8080
u0 = 10 * rand(rng, length(get_unknowns(mmr_network)))
8181
p = 10 * rand(rng, length(get_ps(mmr_network)))
@@ -94,7 +94,7 @@ let
9494
hill(X, v, K, 2), 0 --> X1
9595
hill(X, v, K, 2), 0 --> X2
9696
end
97-
f_hill = ODEFunction(convert(ODESystem, hill_network), jac = true)
97+
f_hill = ODEFunction(complete(convert(ODESystem, hill_network)), jac = true)
9898

9999
u0 = 10 * rand(rng, length(get_unknowns(hill_network)))
100100
p = 10 * rand(rng, length(get_ps(hill_network)))
@@ -113,7 +113,7 @@ let
113113
hillr(X, v, K, 2), 0 --> X1
114114
hillr(X, v, K, 2), 0 --> X2
115115
end
116-
f_hillr = ODEFunction(convert(ODESystem, hillr_network), jac = true)
116+
f_hillr = ODEFunction(complete(convert(ODESystem, hillr_network)), jac = true)
117117

118118
u0 = 10 * rand(rng, length(get_unknowns(hillr_network)))
119119
p = 10 * rand(rng, length(get_ps(hillr_network)))
@@ -134,7 +134,7 @@ let
134134
hillar(X, Y, v, K, 2), 0 --> X3
135135
hillar(X, Y, v, K, 2), 0 --> X4
136136
end
137-
f_hillar = ODEFunction(convert(ODESystem, hillar_network), jac = true)
137+
f_hillar = ODEFunction(complete(convert(ODESystem, hillar_network)), jac = true)
138138

139139
u0 = 10 * rand(rng, length(get_unknowns(hillar_network)))
140140
p = 10 * rand(rng, length(get_ps(hillar_network)))

test/dsl/dsl_basics.jl

Lines changed: 43 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -68,54 +68,53 @@ end
6868
### Test Interpolation Within the DSL ###
6969

7070
# Tests basic interpolation cases.
71-
let
72-
# Declares parameters and species used across the test.
73-
@parameters α k k1 k2
74-
@species A(t) B(t) C(t) D(t)
7571

76-
let
77-
AA = A
78-
AAA = A^2 + B
79-
rn = @reaction_network rn begin
80-
@parameters k
81-
@species A(t) B(t) C(t) D(t)
82-
k*$AAA, C --> D
83-
end
84-
rn2 = ReactionSystem([Reaction(k*AAA, [C], [D])], t; name=:rn)
85-
@test rn == rn2
72+
# Declares parameters and species used across the test.
73+
@parameters α k k1 k2
74+
@species A(t) B(t) C(t) D(t)
8675

87-
rn = @reaction_network rn begin
88-
@parameters k
89-
@species A(t) C(t) D(t)
90-
k, $AA + C --> D
91-
end
92-
rn2 = ReactionSystem([Reaction(k, [AA,C], [D])], t; name=:rn)
93-
@test rn == rn2
76+
let
77+
AA = A
78+
AAA = A^2 + B
79+
rn = @reaction_network rn begin
80+
@parameters k
81+
@species A(t) B(t) C(t) D(t)
82+
k*$AAA, C --> D
9483
end
84+
rn2 = ReactionSystem([Reaction(k*AAA, [C], [D])], t; name=:rn)
85+
@test rn == rn2
9586

96-
let
97-
BB = B; A2 = A
98-
rn = @reaction_network rn begin
99-
@parameters k1 k2
100-
(k1,k2), C + $A2 + $BB + $A2 <--> $BB + $BB
101-
end
102-
rn2 = ReactionSystem([Reaction(k1, [C, A, B], [B], [1,2,1],[2]),
103-
Reaction(k2, [B], [C, A, B], [2], [1,2,1])],
104-
t; name=:rn)
105-
@test rn == rn2
87+
rn = @reaction_network rn begin
88+
@parameters k
89+
@species A(t) C(t) D(t)
90+
k, $AA + C --> D
10691
end
92+
rn2 = ReactionSystem([Reaction(k, [AA,C], [D])], t; name=:rn)
93+
@test rn == rn2
94+
end
10795

108-
let
109-
AA = A
110-
kk1 = k^2*A
111-
kk2 = k1+k2
112-
rn = @reaction_network rn begin
113-
@parameters α k k1 k2
114-
α+$kk1*$kk2*$AA, 2*$AA + B --> $AA
115-
end
116-
rn2 = ReactionSystem([Reaction+kk1*kk2*AA, [A, B], [A], [2, 1], [1])], t; name=:rn)
117-
@test rn == rn2
96+
let
97+
BB = B; A2 = A
98+
rn = @reaction_network rn begin
99+
@parameters k1 k2
100+
(k1,k2), C + $A2 + $BB + $A2 <--> $BB + $BB
101+
end
102+
rn2 = ReactionSystem([Reaction(k1, [C, A, B], [B], [1,2,1],[2]),
103+
Reaction(k2, [B], [C, A, B], [2], [1,2,1])],
104+
t; name=:rn)
105+
@test rn == rn2
106+
end
107+
108+
let
109+
AA = A
110+
kk1 = k^2*A
111+
kk2 = k1+k2
112+
rn = @reaction_network rn begin
113+
@parameters α k k1 k2
114+
α+$kk1*$kk2*$AA, 2*$AA + B --> $AA
118115
end
116+
rn2 = ReactionSystem([Reaction+kk1*kk2*AA, [A, B], [A], [2, 1], [1])], t; name=:rn)
117+
@test rn == rn2
119118
end
120119

121120
# Miscellaneous interpolation tests. Unsure what they do here (not related to DSL).
@@ -272,6 +271,7 @@ let
272271
rx2 = Reaction(2*k, [B], [D], [1], [2.5])
273272
rx3 = Reaction(2*k, [B], [D], [2.5], [2])
274273
@named mixedsys = ReactionSystem([rx1,rx2,rx3],t,[B,C,D],[k])
274+
mixedsys = complete(mixedsys)
275275
osys = convert(ODESystem, mixedsys; combinatoric_ratelaws=false)
276276
rn = @reaction_network mixedsys begin
277277
@parameters k
@@ -313,11 +313,12 @@ let
313313
eq = D(B) ~ -B
314314
@named osys = ODESystem([eq], t)
315315
@named rn2 = extend(osys, rn2)
316+
rn2 = complete(rn2)
316317
@test issetequal(unknowns(rn2), species(rn2))
317318
@test all(isspecies, species(rn))
318319
@test Catalyst.isbc(ModelingToolkit.value(B))
319320
@test Catalyst.isbc(ModelingToolkit.value(A)) == false
320-
osys2 = convert(ODESystem, rn2)
321+
osys2 = complete(convert(ODESystem, rn2))
321322
@test issetequal(unknowns(osys2), unknowns(rn2))
322323
@test length(equations(osys2)) == 2
323324
end

test/dsl/dsl_model_construction.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ let
316316
end
317317
end
318318

319-
# CHeck that various symbols can be used as species/parameter names.
319+
# Check that various symbols can be used as species/parameter names.
320320
let
321321
@reaction_network begin
322322
(a, A), n N

test/miscellaneous_tests/api.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ let
537537
b23, F2 --> F3
538538
b31, F3 --> F1
539539
end
540-
osys = convert(ODESystem, rn; remove_conserved = true)
540+
osys = complete(convert(ODESystem, rn; remove_conserved = true))
541541
@unpack A, B, C, D, E, F1, F2, F3, k1, k2, m1, m2, b12, b23, b31 = osys
542542
u0 = [A => 10.0, B => 10.0, C => 0.0, D => 10.0, E => 0.0, F1 => 8.0, F2 => 0.0,
543543
F3 => 0.0]
@@ -556,7 +556,7 @@ let
556556
@test isapprox(sol2(tv, idxs = s), sol2(tv, idxs = s))
557557
end
558558

559-
nsys = convert(NonlinearSystem, rn; remove_conserved = true)
559+
nsys = complete(convert(NonlinearSystem, rn; remove_conserved = true))
560560
nprob = NonlinearProblem{true}(nsys, u0, p)
561561
nsol = solve(nprob, NewtonRaphson(); abstol = 1e-10)
562562
nprob2 = ODEProblem(rn, u0, (0.0, 100.0 * tspan[2]), p)
@@ -570,7 +570,7 @@ let
570570

571571
u0 = [A => 100.0, B => 20.0, C => 5.0, D => 10.0, E => 3.0, F1 => 8.0, F2 => 2.0,
572572
F3 => 20.0]
573-
ssys = convert(SDESystem, rn; remove_conserved = true)
573+
ssys = complete(convert(SDESystem, rn; remove_conserved = true))
574574
sprob = SDEProblem(ssys, u0, tspan, p)
575575
sprob2 = SDEProblem(rn, u0, tspan, p)
576576
sprob3 = SDEProblem(rn, u0, tspan, p; remove_conserved = true)

test/miscellaneous_tests/events.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,13 @@ let
1717
discrete_events = [1.0 => [V ~ 1.0]]
1818
rxs = [(@reaction $V, 0 --> A), (@reaction 1.0, A --> 0)]
1919
@named rs = ReactionSystem([rxs; eqs], t; discrete_events)
20+
rs = complete(rs)
2021
@test length(ModelingToolkit.discrete_events(rs)) == 1
2122
@test length(ModelingToolkit.continuous_events(rs)) == 0
2223

2324
# Tests in simulation.
2425
setdefaults!(rs, [:A => 0.0])
25-
osys = convert(ODESystem, rs)
26+
osys = complete(convert(ODESystem, rs))
2627
@test length(ModelingToolkit.discrete_events(osys)) == 1
2728
oprob = ODEProblem(osys, [], (0.0, 20.0))
2829
sol = solve(oprob, Tsit5())
@@ -37,6 +38,7 @@ let
3738
rxs = [Reaction(α, nothing, [V]), Reaction(β, [V], nothing)]
3839
continuous_events = [V ~ 2.5] =>~ 0, β ~ 0]
3940
@named rs = ReactionSystem(rxs, t; continuous_events)
41+
rs = complete(rs)
4042
@test length(ModelingToolkit.discrete_events(rs)) == 0
4143
@test length(ModelingToolkit.continuous_events(rs)) == 1
4244

test/model_simulation/simulate_SDEs.jl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,6 @@ let
255255
(p,d), 0 <--> X2, ([description="Y"],[description="Y"])
256256
(p,d), 0 <--> X3
257257
end
258-
noise_scaling_network = complete(noise_scaling_network)
259258

260259
u0 = [:X1 => 1000.0, :X2 => 1000.0, :X3 => 1000.0]
261260
ps = [noise_scaling_network.p => 1000.0, noise_scaling_network.d => 1.0, noise_scaling_network.η1 => 1.0]
@@ -316,8 +315,8 @@ let
316315

317316
# Checks that systems have the correct noise scaling terms.
318317
rn = set_default_noise_scaling(rn, 0.5)
319-
rn1_noise_scaling = [get_noise_scaling(rx) for rx in get_rxs(rn)]
320-
rn2_noise_scaling = [get_noise_scaling(rx) for rx in get_rxs(Catalyst.get_systems(rn)[1])]
318+
rn1_noise_scaling = [get_noise_scaling(rx) for rx in Catalyst.get_rxs(rn)]
319+
rn2_noise_scaling = [get_noise_scaling(rx) for rx in Catalyst.get_rxs(Catalyst.get_systems(rn)[1])]
321320
rn_noise_scaling = [get_noise_scaling(rx) for rx in reactions(rn)]
322321
@test issetequal(rn1_noise_scaling, [2.0, 0.5])
323322
@test issetequal(rn2_noise_scaling, [5.0, 0.5])

test/model_simulation/u0_n_parameter_inputs.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ include("../test_networks.jl")
1919
# Tests various ways to input u0 and p for various functions.
2020
let
2121
test_network = reaction_networks_standard[7]
22-
test_osys = convert(ODESystem, test_network)
22+
test_osys = complete(convert(ODESystem, test_network))
2323
@parameters p1 p2 p3 k1 k2 k3 v1 K1 d1 d2 d3 d4 d5
2424
@species X1(t) X2(t) X3(t) X4(t) X5(t) X6(t) X(t)
2525

0 commit comments

Comments
 (0)