Skip to content

Commit

Permalink
Merge pull request #835 from SciML/test_restructure
Browse files Browse the repository at this point in the history
Test restructure and parallelisation
  • Loading branch information
TorkelE authored May 16, 2024
2 parents 0807b15 + 968dbe8 commit 1cfa932
Show file tree
Hide file tree
Showing 33 changed files with 487 additions and 574 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@ on:
pull_request:
branches:
- master
- Catalyst_version_14
push:
branches:
- master
- Catalyst_version_14
jobs:
test:
runs-on: ubuntu-latest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using Catalyst, LinearAlgebra, OrdinaryDiffEq, SciMLNLSolve, Test
using ModelingToolkit: nameof

# Fetch test networks.
# Sets the default `t` to use.
t = default_t()


Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#! format: off

### Fetch Packages and Set Global Variables ###
### Prepares Tests ###

# Fetch packages.
using Catalyst, ModelingToolkit
Expand All @@ -10,7 +10,16 @@ t = default_t()

### Naming Tests ###

# Test that the correct name is generated.
# Basic name test.
let
rn = @reaction_network SIR1 begin
k1, S + I --> 2I
k2, I --> R
end
@test nameof(rn) == :SIR1
end

# Advanced name tests.
let
@parameters k
@species A(t)
Expand Down Expand Up @@ -67,12 +76,12 @@ end

### Test Interpolation Within the DSL ###

# Tests basic interpolation cases.

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

# Tests basic interpolation cases.
let
AA = A
AAA = A^2 + B
Expand All @@ -92,7 +101,6 @@ let
rn2 = ReactionSystem([Reaction(k, [AA,C], [D])], t; name=:rn)
@test rn == rn2
end

let
BB = B; A2 = A
rn = @reaction_network rn begin
Expand All @@ -104,7 +112,6 @@ let
t; name=:rn)
@test rn == rn2
end

let
AA = A
kk1 = k^2*A
Expand Down Expand Up @@ -323,58 +330,6 @@ let
@test length(equations(osys2)) == 2
end

# Test @variables in DSL.
let
rn = @reaction_network tester begin
@parameters k1
@variables V1(t) V2(t) V3(t)
@species B1(t) B2(t)
(k1*k2 + V3), V1*A + 2*B1 --> V2*C + B2
end

@parameters k1 k2
@variables V1(t) V2(t) V3(t)
@species A(t) B1(t) B2(t) C(t)
rx = Reaction(k1*k2 + V3, [A, B1], [C, B2], [V1, 2], [V2, 1])
@named tester = ReactionSystem([rx], t)
@test tester == rn

sts = (A, B1, B2, C, V1, V2, V3)
spcs = (A, B1, B2, C)
@test issetequal(unknowns(rn), sts)
@test issetequal(species(rn), spcs)

@test_throws ArgumentError begin
rn = @reaction_network begin
@variables K
k, K*A --> B
end
end
end

# Test ivs in DSL.
let
rn = @reaction_network ivstest begin
@ivs s x
@parameters k2
@variables D(x) E(s) F(s,x)
@species A(s,x) B(s) C(x)
k*k2*D, E*A +B --> F*C + C2
end

@parameters k k2
@variables s x D(x) E(s) F(s,x)
@species A(s,x) B(s) C(x) C2(s,x)
rx = Reaction(k*k2*D, [A, B], [C, C2], [E, 1], [F, 1])
@named ivstest = ReactionSystem([rx], s; spatial_ivs = [x])

@test ivstest == rn
@test issetequal(unknowns(rn), [D, E, F, A, B, C, C2])
@test issetequal(species(rn), [A, B, C, C2])
@test isequal(ModelingToolkit.get_iv(rn), s)
@test issetequal(Catalyst.get_sivs(rn), [x])
end

# Array variables test.
let
rn = @reaction_network arrtest begin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
using DiffEqBase, Catalyst, Random, Test
using ModelingToolkit: operation, istree, get_unknowns, get_ps, get_eqs, get_systems,
get_iv, nameof
t = default_t()

# Sets rnd number.
# Sets stable rng number.
using StableRNGs
rng = StableRNG(12345)

# Sets the default `t` to use.
t = default_t()

# Fetch test networks and functions.
include("../test_networks.jl")
include("../test_functions.jl")
Expand All @@ -33,7 +35,7 @@ function all_reactants(eqs)
return Set{Symbol}(unique(all_reactants))
end

