Skip to content

Commit 88374e9

Browse files
committed
init
1 parent 4d1c677 commit 88374e9

File tree

4 files changed

+73
-21
lines changed

4 files changed

+73
-21
lines changed

test/simulation_and_solving/simulate_ODEs.jl

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,13 @@ end
164164

165165
### Other Tests ###
166166

167-
# Checks that simulations values consistently have Float64 type.
167+
# Checks that solution values have types consistent with their input types.
168+
# Check that both float types are preserved in the solution (and problems), while integers are
169+
# promoted to floats.
170+
# Checks that the time types are correct (`Float64` by default or possibly `Float32`), however,
171+
# type conversion only occurs in the solution, and integer types are preserved in problems.
168172
let
169-
# Create model and check simulation value type (FLoat64 values).
170-
# Generally, the tend type should not matter.
173+
# Create model. Checks when input type is `Float64` the produced values are also `Float64`.
171174
rn = @reaction_network begin
172175
(k1,k2), X1 <--> X2
173176
end
@@ -176,20 +179,24 @@ let
176179
oprob = ODEProblem(rn, u0, 1.0, ps)
177180
osol = solve(oprob)
178181
@test eltype(osol[:X1]) == eltype(osol[:X2]) == typeof(oprob[:X1]) == typeof(oprob[:X2]) == Float64
182+
@test eltype(osol.t) == typeof(oprob.tspan[1]) == typeof(oprob.tspan[2]) == Float64
179183

180-
# Check type when input values are Int64.
184+
# Checks that `Int64` values are promoted to `Float64`.
181185
u0 = [:X1 => 1, :X2 => 3]
182186
ps = [:k1 => 2, :k2 => 3]
183187
oprob = ODEProblem(rn, u0, 1, ps)
184188
osol = solve(oprob)
185189
@test eltype(osol[:X1]) == eltype(osol[:X2]) == typeof(oprob[:X1]) == typeof(oprob[:X2]) == Float64
190+
@test eltype(osol.t) == Float64
191+
@test typeof(oprob.tspan[1]) == typeof(oprob.tspan[2]) == Int64
186192

187-
# Check type when input values are Float32.
193+
# Checks when values are `Float32` (a valid type and should be preserved).
188194
u0 = [:X1 => 1.0f0, :X2 => 3.0f0]
189195
ps = [:k1 => 2.0f0, :k2 => 3.0f0]
190196
oprob = ODEProblem(rn, u0, 1.0f0, ps)
191197
osol = solve(oprob)
192198
@test eltype(osol[:X1]) == eltype(osol[:X2]) == typeof(oprob[:X1]) == typeof(oprob[:X2]) == Float32
199+
@test eltype(osol.t) == typeof(oprob.tspan[1]) == typeof(oprob.tspan[2]) == Float32
193200
end
194201

195202
# Tests simulating a network without parameters.

test/simulation_and_solving/simulate_SDEs.jl

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -383,32 +383,39 @@ end
383383

384384
### Other Tests ###
385385

386-
# Checks that simulations values consistently have Float64 type.
386+
# Checks that solution values have types consistent with their input types.
387+
# Check that both float types are preserved in the solution (and problems), while integers are
388+
# promoted to floats.
389+
# Checks that the time types are correct (`Float64` by default or possibly `Float32`), however,
390+
# type conversion only occurs in the solution, and integer types are preserved in problems.
387391
let
388-
# Create model and check simulation value type (FLoat64 values).
389-
# Generally, the tend type should not matter.
392+
# Create model. Checks when input type is `Float64` the produced values are also `Float64`.
390393
rn = @reaction_network begin
391394
(k1,k2), X1 <--> X2
392395
end
393-
u0 = [:X1 => 100.0, :X2 => 300.0]
396+
u0 = [:X1 => 1.0, :X2 => 3.0]
394397
ps = [:k1 => 2.0, :k2 => 3.0]
395398
sprob = SDEProblem(rn, u0, 1.0, ps)
396399
ssol = solve(sprob, ISSEM())
397400
@test eltype(ssol[:X1]) == eltype(ssol[:X2]) == typeof(sprob[:X1]) == typeof(sprob[:X2]) == Float64
401+
@test eltype(ssol.t) == typeof(sprob.tspan[1]) == typeof(sprob.tspan[2]) == Float64
398402

