Skip to content

Commit

Permalink
add tests for non-time functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
TorkelE committed Mar 8, 2025
1 parent c906855 commit c7a441b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
5 changes: 3 additions & 2 deletions docs/src/model_creation/time_dependent_parameters.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ end
```
Finally, we can simulate our model as normal, but setting the value of the `pIn` parameter to our interpolated data.
```@example time_dependent_parameters_basic_example
using OrdinaryDiffEq, Plots
using OrdinaryDiffEqDefault, Plots
u0 = [:X => 0.5]
ps = [:d => 2.0, pIn => spline]
oprob = ODEProblem(bd_model, u0, tend, ps)
Expand Down Expand Up @@ -65,7 +65,8 @@ using OrdinaryDiffEqDefault
u0 = [Pi => 1.0, Pa => 0.0]
ps = [kA => 1.5, kB => 1.0, pIn => interpolated_light]
oprob = ODEProblem(rs, u0, tend, ps)
sol = solve()
sol = solve(oprob)
nothing # hide
```

### [Interpolating the input into the DSL] (@id time_dependent_parameters_circ_rhythm_dsl)
Expand Down
27 changes: 26 additions & 1 deletion test/reactionsystem_core/functional_parameters.jl
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,33 @@ let
end

# Checks correctness for non-time functions.
# Uses an SIR model where we have modified the infection step to not scale linary with I.
# Intended to add cases with 2d functions here as well, but this is currently not supported.
let
# TBC
# Declares the functional parameter.
Is = collect(0.0:0.0001:200.0)
spline1d = LinearInterpolation(100.0*Is ./ (100.0 .+ Is), Is)
@parameters (i_rate::typeof(spline1d))(..)

# Decalres the models.
sir = @reaction_network begin
k1*100*I/(100 + I), S --> I
k2, I --> R
end
input = i_rate(sir.I)
sir_funcp = @reaction_network rs begin
k1*$(input), S --> I
k2, I --> R
end

# Simulates the models for the same conditions. Checks that simulations are identical.
u0 = [:S => 99.0, :I => 10.0, :R => 0.0]
ps = [:k1 => 0.01, :k2 => 0.01]
oprob = ODEProblem(sir, u0, 200.0, ps)
oprob_funcp = ODEProblem(sir_funcp, u0, 200.0, [ps; i_rate => spline1d])
sol = solve(oprob)
sol_funcp = solve(oprob_funcp)
@test sol.u sol_funcp.u atol = 1e-6 rtol = 1e-6
end

### Error Checks ###
Expand Down

0 comments on commit c7a441b

Please sign in to comment.