# Gets all parameters (where every reaction rate is constant)
# Gets all parameters (where every reaction rate is constant).
function all_parameters(eqs)
return Set(unique(map(eq -> opname(eq.rate), eqs)))
end
Expand Down Expand Up @@ -371,7 +373,7 @@ let
end
end

# Test that I works as a name.
# Test that the `I` symbol works as a quantity name.
let
rn = @reaction_network begin
k1, S + I --> 2I
Expand All @@ -382,7 +384,7 @@ let
@test any(isequal(I), unknowns(rn))
end

# Tests backwards and double arrows.
# Tests backwards and bi-directional arrows.
let
rn1 = @reaction_network arrowtest begin
(a1, a2), C <--> 0
Expand All @@ -401,7 +403,7 @@ let
@test rn1 == rn2
end

# Tests arrow variants in "@reaction" macro .
# Tests arrow variants in `@reaction`` macro .
let
@test isequal((@reaction k, 0 --> X), (@reaction k, X <-- 0))
@test isequal((@reaction k, 0 --> X), (@reaction k, X 0))
Expand Down Expand Up @@ -435,15 +437,3 @@ let
@test_throws LoadError @eval @reaction k, 0 --> im
@test_throws LoadError @eval @reaction k, 0 --> nothing
end


### Other Tests ###

# Test names work.
let
rn = @reaction_network SIR1 begin
k1, S + I --> 2I
k2, I --> R
end
@test nameof(rn) == :SIR1
end
61 changes: 58 additions & 3 deletions test/dsl/dsl_options.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ seed = rand(rng, 1:100)
# Sets the default `t` to use.
t = default_t()

### Tests `@parameters` and `@species` Options ###
### Tests `@parameters`, `@species`, and `@variables` Options ###

# Test creating networks with/without options.
let
Expand Down Expand Up @@ -394,6 +394,61 @@ let
@test !ModelingToolkit.hasdescription(unwrap(rn.k5))
end

# Test @variables in DSL.
let
rn = @reaction_network tester begin
@parameters k1
@variables V1(t) V2(t) V3(t)
@species B1(t) B2(t)
(k1*k2 + V3), V1*A + 2*B1 --> V2*C + B2
end

@parameters k1 k2
@variables V1(t) V2(t) V3(t)
@species A(t) B1(t) B2(t) C(t)
rx = Reaction(k1*k2 + V3, [A, B1], [C, B2], [V1, 2], [V2, 1])
@named tester = ReactionSystem([rx], t)
@test tester == rn

sts = (A, B1, B2, C, V1, V2, V3)
spcs = (A, B1, B2, C)
@test issetequal(unknowns(rn), sts)
@test issetequal(species(rn), spcs)

@test_throws ArgumentError begin
rn = @reaction_network begin
@variables K
k, K*A --> B
end
end
end

### Test Independent Variable Designations ###

# Test ivs in DSL.
let
rn = @reaction_network ivstest begin
@ivs s x
@parameters k2
@variables D(x) E(s) F(s,x)
@species A(s,x) B(s) C(x)
k*k2*D, E*A +B --> F*C + C2
end

@parameters k k2
@variables s x D(x) E(s) F(s,x)
@species A(s,x) B(s) C(x) C2(s,x)
rx = Reaction(k*k2*D, [A, B], [C, C2], [E, 1], [F, 1])
@named ivstest = ReactionSystem([rx], s; spatial_ivs = [x])

@test ivstest == rn
@test issetequal(unknowns(rn), [D, E, F, A, B, C, C2])
@test issetequal(species(rn), [A, B, C, C2])
@test isequal(ModelingToolkit.get_iv(rn), s)
@test issetequal(Catalyst.get_sivs(rn), [x])
end


### Observables ###

# Test basic functionality.
Expand Down Expand Up @@ -596,7 +651,7 @@ let
@test length(unknowns(rn2)) == 2
end

# Tests specific declaration of Observables as species/variables
# Tests specific declaration of observables as species/variables.
let
rn = @reaction_network begin
@species X(t)
Expand Down Expand Up @@ -687,7 +742,7 @@ let
end


### Coupled CRN/Equations Models ###
### Test `@equations` Option for Coupled CRN/Equations Models ###

# Checks creation of basic network.
# Check indexing of output solution.
Expand Down
Loading

0 comments on commit 1cfa932

Please sign in to comment.