Skip to content

Commit

Permalink
save progress
Browse files Browse the repository at this point in the history
  • Loading branch information
TorkelE committed Apr 10, 2024
1 parent fcae9d2 commit 7b816cc
Showing 1 changed file with 15 additions and 17 deletions.
32 changes: 15 additions & 17 deletions test/reactionsystem_structure/hybrid_equation_reaction_systems.jl
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,7 @@ let
osol_messy[[:S, :I, :R, :M, :H]] osol_ordered[[:S, :I, :R, :M, :H]]
end


### DSL Tests ###

# Check that a hybrid CRN/DAE created programmatically and via the DSL are identical.
Expand All @@ -546,8 +547,8 @@ end
# Checks that generated system contents are correct, and ODE simulations are identical.
let
# Creates the model programmatically.
@species X1(t) X2(t) X3(t) X_tot(t)
@variables V(t)=5.0 [description="Volume"] N(t) X_conc(t)
@species X1(t) X2(t) X3(t)
@variables V(t)=5.0 [description="Volume"] N(t) X_conc(t) X_tot(t)
@parameters p k1 k2 d v n x_scale::Float32
eqs = [
Reaction(p, nothing, [X1])
Expand All @@ -563,8 +564,7 @@ let

# Creates the model via the DSL.
rs_dsl = @reaction_network hybrid_rs begin
@species X_tot(t)
@variables X_conc(t) V(t)=5.0 [description="Volume"]
@variables X_conc(t) V(t)=5.0 [description="Volume"] X_tot(t)
@parameters v n x_scale::Float32
@equations begin
D(V) ~ X3/(1+X3) - v*V
Expand All @@ -580,31 +580,29 @@ let

# Checks that models are identical. Also checks that they have the correct content.
@test rs_prog == rs_dsl
@test getdescription(rs_dsl.V) == "Volume"
@test getdefault(rs_dsl.V) == 5.0
@test unwrap(rs_dsl.x_scale) isa BasicSymbolic{Float32}

@test issetequal(parameters(rs_dsl), [p, k1, k2, d, v, n, x_scale])
@test issetequal(species(rs_dsl), unknowns(rs_dsl)[1:4])
@test issetequal(unknowns(rs_dsl)[1:4], [X1, X2, X3, X_tot])
@test issetequal(unknowns(rs_dsl)[5:7], [V N X_conc])
@test issetequal(species(rs_dsl), unknowns(rs_dsl)[1:3])
@test issetequal(unknowns(rs_dsl)[1:3], [X1, X2, X3])
@test issetequal(unknowns(rs_dsl)[4:7], [V, N, X_conc, X_tot])
@test issetequal(reactions(rs_dsl), equations(rs_dsl)[1:4])
@test issetequal(equations(rs_dsl)[1:4], eqs[1:4])
@test issetequal(equations(rs_dsl)[5:7], eqs[5:7])

@test getdescription(rs_dsl.V) == "Volume"
@test getdefault(rs_dsl.V) == 5.0
@test unwrap(rs_dsl.x_scale) isa BasicSymbolic{Float32}

# Checks that the models can be simulated and yield identical results.
# Test most likely redundant, but seem useful to have one test like this to be sure.
u0 = [X1 => 0.1, X2 => 0.2, X3 => 0.2, X_tot => 0.6, N => 10.0, X_conc => 10.0]
tspan = (0.0, 10.0)
ps = [p => 1.0, k1 => 1.2, k2 => 1.5, d => 2.0, v => 0.2, n => 0.5, x_scale => 2.0]

@test_broken begin # ODEs become overdetermined.
oprob_prog = ODEProblem(rs_prog, u0, tspan, ps; structural_simplify = true)
oprob_dsl = ODEProblem(rs_dsl, u0, tspan, ps; structural_simplify = true)
@test solve(oprob_prog, Tsit5()) == solve(oprob_dsl, Tsit5())
end
oprob_prog = ODEProblem(rs_prog, u0, (0.0, 10.0), ps; structural_simplify = true)
oprob_dsl = ODEProblem(rs_dsl, u0, (0.0, 10.0), ps; structural_simplify = true)
@test solve(oprob_prog, Rosenbrock23()) == solve(oprob_dsl, Rosenbrock23())
end


### Error Tests ###

# Checks that various erroneous hybrid system declarations yield errors.
Expand Down

0 comments on commit 7b816cc

Please sign in to comment.