Skip to content

Commit 1cfa932

Browse files
authored
Merge pull request #835 from SciML/test_restructure
Test restructure and parallelisation
2 parents 0807b15 + 968dbe8 commit 1cfa932

33 files changed

+487
-574
lines changed

.github/workflows/CI.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,9 @@ on:
33
pull_request:
44
branches:
55
- master
6-
- Catalyst_version_14
76
push:
87
branches:
98
- master
10-
- Catalyst_version_14
119
jobs:
1210
test:
1311
runs-on: ubuntu-latest

test/programmatic_model_creation/component_based_model_creation.jl renamed to test/compositional_modelling/component_based_model_creation.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
using Catalyst, LinearAlgebra, OrdinaryDiffEq, SciMLNLSolve, Test
77
using ModelingToolkit: nameof
88

9-
# Fetch test networks.
9+
# Sets the default `t` to use.
1010
t = default_t()
1111

1212

test/dsl/dsl_basics.jl renamed to test/dsl/dsl_advanced_model_construction.jl

Lines changed: 12 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#! format: off
22

3-
### Fetch Packages and Set Global Variables ###
3+
### Prepares Tests ###
44

55
# Fetch packages.
66
using Catalyst, ModelingToolkit
@@ -10,7 +10,16 @@ t = default_t()
1010

1111
### Naming Tests ###
1212

13-
# Test that the correct name is generated.
13+
# Basic name test.
14+
let
15+
rn = @reaction_network SIR1 begin
16+
k1, S + I --> 2I
17+
k2, I --> R
18+
end
19+
@test nameof(rn) == :SIR1
20+
end
21+
22+
# Advanced name tests.
1423
let
1524
@parameters k
1625
@species A(t)
@@ -67,12 +76,12 @@ end
6776

6877
### Test Interpolation Within the DSL ###
6978

70-
# Tests basic interpolation cases.
7179

7280
# Declares parameters and species used across the test.
7381
@parameters α k k1 k2
7482
@species A(t) B(t) C(t) D(t)
7583

84+
# Tests basic interpolation cases.
7685
let
7786
AA = A
7887
AAA = A^2 + B
@@ -92,7 +101,6 @@ let
92101
rn2 = ReactionSystem([Reaction(k, [AA,C], [D])], t; name=:rn)
93102
@test rn == rn2
94103
end
95-
96104
let
97105
BB = B; A2 = A
98106
rn = @reaction_network rn begin
@@ -104,7 +112,6 @@ let
104112
t; name=:rn)
105113
@test rn == rn2
106114
end
107-
108115
let
109116
AA = A
110117
kk1 = k^2*A
@@ -323,58 +330,6 @@ let
323330
@test length(equations(osys2)) == 2
324331
end
325332

326-
# Test @variables in DSL.
327-
let
328-
rn = @reaction_network tester begin
329-
@parameters k1
330-
@variables V1(t) V2(t) V3(t)
331-
@species B1(t) B2(t)
332-
(k1*k2 + V3), V1*A + 2*B1 --> V2*C + B2
333-
end
334-
335-
@parameters k1 k2
336-
@variables V1(t) V2(t) V3(t)
337-
@species A(t) B1(t) B2(t) C(t)
338-
rx = Reaction(k1*k2 + V3, [A, B1], [C, B2], [V1, 2], [V2, 1])
339-
@named tester = ReactionSystem([rx], t)
340-
@test tester == rn
341-
342-
sts = (A, B1, B2, C, V1, V2, V3)
343-
spcs = (A, B1, B2, C)
344-
@test issetequal(unknowns(rn), sts)
345-
@test issetequal(species(rn), spcs)
346-
347-
@test_throws ArgumentError begin
348-
rn = @reaction_network begin
349-
@variables K
350-
k, K*A --> B
351-
end
352-
end
353-
end
354-
355-
# Test ivs in DSL.
356-
let
357-
rn = @reaction_network ivstest begin
358-
@ivs s x
359-
@parameters k2
360-
@variables D(x) E(s) F(s,x)
361-
@species A(s,x) B(s) C(x)
362-
k*k2*D, E*A +B --> F*C + C2
363-
end
364-
365-
@parameters k k2
366-
@variables s x D(x) E(s) F(s,x)
367-
@species A(s,x) B(s) C(x) C2(s,x)
368-
rx = Reaction(k*k2*D, [A, B], [C, C2], [E, 1], [F, 1])
369-
@named ivstest = ReactionSystem([rx], s; spatial_ivs = [x])
370-
371-
@test ivstest == rn
372-
@test issetequal(unknowns(rn), [D, E, F, A, B, C, C2])
373-
@test issetequal(species(rn), [A, B, C, C2])
374-
@test isequal(ModelingToolkit.get_iv(rn), s)
375-
@test issetequal(Catalyst.get_sivs(rn), [x])
376-
end
377-
378333
# Array variables test.
379334
let
380335
rn = @reaction_network arrtest begin

test/dsl/dsl_model_construction.jl renamed to test/dsl/dsl_basic_model_construction.jl

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@
44
using DiffEqBase, Catalyst, Random, Test
55
using ModelingToolkit: operation, istree, get_unknowns, get_ps, get_eqs, get_systems,
66
get_iv, nameof
7-
t = default_t()
87

9-
# Sets rnd number.
8+
# Sets stable rng number.
109
using StableRNGs
1110
rng = StableRNG(12345)
1211