399-
# Check type when input values are Int64.
400-
u0 = [:X1 => 100, :X2 => 300]
403+
# Checks that `Int64` values are promoted to `Float64`.
404+
u0 = [:X1 => 1, :X2 => 3]
401405
ps = [:k1 => 2, :k2 => 3]
402406
sprob = SDEProblem(rn, u0, 1, ps)
403407
ssol = solve(sprob, ISSEM())
404408
@test eltype(ssol[:X1]) == eltype(ssol[:X2]) == typeof(sprob[:X1]) == typeof(sprob[:X2]) == Float64
409+
@test eltype(ssol.t) == Float64
410+
@test typeof(sprob.tspan[1]) == typeof(sprob.tspan[2]) == Int64
405411

406-
# Check type when input values are Float32.
407-
u0 = [:X1 => 100.0f0, :X2 => 300.0f0]
412+
# Checks when values are `Float32` (a valid type and should be preserved).
413+
u0 = [:X1 => 1.0f0, :X2 => 3.0f0]
408414
ps = [:k1 => 2.0f0, :k2 => 3.0f0]
409415
sprob = SDEProblem(rn, u0, 1.0f0, ps)
410416
ssol = solve(sprob, ISSEM())
411417
@test eltype(ssol[:X1]) == eltype(ssol[:X2]) == typeof(sprob[:X1]) == typeof(sprob[:X2]) == Float32
418+
@test eltype(ssol.t) == typeof(sprob.tspan[1]) == typeof(sprob.tspan[2]) == Float32
412419
end
413420

414421
# Tests simulating a network without parameters.

test/simulation_and_solving/simulate_jumps.jl

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -223,10 +223,13 @@ end
223223

224224
### Other Tests ###
225225

226-
# Checks that simulations values have the correct type (Float64/Int64 depending on input).
226+
# Checks that solution values have types consistent with their input types.
227+
# Check that both float and integer values are preserved in the solution (and problems).
228+
# Checks that the time values are correct (`Float64` by default or possibly `Float32`).
229+
# `JumpInputs` currently does not support integer time spans. When it does, we will check that
230+
# these produce `Float64` time values.
227231
let
228-
# Create model and check simulation value type (FLoat64 values).
229-
# Generally, the tend type should not matter.
232+
# Create model. Checks when input type is `Float64` the produced values are also `Float64`.
230233
rn = @reaction_network begin
231234
(k1,k2), X1 <--> X2
232235
end
@@ -235,25 +238,29 @@ let
235238
jprob = JumpProblem(JumpInputs(rn, u0, (0.0, 1.0), ps))
236239
jsol = solve(jprob)
237240
@test eltype(jsol[:X1]) == eltype(jsol[:X2]) == typeof(jprob[:X1]) == typeof(jprob[:X2]) == Float64
241+
@test eltype(jsol.t) == typeof(jprob.prob.tspan[1]) == typeof(jprob.prob.tspan[2]) == Float64
238242

239-
# Check type when input values are Int64.
243+
# Checks that `Int64` gives `Int64` species values.
240244
u0 = [:X1 => 1 :X2 => 3]
241245
ps = [:k1 => 2, :k2 => 3]
242-
jprob = JumpProblem(JumpInputs(rn, u0, (0, 1), ps))
246+
jprob = JumpProblem(JumpInputs(rn, u0, (0.0, 1.0), ps))
243247
jsol = solve(jprob)
244248
@test eltype(jsol[:X1]) == eltype(jsol[:X2]) == typeof(jprob[:X1]) == typeof(jprob[:X2]) == Int64
249+
@test eltype(jsol.t) == typeof(jprob.prob.tspan[1]) == typeof(jprob.prob.tspan[2]) == Float64
245250

