Skip to content

Commit 2b88314

Browse files
committed
Merge branch 'restructure_tests' into main
2 parents e45221a + 50f2d2e commit 2b88314

File tree

6 files changed

+160
-111
lines changed

6 files changed

+160
-111
lines changed

.github/workflows/ci.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: CI
2+
on:
3+
- push
4+
- pull_request
5+
jobs:
6+
test:
7+
name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }}
8+
runs-on: ${{ matrix.os }}
9+
strategy:
10+
fail-fast: false
11+
matrix:
12+
version:
13+
- '1.5'
14+
- '1.6'
15+
os:
16+
- ubuntu-latest
17+
arch:
18+
- x64
19+
steps:
20+
- uses: actions/checkout@v2
21+
- uses: julia-actions/setup-julia@v1
22+
with:
23+
version: ${{ matrix.version }}
24+
arch: ${{ matrix.arch }}
25+
- uses: actions/cache@v1
26+
env:
27+
cache-name: cache-artifacts
28+
with:
29+
path: ~/.julia/artifacts
30+
key: ${{ runner.os }}-test-${{ env.cache-name }}-${{ hashFiles('**/Project.toml') }}
31+
restore-keys: |
32+
${{ runner.os }}-test-${{ env.cache-name }}-
33+
${{ runner.os }}-test-
34+
${{ runner.os }}-
35+
- uses: julia-actions/julia-buildpkg@v1
36+
- uses: julia-actions/julia-runtest@v1
37+
- uses: julia-actions/julia-processcoverage@v1
38+
- uses: codecov/codecov-action@v1
39+
with:
40+
file: lcov.info

Project.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,12 @@ SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
1515

1616
[compat]
1717
Catalyst = "6.12, 7, 8"
18+
19+
[extras]
20+
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
21+
OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed"
22+
SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f"
23+
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
24+
25+
[targets]
26+
test = ["Distributions", "OrdinaryDiffEq", "SafeTestsets", "Test"]

test/Project.toml

Lines changed: 0 additions & 5 deletions
This file was deleted.

test/birthdeath2D.jl

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
using Test
2+
using OrdinaryDiffEq
3+
using Distributions
4+
using FiniteStateProjection
5+
using SparseArrays
6+
7+
marg(vec; dims) = dropdims(sum(vec; dims); dims)
8+
9+
@parameters r1, r2, s1, s2
10+
rs = @reaction_network begin
11+
r1, 0 --> A
12+
r2, A --> 0
13+
s1, 0 --> B
14+
s2, B --> 0
15+
end r1 r2 s1 s2
16+
17+
sys = FSPSystem(rs)
18+
19+
prs = exp.(2 .* rand(2))
20+
ps = [ prs; prs ./ exp.(4 .* rand(2)) ]
21+
22+
Nmax = 250
23+
u0 = zeros(Nmax+1, Nmax+1)
24+
u0[1] = 1.0
25+
26+
tt = [ 0.25, 1.0, 10.0 ]
27+
28+
prob = convert(ODEProblem, sys, u0, 10.0, ps)
29+
sol = solve(prob, Vern7(), atol=1e-9, rtol=1e-6, saveat=tt)
30+
31+
@test marg(sol.u[1], dims=2) pdf.(Poisson(ps[1] / ps[2] * (1 - exp(-ps[2] * tt[1]))), 0:Nmax) atol=1e-4
32+
@test marg(sol.u[1], dims=1) pdf.(Poisson(ps[3] / ps[4] * (1 - exp(-ps[4] * tt[1]))), 0:Nmax) atol=1e-4
33+
34+
@test marg(sol.u[2], dims=2) pdf.(Poisson(ps[1] / ps[2] * (1 - exp(-ps[2] * tt[2]))), 0:Nmax) atol=1e-4
35+
@test marg(sol.u[2], dims=1) pdf.(Poisson(ps[3] / ps[4] * (1 - exp(-ps[4] * tt[2]))), 0:Nmax) atol=1e-4
36+
37+
@test marg(sol.u[3], dims=2) pdf.(Poisson(ps[1] / ps[2] * (1 - exp(-ps[2] * tt[3]))), 0:Nmax) atol=1e-4
38+
@test marg(sol.u[3], dims=1) pdf.(Poisson(ps[3] / ps[4] * (1 - exp(-ps[4] * tt[3]))), 0:Nmax) atol=1e-4
39+
40+
A = convert(SparseMatrixCSC, sys, (Nmax+1, Nmax+1), ps, 0)
41+
f = (du,u,t) -> mul!(du, A, u)
42+
43+
probA = ODEProblem(f, u0, 10.0)
44+
solA = solve(prob, Vern7(), atol=1e-9, rtol=1e-6, saveat=tt)
45+
46+
@test sol.u[1] solA.u[1] atol=1e-4
47+
@test sol.u[2] solA.u[2] atol=1e-4
48+
@test sol.u[3] solA.u[3] atol=1e-4