12+
# Sets the default `t` to use.
13+
t = default_t()
14+
1315
# Fetch test networks and functions.
1416
include("../test_networks.jl")
1517
include("../test_functions.jl")
@@ -33,7 +35,7 @@ function all_reactants(eqs)
3335
return Set{Symbol}(unique(all_reactants))
3436
end
3537

36-
# Gets all parameters (where every reaction rate is constant)
38+
# Gets all parameters (where every reaction rate is constant).
3739
function all_parameters(eqs)
3840
return Set(unique(map(eq -> opname(eq.rate), eqs)))
3941
end
@@ -371,7 +373,7 @@ let
371373
end
372374
end
373375

374-
# Test that I works as a name.
376+
# Test that the `I` symbol works as a quantity name.
375377
let
376378
rn = @reaction_network begin
377379
k1, S + I --> 2I
@@ -382,7 +384,7 @@ let
382384
@test any(isequal(I), unknowns(rn))
383385
end
384386

385-
# Tests backwards and double arrows.
387+
# Tests backwards and bi-directional arrows.
386388
let
387389
rn1 = @reaction_network arrowtest begin
388390
(a1, a2), C <--> 0
@@ -401,7 +403,7 @@ let
401403
@test rn1 == rn2
402404
end
403405

404-
# Tests arrow variants in "@reaction" macro .
406+
# Tests arrow variants in `@reaction`` macro .
405407
let
406408
@test isequal((@reaction k, 0 --> X), (@reaction k, X <-- 0))
407409
@test isequal((@reaction k, 0 --> X), (@reaction k, X 0))
@@ -435,15 +437,3 @@ let
435437
@test_throws LoadError @eval @reaction k, 0 --> im
436438
@test_throws LoadError @eval @reaction k, 0 --> nothing
437439
end
438-
439-
440-
### Other Tests ###
441-
442-
# Test names work.
443-
let
444-
rn = @reaction_network SIR1 begin
445-
k1, S + I --> 2I
446-
k2, I --> R
447-
end
448-
@test nameof(rn) == :SIR1
449-
end

test/dsl/dsl_options.jl

Lines changed: 58 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ seed = rand(rng, 1:100)
1414
# Sets the default `t` to use.
1515
t = default_t()
1616

17-
### Tests `@parameters` and `@species` Options ###
17+
### Tests `@parameters`, `@species`, and `@variables` Options ###
1818

1919
# Test creating networks with/without options.
2020
let
@@ -394,6 +394,61 @@ let
394394
@test !ModelingToolkit.hasdescription(unwrap(rn.k5))
395395
end
396396

397+
# Test @variables in DSL.
398+
let
399+
rn = @reaction_network tester begin
400+
@parameters k1
401+
@variables V1(t) V2(t) V3(t)
402+
@species B1(t) B2(t)
403+
(k1*k2 + V3), V1*A + 2*B1 --> V2*C + B2
404+
end
405+
406+
@parameters k1 k2
407+
@variables V1(t) V2(t) V3(t)
408+
@species A(t) B1(t) B2(t) C(t)
409+
rx = Reaction(k1*k2 + V3, [A, B1], [C, B2], [V1, 2], [V2, 1])
410+
@named tester = ReactionSystem([rx], t)
411+
@test tester == rn
412+
413+
sts = (A, B1, B2, C, V1, V2, V3)
414+
spcs = (A, B1, B2, C)
415+
@test issetequal(unknowns(rn), sts)
416+
@test issetequal(species(rn), spcs)
417+
418+
@test_throws ArgumentError begin
419+
rn = @reaction_network begin
420+
@variables K
421+
k, K*A --> B
422+
end
423+
end
424+
end
425+
426+
### Test Independent Variable Designations ###
427+
428+
# Test ivs in DSL.
429+
let
430+
rn = @reaction_network ivstest begin
431+
@ivs s x
432+
@parameters k2
433+
@variables D(x) E(s) F(s,x)
434+
@species A(s,x) B(s) C(x)
435+
k*k2*D, E*A +B --> F*C + C2
436+
end
437+
438+
@parameters k k2
439+
@variables s x D(x) E(s) F(s,x)
440+
@species A(s,x) B(s) C(x) C2(s,x)
441+
rx = Reaction(k*k2*D, [A, B], [C, C2], [E, 1], [F, 1])
442+
@named ivstest = ReactionSystem([rx], s; spatial_ivs = [x])
443+
444+
@test ivstest == rn
445+
@test issetequal(unknowns(rn), [D, E, F, A, B, C, C2])
446+
@test issetequal(species(rn), [A, B, C, C2])
447+
@test isequal(ModelingToolkit.get_iv(rn), s)
448+
@test issetequal(Catalyst.get_sivs(rn), [x])
449+
end
450+
451+
397452
### Observables ###
398453

399454
# Test basic functionality.
@@ -596,7 +651,7 @@ let
596651
@test length(unknowns(rn2)) == 2
597652
end
598653

599-
# Tests specific declaration of Observables as species/variables
654+
# Tests specific declaration of observables as species/variables.
600655
let
601656
rn = @reaction_network begin
602657
@species X(t)
@@ -687,7 +742,7 @@ let
687742
end
688743

689744

690-
### Coupled CRN/Equations Models ###
745+
### Test `@equations` Option for Coupled CRN/Equations Models ###
691746

692747
# Checks creation of basic network.
693748
# Check indexing of output solution.

0 commit comments

Comments
 (0)