246-
# Check type when input values are Float32 (should yield types that are ).
251+
# Checks when values are `Float32` (a valid type and should be preserved).
247252
u0 = [:X1 => 1.0f0, :X2 => 3.0f0]
248253
ps = [:k1 => 2.0f0, :k2 => 3.0f0]
249254
jprob = JumpProblem(JumpInputs(rn, u0, (0.0f0, 1.0f0), ps))
250255
jsol = solve(jprob)
251256
@test eltype(jsol[:X1]) == eltype(jsol[:X2]) == typeof(jprob[:X1]) == typeof(jprob[:X2]) == Float32
257+
@test eltype(jsol.t) == typeof(jprob.prob.tspan[1]) == typeof(jprob.prob.tspan[2]) == Float32
252258

253-
# Check type when input values are Int32 (should yield types that are ).
259+
# Checks when values are `Int32` (a valid species type and should be preserved).
254260
u0 = [:X1 => Int32(1), :X2 => Int32(3)]
255261
ps = [:k1 => Int32(2), :k2 => Int32(3)]
256-
jprob = JumpProblem(JumpInputs(rn, u0, (Int32(0), Int32(1)), ps))
262+
jprob = JumpProblem(JumpInputs(rn, u0, (0.0, 1.0), ps))
257263
jsol = solve(jprob)
258264
@test eltype(jsol[:X1]) == eltype(jsol[:X2]) == typeof(jprob[:X1]) == typeof(jprob[:X2]) == Int32
265+
@test eltype(jsol.t) == typeof(jprob.prob.tspan[1]) == typeof(jprob.prob.tspan[2]) == Float64
259266
end

test/simulation_and_solving/solve_nonlinear.jl

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,34 @@ let
101101
@test f_eval(steady_state_network_3, [:X => sol1[X], :Y => sol1[Y], :Y2 => sol1[Y2], :XY2 => sol1[XY2]], p, 0.0) [0.0, 0.0, 0.0, 0.0] atol=1e-10
102102
@test f_eval(steady_state_network_3, [:X => sol2[X], :Y => sol2[Y], :Y2 => sol2[Y2], :XY2 => sol2[XY2]], p, 0.0) [0.0, 0.0, 0.0, 0.0] atol=1e-10
103103
end
104+
105+
### Other Tests ###
106+
107+
# Checks that solution values have types consistent with their input types.
108+
# Check for values that types that should be preserved (`Float64` and `Float32`) and types
109+
# that should be converted to the default (conversion of `Int64 to `Float64`).
110+
let
111+
# Create model. Checks when input type is `Float64` that the problem and solution types are `Float64`.
112+
rn = @reaction_network begin
113+
(k1,k2), X1 <--> X2
114+
end
115+
u0 = [:X1 => 1.0, :X2 => 3.0]
116+
ps = [:k1 => 2.0, :k2 => 3.0]
117+
nlprob = NonlinearProblem(rn, u0, ps)
118+
nlsol = solve(nlprob)
119+
@test eltype(nlsol[:X1]) == eltype(nlsol[:X2]) == typeof(nlprob[:X1]) == typeof(nlprob[:X2]) == Float64
120+
121+
# Checks that input type `Int64` is converted to `Float64`.
122+
u0 = [:X1 => 1, :X2 => 3]
123+
ps = [:k1 => 2, :k2 => 3]
124+
nlprob = NonlinearProblem(rn, u0, ps)
125+
nlsol = solve(nlprob)
126+
@test eltype(nlsol[:X1]) == eltype(nlsol[:X2]) == typeof(nlprob[:X1]) == typeof(nlprob[:X2]) == Float64
127+
128+
# Checks that input type `Float32` is preserved
129+
u0 = [:X1 => 1.0f0, :X2 => 3.0f0]
130+
ps = [:k1 => 2.0f0, :k2 => 3.0f0]
131+
nlprob = NonlinearProblem(rn, u0, ps)
132+
nlsol = solve(nlprob)
133+
@test eltype(nlsol[:X1]) == eltype(nlsol[:X2]) == typeof(nlprob[:X1]) == typeof(nlprob[:X2]) == Float32
134+
end

0 commit comments

Comments
 (0)