test/feedbackloop.jl

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Thanks to Xiaoming Fu for sharing his example code
2+
3+
using Test
4+
using OrdinaryDiffEq
5+
using FiniteStateProjection
6+
using SparseArrays
7+
8+
@parameters σ_off σ_on ρ_on ρ_off d
9+
10+
rs = @reaction_network begin
11+
σ_off, G + P 0
12+
σ_on * (1 - G), 0 G + P
13+
ρ_on, G G + P
14+
ρ_off * (1-G), 0 P
15+
d, P 0
16+
end σ_off σ_on ρ_on ρ_off d
17+
18+
ps = [ 1, 0.1, 20, 1, 1]
19+
Nmax = 200
20+
21+
sys = FSPSystem(rs)
22+
23+
function create_A(ps, Nmax)
24+
σ_off, σ_on, ρ_on, ρ_off, d = ps
25+
26+
A00 = sparse([ j == i ? -(ρ_off + σ_on + (i-1) * d) : j == i - 1 ? ρ_off : j == i + 1 ? i * d : 0 for i = 1:Nmax, j=1:Nmax])
27+
A01 = sparse([ j == i + 1 ? i * σ_off : 0 for i = 1:Nmax, j = 1:Nmax])
28+
29+
A10 = sparse([ j == i - 1 ? σ_on : 0 for i = 1:Nmax, j = 1:Nmax])
30+
A11 = sparse([ j == i ? -(ρ_on + (i - 1) * (d + σ_off)) : j == i - 1 ? ρ_on : j == i + 1 ? i * d : 0 for i = 1:Nmax, j=1:Nmax ])
31+
32+
A = SparseMatrixCSC{Float64, Int64}([ A00 A01; A10 A11 ])
33+
34+
# Convert to column-major ordering used by Julia
35+
J = vec(reshape(1:2*Nmax, 2, Nmax)')
36+
P = sparse(1:2*Nmax, J, 1)
37+
P' * A * P
38+
end
39+
40+
A = create_A(ps, Nmax)
41+
A_fsp = convert(SparseMatrixCSC, sys, (2, Nmax), ps, 0.)
42+
43+
@test A A_fsp
44+
45+
tt = [ 1.0, 10.0, 20.0 ]
46+
47+
u0 = zeros(2, Nmax)
48+
u0[1] = 1.0
49+
50+
prob = convert(ODEProblem, sys, u0, maximum(tt), ps)
51+
sol = solve(prob, Vern7(), atol=1e-9, rtol=1e-6, saveat=tt)
52+
53+
f = (du,u,t) -> mul!(du, A, u)
54+
55+
probA = ODEProblem(f, u0, 10.0)
56+
solA = solve(prob, Vern7(), atol=1e-9, rtol=1e-6, saveat=tt)
57+
58+
@test sol.u[1] solA.u[1] atol=1e-4
59+
@test sol.u[2] solA.u[2] atol=1e-4
60+
@test sol.u[3] solA.u[3] atol=1e-4

test/runtests.jl

Lines changed: 3 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -1,109 +1,6 @@
1-
using Test
2-
using OrdinaryDiffEq
3-
using Distributions
4-
using FiniteStateProjection
5-
using SparseArrays
6-
7-
marg(vec; dims) = dropdims(sum(vec; dims); dims)
1+
using SafeTestsets
82

93
@time begin
10-
@testset "BirthDeath2D" begin
11-
@parameters r1, r2, s1, s2
12-
rs = @reaction_network begin
13-
r1, 0 --> A
14-
r2, A --> 0
15-
s1, 0 --> B
16-
s2, B --> 0
17-
end r1 r2 s1 s2
18-
19-
sys = FSPSystem(rs)
20-
21-
prs = exp.(2 .* rand(2))
22-
ps = [ prs; prs ./ exp.(4 .* rand(2)) ]
23-
24-
Nmax = 250
25-
u0 = zeros(Nmax+1, Nmax+1)
26-
u0[1] = 1.0
27-
28-
tt = [ 0.25, 1.0, 10.0 ]
29-
30-
prob = convert(ODEProblem, sys, u0, 10.0, ps)
31-
sol = solve(prob, Vern7(), atol=1e-9, rtol=1e-6, saveat=tt)
32-
33-
@test marg(sol.u[1], dims=2) pdf.(Poisson(ps[1] / ps[2] * (1 - exp(-ps[2] * tt[1]))), 0:Nmax) atol=1e-4
34-
@test marg(sol.u[1], dims=1) pdf.(Poisson(ps[3] / ps[4] * (1 - exp(-ps[4] * tt[1]))), 0:Nmax) atol=1e-4
35-
36-
@test marg(sol.u[2], dims=2) pdf.(Poisson(ps[1] / ps[2] * (1 - exp(-ps[2] * tt[2]))), 0:Nmax) atol=1e-4
37-
@test marg(sol.u[2], dims=1) pdf.(Poisson(ps[3] / ps[4] * (1 - exp(-ps[4] * tt[2]))), 0:Nmax) atol=1e-4
38-
39-
@test marg(sol.u[3], dims=2) pdf.(Poisson(ps[1] / ps[2] * (1 - exp(-ps[2] * tt[3]))), 0:Nmax) atol=1e-4
40-
@test marg(sol.u[3], dims=1) pdf.(Poisson(ps[3] / ps[4] * (1 - exp(-ps[4] * tt[3]))), 0:Nmax) atol=1e-4
41-
42-
A = convert(SparseMatrixCSC, sys, (Nmax+1, Nmax+1), ps, 0)
43-
f = (du,u,t) -> mul!(du, A, u)
44-
45-
probA = ODEProblem(f, u0, 10.0)
46-
solA = solve(prob, Vern7(), atol=1e-9, rtol=1e-6, saveat=tt)
47-
48-
@test sol.u[1] solA.u[1] atol=1e-4
49-
@test sol.u[2] solA.u[2] atol=1e-4
50-
@test sol.u[3] solA.u[3] atol=1e-4
51-
end
52-
53-
# Thanks to Xiaoming Fu for sharing his example code
54-
@testset "FeedbackLoop" begin
55-
@parameters σ_off σ_on ρ_on ρ_off d
56-
57-
rs = @reaction_network begin
58-
σ_off, G + P 0
59-
σ_on * (1 - G), 0 G + P
60-
ρ_on, G G + P
61-
ρ_off * (1-G), 0 P
62-
d, P 0
63-
end σ_off σ_on ρ_on ρ_off d
64-
65-
ps = [ 1, 0.1, 20, 1, 1]
66-
Nmax = 200
67-
68-
sys = FSPSystem(rs)
69-
70-
function create_A(ps, Nmax)
71-
σ_off, σ_on, ρ_on, ρ_off, d = ps
72-
73-
A00 = sparse([ j == i ? -(ρ_off + σ_on + (i-1) * d) : j == i - 1 ? ρ_off : j == i + 1 ? i * d : 0 for i = 1:Nmax, j=1:Nmax])
74-
A01 = sparse([ j == i + 1 ? i * σ_off : 0 for i = 1:Nmax, j = 1:Nmax])
75-
76-
A10 = sparse([ j == i - 1 ? σ_on : 0 for i = 1:Nmax, j = 1:Nmax])
77-
A11 = sparse([ j == i ? -(ρ_on + (i - 1) * (d + σ_off)) : j == i - 1 ? ρ_on : j == i + 1 ? i * d : 0 for i = 1:Nmax, j=1:Nmax ])
78-
79-
A = SparseMatrixCSC{Float64, Int64}([ A00 A01; A10 A11 ])
80-
81-
# Convert to column-major ordering used by Julia
82-
J = vec(reshape(1:2*Nmax, 2, Nmax)')
83-
P = sparse(1:2*Nmax, J, 1)
84-
P' * A * P
85-
end
86-
87-
A = create_A(ps, Nmax)
88-
A_fsp = convert(SparseMatrixCSC, sys, (2, Nmax), ps, 0.)
89-
90-
@test A A_fsp
91-
92-
tt = [ 1.0, 10.0, 20.0 ]
93-
94-
u0 = zeros(2, Nmax)
95-
u0[1] = 1.0
96-
97-
prob = convert(ODEProblem, sys, u0, maximum(tt), ps)
98-
sol = solve(prob, Vern7(), atol=1e-9, rtol=1e-6, saveat=tt)
99-
100-
f = (du,u,t) -> mul!(du, A, u)
101-
102-
probA = ODEProblem(f, u0, 10.0)
103-
solA = solve(prob, Vern7(), atol=1e-9, rtol=1e-6, saveat=tt)
104-
105-
@test sol.u[1] solA.u[1] atol=1e-4
106-
@test sol.u[2] solA.u[2] atol=1e-4
107-
@test sol.u[3] solA.u[3] atol=1e-4
108-
end
4+
@safetestset "BirthDeath2D" begin include("birthdeath2D.jl") end
5+
@safetestset "FeedbackLoop" begin include("feedbackloop.jl") end
1096
end

0 commit comments

Comments
 (0)