From 654088c13ba739f78e9f2b818d4d778e4d4ea4c9 Mon Sep 17 00:00:00 2001 From: Sam Isaacson Date: Mon, 28 Oct 2024 10:58:25 -0400 Subject: [PATCH 1/7] try to update CI scripts --- test/extensions/Project.toml | 12 ++ .../extensions/lattice_simulation_plotting.jl | 133 ++++++++++++++++++ test/extensions/stability_computation.jl | 108 ++++++++++++++ 3 files changed, 253 insertions(+) create mode 100644 test/extensions/Project.toml create mode 100644 test/extensions/lattice_simulation_plotting.jl create mode 100644 test/extensions/stability_computation.jl diff --git a/test/extensions/Project.toml b/test/extensions/Project.toml new file mode 100644 index 0000000000..3b6c17bf0a --- /dev/null +++ b/test/extensions/Project.toml @@ -0,0 +1,12 @@ +[deps] +BifurcationKit = "0f109fa4-8a5d-4b75-95aa-f515264e7665" +Catalyst = "479239e8-5488-4da2-87a7-35f2df7eef83" +CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0" +GraphMakie = "1ecd5474-83a3-4783-bb4f-06765db800d2" +Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6" +HomotopyContinuation = "f213a82b-91d6-5c5d-acf7-10f1c761b327" +JumpProcesses = "ccbc3e58-028d-4f4c-8cd5-9ae44345cda5" +ModelingToolkit = "961ee093-0014-501f-94e3-6117800e7a78" +OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed" +SteadyStateDiffEq = "9672c7b4-1e72-59bd-8a11-6ac3964bc41f" +# StructuralIdentifiability = "220ca800-aa68-49bb-acd8-6037fa93a544" diff --git a/test/extensions/lattice_simulation_plotting.jl b/test/extensions/lattice_simulation_plotting.jl new file mode 100644 index 0000000000..0092916748 --- /dev/null +++ b/test/extensions/lattice_simulation_plotting.jl @@ -0,0 +1,133 @@ +### Preparations ### + +# Fetch packages. +using Catalyst, CairoMakie, GraphMakie, Graphs, JumpProcesses, OrdinaryDiffEq, Test + + +### Checks Basic Plot Cases ### + +# Basic test for animations and plots of 1d Cartesian and masked lattice simulations. +# Checks both animations and plots. +# Checks for both ODE and jump simulations. +# TODO: Should be expanded and made more comprehensive. +let + # Creates the `LatticeReactionSystem` model. + rs = @reaction_network begin + (p,d), 0 <--> X + end + diffusion_rx = @transport_reaction D X + for lattice in [CartesianGrid(3), [true, true, false]] + lrs = LatticeReactionSystem(rs, [diffusion_rx], lattice) + + # Simulates the model (using ODE and jumps). + u0 = [:X => [1, 2, 3]] + tspan = (0.0, 1.0) + ps = [:p => 1.0, :d => 1.0, :D => 0.2] + oprob = ODEProblem(lrs, u0, tspan, ps) + osol = solve(oprob, Tsit5()) + dprob = DiscreteProblem(lrs, u0, tspan, ps) + jprob = JumpProblem(lrs, dprob, NSM()) + jsol = solve(jprob, SSAStepper()) + + for sol in [osol, jsol] + # Plots the simulation and checks that a stored value is correct. + fig, ax, plt = lattice_plot(sol, :X, lrs; t = 1.0) + @test plt[1].val[1][2] ≈ sol.u[end][1] + + # Attempts to animate the simulation (using various arguments). Deletes the saved file. + lattice_animation(sol, :X, lrs, "animation_tmp.mp4"; nframes = 10, framerate = 10, colormap = :BuGn_6) + @test isfile("animation_tmp.mp4") + rm("animation_tmp.mp4") + + # Plots the kymograph and checks that a stored value is correct. + fig, ax, hm = lattice_kymograph(sol, :X, lrs) + hm[3].val[end,1] ≈ sol.u[end][1] + end + end +end + +# Basic test for animations and plots of 2d Cartesian and masked lattice simulations. +# Checks both animations and plots. +# Checks for both ODE and jump simulations. +# TODO: Should be expanded and made more comprehensive. +let + # Creates the `LatticeReactionSystem` model. + rs = @reaction_network begin + (p,d), 0 <--> X + end + diffusion_rx = @transport_reaction D X + for lattice in [CartesianGrid((2,2)), [true true; false true]] + lrs = LatticeReactionSystem(rs, [diffusion_rx], lattice) + + # Simulates the model (using ODE and jumps). + u0 = [:X => [1 2; 3 4]] + tspan = (0.0, 1.0) + ps = [:p => 1.0, :d => 1.0, :D => 0.2] + oprob = ODEProblem(lrs, u0, tspan, ps) + osol = solve(oprob, Tsit5()) + dprob = DiscreteProblem(lrs, u0, tspan, ps) + jprob = JumpProblem(lrs, dprob, NSM()) + jsol = solve(jprob, SSAStepper()) + + for sol in [osol, jsol] + # Plots the simulation and checks that a stored value is correct. + fig, ax, hm = lattice_plot(sol, :X, lrs; t = 1.0) + @test hm[3].val[1] ≈ sol.u[end][1] + + # Attempts to animate the simulation (using various arguments). Deletes the saved file. + lattice_animation(sol, :X, lrs, "animation_tmp.mp4"; nframes = 10, framerate = 10, colormap = :BuGn_6) + @test isfile("animation_tmp.mp4") + rm("animation_tmp.mp4") + end + end +end + +# Basic tests that plotting functions yield correct errors for 3d Cartesian and masked lattice simulations. +let + rs = @reaction_network begin + d, X --> 0 + end + diffusion_rx = @transport_reaction D X + lattice = CartesianGrid((2,2,2)) + lrs = LatticeReactionSystem(rs, [diffusion_rx], lattice) + oprob = ODEProblem(lrs, [:X => 1.0], 1.0, [:d => 1.0, :D => 0.2]) + osol = solve(oprob) + + @test_throws ArgumentError lattice_plot(osol, :X, lrs) + @test_throws ArgumentError lattice_animation(osol, :X, lrs, "animation_tmp.mp4") +end + +# Basic test for animations and plots of graph lattices simulations. +# Checks both animations and plots. +# Checks for both ODE and jump simulations. +# TODO: Should be expanded and made more comprehensive. +let + # Creates the `LatticeReactionSystem` model. + rs = @reaction_network begin + (p,d), 0 <--> X + end + diffusion_rx = @transport_reaction D X + lattice = Graphs.SimpleGraphs.cycle_graph(4) + lrs = LatticeReactionSystem(rs, [diffusion_rx], lattice) + + # Simulates the model (using ODE and jumps). + u0 = [:X => [1, 2, 3, 4]] + tspan = (0.0, 1.0) + ps = [:p => 1.0, :d => 1.0, :D => 0.2] + oprob = ODEProblem(lrs, u0, tspan, ps) + osol = solve(oprob, Tsit5()) + dprob = DiscreteProblem(lrs, u0, tspan, ps) + jprob = JumpProblem(lrs, dprob, NSM()) + jsol = solve(jprob, SSAStepper()) + + for sol in [osol, jsol] + # Plots the simulation and checks that a stored value is correct. + fig, ax, plt = lattice_plot(sol, :X, lrs; t = 0.0) + @test plt.node_color[] == osol.u[1] + + # Attempts to animate the simulation (using various arguments). Deletes the saved file. + lattice_animation(sol, :X, lrs, "animation_tmp.mp4"; nframes = 10, framerate = 10, colormap = :BuGn_6) + @test isfile("animation_tmp.mp4") + rm("animation_tmp.mp4") + end +end \ No newline at end of file diff --git a/test/extensions/stability_computation.jl b/test/extensions/stability_computation.jl new file mode 100644 index 0000000000..24ddfe7a29 --- /dev/null +++ b/test/extensions/stability_computation.jl @@ -0,0 +1,108 @@ +### Fetch Packages ### + +# Fetch packages. +using Catalyst, OrdinaryDiffEq, SteadyStateDiffEq, Test +import HomotopyContinuation + +# Sets rnd number. +using StableRNGs +rng = StableRNG(12345) + +### Basic Tests ### + +# Tests that stability is correctly assessed (using simulation) in multi stable system. +# Tests that `steady_state_jac` function works. +# Tests using symbolic input. +let + # System which may have between 1 and 7 fixed points. + rn = @reaction_network begin + v/20.0 + hillar(X,Y,v,K,n), 0 --> X + v/20.0 + hillar(Y,X,v,K,n), 0 --> Y + d, (X,Y) --> 0 + end + ss_jac = steady_state_jac(rn) + + # Repeats several times, most steady state stability cases should be encountered several times. + for repeat = 1:20 + # Generates random parameter values (which can generate all steady states cases). + ps = (:v => 1.0 + 3*rand(rng), :K => 0.5 + 2*rand(rng), :n => rand(rng,[1,2,3,4]), + :d => 0.5 + rand(rng)) + + # Computes stability using various jacobian options. + sss = hc_steady_states(rn, ps; show_progress = false) + stabs_1 = [steady_state_stability(ss, rn, ps) for ss in sss] + stabs_2 = [steady_state_stability(ss, rn, ps; ss_jac = ss_jac) for ss in sss] + + # Confirms stability using simulations. + for (idx, ss) in enumerate(sss) + ssprob = SteadyStateProblem(rn, [1.001, 0.999] .* ss, ps) + sol = solve(ssprob, DynamicSS(Vern7()); abstol = 1e-8, reltol = 1e-8) + stabs_3 = isapprox(ss, sol.u; atol = 1e-6) + @test stabs_1[idx] == stabs_2[idx] == stabs_3 + + # Checks stability when steady state is given on a pair form ([X => x_val, Y => y_val]). + stabs_4 = steady_state_stability(Pair.(unknowns(rn), ss), rn, ps) + @test stabs_3 == stabs_4 + end + end +end + +# Checks stability for system with known stability structure. +# Tests for system with conservation laws. +# Tests for various input forms of u0 and ps. +let + # Creates model. + rn = @reaction_network begin + k1+Z, Y --> 2X + k2, 2X --> X + Y + k3, X + Y --> Y + k4, X --> 0 + (kD1+X, kD2), 2Z <--> Z2 + end + + # Creates various forms of input. + @unpack k1, k2, k3, k4, kD1, kD2, X, Y, Z, Z2 = rn + u0_1 = [X => 1.0, Y => 1.0, Z => 1.0, Z2 => 1.0] + u0_2 = [:X => 1.0, :Y => 1.0, :Z => 1.0, :Z2 => 1.0] + u0_3 = [rn.X => 1.0, rn.Y => 1.0, rn.Z => 1.0, rn.Z2 => 1.0] + u0_4 = [1.0, 1.0, 1.0, 1.0] + ps_1 = [k1 => 8.0, k2 => 2.0, k3 => 1.0, k4 => 1.5, kD1 => 0.5, kD2 => 2.0] + ps_2 = [:k1 => 8.0, :k2 => 2.0, :k3 => 1.0, :k4 => 1.5, :kD1 => 0.5, :kD2 => 2.0] + ps_3 = [rn.k1 => 8.0, rn.k2 => 2.0, rn.k3 => 1.0, rn.k4 => 1.5, rn.kD1 => 0.5, rn.kD2 => 4.0] + + # Computes stability using various input forms, and checks that the output is correct. + sss = hc_steady_states(rn, ps_1; u0 = u0_1, show_progress = false) + for u0 in [u0_1, u0_2, u0_3, u0_4], ps in [ps_1, ps_2, ps_3] + stab_1 = [steady_state_stability(ss, rn, ps) for ss in sss] + ss_jac = steady_state_jac(rn; u0 = u0) + stab_2 = [steady_state_stability(ss, rn, ps; ss_jac = ss_jac) for ss in sss] + @test length(stab_1) == length(stab_2) == 3 + @test count(stab_1) == count(stab_2) == 2 + end + + # Confirms error when computing Jacobian with wrong length of u0. + @test_throws Exception steady_state_jac(rn; u0 = [1.0, 1.0]) +end + +### Other Tests ### + +# Tests `tol` option. In this case, the maximum eigenvalue real part is -1.0, which generates +# and error with `tol = 100`. +let + rn = @reaction_network begin + (p,d), 0 <--> X + end + p = [:p => 1.0, :d => 1.0] + u = [1.0] + @test_throws Exception steady_state_stability(u, rn, p; tol = 1e2) +end + +# Test that stability computation for non-autonomous (t-dependent) systems throws error. +let + rn = @reaction_network begin + (p + 1/(1+t),d), 0 <--> X + end + p = [:p => 1.0, :d => 1.0] + u = [1.0] + @test_throws Exception steady_state_stability(u, rn, p) +end \ No newline at end of file From 89e3a6b050ad3bc0996c5924cf9d21a8e6cbc684 Mon Sep 17 00:00:00 2001 From: Sam Isaacson Date: Mon, 28 Oct 2024 11:00:17 -0400 Subject: [PATCH 2/7] updates --- .github/workflows/CI.yml | 44 ------ .github/workflows/Test.yml | 38 +++++ .../stability_computation.jl | 108 -------------- test/runtests.jl | 138 ++++++++++-------- .../lattice_simulation_plotting.jl | 133 ----------------- 5 files changed, 114 insertions(+), 347 deletions(-) delete mode 100644 .github/workflows/CI.yml create mode 100644 .github/workflows/Test.yml delete mode 100644 test/miscellaneous_tests/stability_computation.jl delete mode 100644 test/spatial_modelling/lattice_simulation_plotting.jl diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml deleted file mode 100644 index e3f54adf5b..0000000000 --- a/.github/workflows/CI.yml +++ /dev/null @@ -1,44 +0,0 @@ -name: CI -on: - pull_request: - branches: - - master - push: - branches: - - master -jobs: - test: - runs-on: ubuntu-latest - strategy: - matrix: - group: - - Core - version: - - '1' - steps: - - uses: actions/checkout@v4 - - uses: julia-actions/setup-julia@v2 - with: - version: ${{ matrix.version }} - - uses: actions/cache@v4 - env: - cache-name: cache-artifacts - with: - path: ~/.julia/artifacts - key: ${{ runner.os }}-test-${{ env.cache-name }}-${{ hashFiles('**/Project.toml') }} - restore-keys: | - ${{ runner.os }}-test-${{ env.cache-name }}- - ${{ runner.os }}-test- - ${{ runner.os }}- - - uses: julia-actions/julia-buildpkg@v1 - - uses: julia-actions/julia-runtest@v1 - - uses: julia-actions/julia-processcoverage@v1 - - uses: codecov/codecov-action@v4 - with: - file: lcov.info - token: ${{ secrets.CODECOV_TOKEN }} - fail_ci_if_error: false - - uses: coverallsapp/github-action@master - with: - github-token: ${{ secrets.GITHUB_TOKEN }} - path-to-lcov: ./lcov.info diff --git a/.github/workflows/Test.yml b/.github/workflows/Test.yml new file mode 100644 index 0000000000..10a62eb3ec --- /dev/null +++ b/.github/workflows/Test.yml @@ -0,0 +1,38 @@ +name: "Tests" + +on: + pull_request: + branches: + - master + push: + branches: + - master + +concurrency: + # Skip intermediate builds: always, but for the master branch. + # Cancel intermediate builds: always, but for the master branch. + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: ${{ github.ref != 'refs/heads/master' }} + +jobs: + tests: + name: "Tests" + strategy: + matrix: + version: + - "1" + - "lts" + - "pre" + group: + - Core + - Spatial + - Extensions + uses: "SciML/.github/.github/workflows/tests.yml@v1" + with: + julia-version: "${{ matrix.version }}" + group: "${{ matrix.group }}" + secrets: "inherit" + uses: coverallsapp/github-action@master + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + path-to-lcov: ./lcov.info diff --git a/test/miscellaneous_tests/stability_computation.jl b/test/miscellaneous_tests/stability_computation.jl deleted file mode 100644 index 24ddfe7a29..0000000000 --- a/test/miscellaneous_tests/stability_computation.jl +++ /dev/null @@ -1,108 +0,0 @@ -### Fetch Packages ### - -# Fetch packages. -using Catalyst, OrdinaryDiffEq, SteadyStateDiffEq, Test -import HomotopyContinuation - -# Sets rnd number. -using StableRNGs -rng = StableRNG(12345) - -### Basic Tests ### - -# Tests that stability is correctly assessed (using simulation) in multi stable system. -# Tests that `steady_state_jac` function works. -# Tests using symbolic input. -let - # System which may have between 1 and 7 fixed points. - rn = @reaction_network begin - v/20.0 + hillar(X,Y,v,K,n), 0 --> X - v/20.0 + hillar(Y,X,v,K,n), 0 --> Y - d, (X,Y) --> 0 - end - ss_jac = steady_state_jac(rn) - - # Repeats several times, most steady state stability cases should be encountered several times. - for repeat = 1:20 - # Generates random parameter values (which can generate all steady states cases). - ps = (:v => 1.0 + 3*rand(rng), :K => 0.5 + 2*rand(rng), :n => rand(rng,[1,2,3,4]), - :d => 0.5 + rand(rng)) - - # Computes stability using various jacobian options. - sss = hc_steady_states(rn, ps; show_progress = false) - stabs_1 = [steady_state_stability(ss, rn, ps) for ss in sss] - stabs_2 = [steady_state_stability(ss, rn, ps; ss_jac = ss_jac) for ss in sss] - - # Confirms stability using simulations. - for (idx, ss) in enumerate(sss) - ssprob = SteadyStateProblem(rn, [1.001, 0.999] .* ss, ps) - sol = solve(ssprob, DynamicSS(Vern7()); abstol = 1e-8, reltol = 1e-8) - stabs_3 = isapprox(ss, sol.u; atol = 1e-6) - @test stabs_1[idx] == stabs_2[idx] == stabs_3 - - # Checks stability when steady state is given on a pair form ([X => x_val, Y => y_val]). - stabs_4 = steady_state_stability(Pair.(unknowns(rn), ss), rn, ps) - @test stabs_3 == stabs_4 - end - end -end - -# Checks stability for system with known stability structure. -# Tests for system with conservation laws. -# Tests for various input forms of u0 and ps. -let - # Creates model. - rn = @reaction_network begin - k1+Z, Y --> 2X - k2, 2X --> X + Y - k3, X + Y --> Y - k4, X --> 0 - (kD1+X, kD2), 2Z <--> Z2 - end - - # Creates various forms of input. - @unpack k1, k2, k3, k4, kD1, kD2, X, Y, Z, Z2 = rn - u0_1 = [X => 1.0, Y => 1.0, Z => 1.0, Z2 => 1.0] - u0_2 = [:X => 1.0, :Y => 1.0, :Z => 1.0, :Z2 => 1.0] - u0_3 = [rn.X => 1.0, rn.Y => 1.0, rn.Z => 1.0, rn.Z2 => 1.0] - u0_4 = [1.0, 1.0, 1.0, 1.0] - ps_1 = [k1 => 8.0, k2 => 2.0, k3 => 1.0, k4 => 1.5, kD1 => 0.5, kD2 => 2.0] - ps_2 = [:k1 => 8.0, :k2 => 2.0, :k3 => 1.0, :k4 => 1.5, :kD1 => 0.5, :kD2 => 2.0] - ps_3 = [rn.k1 => 8.0, rn.k2 => 2.0, rn.k3 => 1.0, rn.k4 => 1.5, rn.kD1 => 0.5, rn.kD2 => 4.0] - - # Computes stability using various input forms, and checks that the output is correct. - sss = hc_steady_states(rn, ps_1; u0 = u0_1, show_progress = false) - for u0 in [u0_1, u0_2, u0_3, u0_4], ps in [ps_1, ps_2, ps_3] - stab_1 = [steady_state_stability(ss, rn, ps) for ss in sss] - ss_jac = steady_state_jac(rn; u0 = u0) - stab_2 = [steady_state_stability(ss, rn, ps; ss_jac = ss_jac) for ss in sss] - @test length(stab_1) == length(stab_2) == 3 - @test count(stab_1) == count(stab_2) == 2 - end - - # Confirms error when computing Jacobian with wrong length of u0. - @test_throws Exception steady_state_jac(rn; u0 = [1.0, 1.0]) -end - -### Other Tests ### - -# Tests `tol` option. In this case, the maximum eigenvalue real part is -1.0, which generates -# and error with `tol = 100`. -let - rn = @reaction_network begin - (p,d), 0 <--> X - end - p = [:p => 1.0, :d => 1.0] - u = [1.0] - @test_throws Exception steady_state_stability(u, rn, p; tol = 1e2) -end - -# Test that stability computation for non-autonomous (t-dependent) systems throws error. -let - rn = @reaction_network begin - (p + 1/(1+t),d), 0 <--> X - end - p = [:p => 1.0, :d => 1.0] - u = [1.0] - @test_throws Exception steady_state_stability(u, rn, p) -end \ No newline at end of file diff --git a/test/runtests.jl b/test/runtests.jl index fd4e69c486..a893918172 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -4,75 +4,89 @@ using SafeTestsets, Test # Required for running parallel test groups (copied from ModelingToolkit). -#const GROUP = get(ENV, "GROUP", "All") +const GROUP = get(ENV, "GROUP", "All") +function activate_extensions_env() + Pkg.activate("extensions") + Pkg.develop(PackageSpec(path = dirname(@__DIR__))) + Pkg.instantiate() +end ### Run Tests ### @time begin + if GROUP == "All" || GROUP == "Core" + # Tests the `ReactionSystem` structure and its properties. + @time @safetestset "Reaction Structure" begin include("reactionsystem_core/reaction.jl") end + @time @safetestset "ReactionSystem Structure" begin include("reactionsystem_core/reactionsystem.jl") end + @time @safetestset "Higher Order Reactions" begin include("reactionsystem_core/higher_order_reactions.jl") end + @time @safetestset "Symbolic Stoichiometry" begin include("reactionsystem_core/symbolic_stoichiometry.jl") end + @time @safetestset "Parameter Type Designation" begin include("reactionsystem_core/parameter_type_designation.jl") end + @time @safetestset "Custom CRN Functions" begin include("reactionsystem_core/custom_crn_functions.jl") end + @time @safetestset "Coupled CRN/Equation Systems" begin include("reactionsystem_core/coupled_equation_crn_systems.jl") end + @time @safetestset "Events" begin include("reactionsystem_core/events.jl") end + + # Tests model creation via the @reaction_network DSL. + @time @safetestset "DSL Basic Model Construction" begin include("dsl/dsl_basic_model_construction.jl") end + @time @safetestset "DSL Advanced Model Construction" begin include("dsl/dsl_advanced_model_construction.jl") end + @time @safetestset "DSL Options" begin include("dsl/dsl_options.jl") end + + # Tests compositional and hierarchical modelling. + @time @safetestset "ReactionSystem Components Based Creation" begin include("compositional_modelling/component_based_model_creation.jl") end + + # Tests various miscellaneous features. + @time @safetestset "API" begin include("miscellaneous_tests/api.jl") end + @time @safetestset "Units" begin include("miscellaneous_tests/units.jl") end + @time @safetestset "Compound Species" begin include("miscellaneous_tests/compound_macro.jl") end + @time @safetestset "Reaction Balancing" begin include("miscellaneous_tests/reaction_balancing.jl") end + @time @safetestset "ReactionSystem Serialisation" begin include("miscellaneous_tests/reactionsystem_serialisation.jl") end + + # Tests reaction network analysis features. + @time @safetestset "Conservation Laws" begin include("network_analysis/conservation_laws.jl") end + @time @safetestset "Network Properties" begin include("network_analysis/network_properties.jl") end + + # Tests ODE, SDE, jump simulations, nonlinear solving, and steady state simulations. + @time @safetestset "ODE System Simulations" begin include("simulation_and_solving/simulate_ODEs.jl") end + @time @safetestset "Automatic Jacobian Construction" begin include("simulation_and_solving/jacobian_construction.jl") end + @time @safetestset "SDE System Simulations" begin include("simulation_and_solving/simulate_SDEs.jl") end + @time @safetestset "Jump System Simulations" begin include("simulation_and_solving/simulate_jumps.jl") end + @time @safetestset "Nonlinear and SteadyState System Solving" begin include("simulation_and_solving/solve_nonlinear.jl") end + + # Tests upstream SciML and DiffEq stuff. + @time @safetestset "MTK Structure Indexing" begin include("upstream/mtk_structure_indexing.jl") end + @time @safetestset "MTK Problem Inputs" begin include("upstream/mtk_problem_inputs.jl") end + + # Tests network visualisation. + # @time @safetestset "Latexify" begin include("visualisation/latexify.jl") end + # Disable on Macs as can't install GraphViz via jll + if !Sys.isapple() + @time @safetestset "Graphs Visualisations" begin include("visualisation/graphs.jl") end + end + end - # Tests the `ReactionSystem` structure and its properties. - @time @safetestset "Reaction Structure" begin include("reactionsystem_core/reaction.jl") end - @time @safetestset "ReactionSystem Structure" begin include("reactionsystem_core/reactionsystem.jl") end - @time @safetestset "Higher Order Reactions" begin include("reactionsystem_core/higher_order_reactions.jl") end - @time @safetestset "Symbolic Stoichiometry" begin include("reactionsystem_core/symbolic_stoichiometry.jl") end - @time @safetestset "Parameter Type Designation" begin include("reactionsystem_core/parameter_type_designation.jl") end - @time @safetestset "Custom CRN Functions" begin include("reactionsystem_core/custom_crn_functions.jl") end - @time @safetestset "Coupled CRN/Equation Systems" begin include("reactionsystem_core/coupled_equation_crn_systems.jl") end - @time @safetestset "Events" begin include("reactionsystem_core/events.jl") end - - # Tests model creation via the @reaction_network DSL. - @time @safetestset "DSL Basic Model Construction" begin include("dsl/dsl_basic_model_construction.jl") end - @time @safetestset "DSL Advanced Model Construction" begin include("dsl/dsl_advanced_model_construction.jl") end - @time @safetestset "DSL Options" begin include("dsl/dsl_options.jl") end - - # Tests compositional and hierarchical modelling. - @time @safetestset "ReactionSystem Components Based Creation" begin include("compositional_modelling/component_based_model_creation.jl") end - - # Tests various miscellaneous features. - @time @safetestset "API" begin include("miscellaneous_tests/api.jl") end - @time @safetestset "Units" begin include("miscellaneous_tests/units.jl") end - @time @safetestset "Compound Species" begin include("miscellaneous_tests/compound_macro.jl") end - @time @safetestset "Reaction Balancing" begin include("miscellaneous_tests/reaction_balancing.jl") end - @time @safetestset "ReactionSystem Serialisation" begin include("miscellaneous_tests/reactionsystem_serialisation.jl") end - - # Tests reaction network analysis features. - @time @safetestset "Conservation Laws" begin include("network_analysis/conservation_laws.jl") end - @time @safetestset "Network Properties" begin include("network_analysis/network_properties.jl") end - - # Tests ODE, SDE, jump simulations, nonlinear solving, and steady state simulations. - @time @safetestset "ODE System Simulations" begin include("simulation_and_solving/simulate_ODEs.jl") end - @time @safetestset "Automatic Jacobian Construction" begin include("simulation_and_solving/jacobian_construction.jl") end - @time @safetestset "SDE System Simulations" begin include("simulation_and_solving/simulate_SDEs.jl") end - @time @safetestset "Jump System Simulations" begin include("simulation_and_solving/simulate_jumps.jl") end - @time @safetestset "Nonlinear and SteadyState System Solving" begin include("simulation_and_solving/solve_nonlinear.jl") end - - # Tests upstream SciML and DiffEq stuff. - @time @safetestset "MTK Structure Indexing" begin include("upstream/mtk_structure_indexing.jl") end - @time @safetestset "MTK Problem Inputs" begin include("upstream/mtk_problem_inputs.jl") end - - # Tests network visualisation. - # @time @safetestset "Latexify" begin include("visualisation/latexify.jl") end - # Disable on Macs as can't install GraphViz via jll - if !Sys.isapple() - @time @safetestset "Graphs Visualisations" begin include("visualisation/graphs.jl") end + if GROUP == "All" || GROUP == "Spatial" + # Tests spatial modelling and simulations. + @time @safetestset "PDE Systems Simulations" begin include("spatial_modelling/simulate_PDEs.jl") end + @time @safetestset "Spatial Reactions" begin include("spatial_modelling/spatial_reactions.jl") end + @time @safetestset "Lattice Reaction Systems" begin include("spatial_modelling/lattice_reaction_systems.jl") end + @time @safetestset "Spatial Lattice Variants" begin include("spatial_modelling/lattice_reaction_systems_lattice_types.jl") end + @time @safetestset "ODE Lattice Systems Simulations" begin include("spatial_modelling/lattice_reaction_systems_ODEs.jl") end + @time @safetestset "Jump Lattice Systems Simulations" begin include("spatial_modelling/lattice_reaction_systems_jumps.jl") end + @time @safetestset "Lattice Simulation Structure Interfacing" begin include("spatial_modelling/lattice_simulation_struct_interfacing.jl") end end # Tests extensions. - @time @safetestset "BifurcationKit Extension" begin include("extensions/bifurcation_kit.jl") end - @time @safetestset "HomotopyContinuation Extension" begin include("extensions/homotopy_continuation.jl") end - # @time @safetestset "Structural Identifiability Extension" begin include("extensions/structural_identifiability.jl") end - - # Tests stability computation (uses HomotopyContinuation extension). - @time @safetestset "Steady State Stability Computations" begin include("miscellaneous_tests/stability_computation.jl") end - - # Tests spatial modelling and simulations. - @time @safetestset "PDE Systems Simulations" begin include("spatial_modelling/simulate_PDEs.jl") end - @time @safetestset "Spatial Reactions" begin include("spatial_modelling/spatial_reactions.jl") end - @time @safetestset "Lattice Reaction Systems" begin include("spatial_modelling/lattice_reaction_systems.jl") end - @time @safetestset "Spatial Lattice Variants" begin include("spatial_modelling/lattice_reaction_systems_lattice_types.jl") end - @time @safetestset "ODE Lattice Systems Simulations" begin include("spatial_modelling/lattice_reaction_systems_ODEs.jl") end - @time @safetestset "Jump Lattice Systems Simulations" begin include("spatial_modelling/lattice_reaction_systems_jumps.jl") end - @time @safetestset "Lattice Simulation Structure Interfacing" begin include("spatial_modelling/lattice_simulation_struct_interfacing.jl") end - @time @safetestset "Lattice Simulation Plotting" begin include("spatial_modelling/lattice_simulation_plotting.jl") end + if GROUP == "All" || GROUP == "Extensions" + activate_extensions_env() + + @time @safetestset "BifurcationKit Extension" begin include("extensions/bifurcation_kit.jl") end + @time @safetestset "HomotopyContinuation Extension" begin include("extensions/homotopy_continuation.jl") end + # @time @safetestset "Structural Identifiability Extension" begin include("extensions/structural_identifiability.jl") end + + # Tests stability computation (but requires the HomotopyContinuation extension). + @time @safetestset "Steady State Stability Computations" begin include("extensions/stability_computation.jl") end + + # Test spatial plotting, using CarioMakie and GraphMakie + @time @safetestset "Lattice Simulation Plotting" begin include("extensions/lattice_simulation_plotting.jl") end + end end # @time diff --git a/test/spatial_modelling/lattice_simulation_plotting.jl b/test/spatial_modelling/lattice_simulation_plotting.jl deleted file mode 100644 index 0092916748..0000000000 --- a/test/spatial_modelling/lattice_simulation_plotting.jl +++ /dev/null @@ -1,133 +0,0 @@ -### Preparations ### - -# Fetch packages. -using Catalyst, CairoMakie, GraphMakie, Graphs, JumpProcesses, OrdinaryDiffEq, Test - - -### Checks Basic Plot Cases ### - -# Basic test for animations and plots of 1d Cartesian and masked lattice simulations. -# Checks both animations and plots. -# Checks for both ODE and jump simulations. -# TODO: Should be expanded and made more comprehensive. -let - # Creates the `LatticeReactionSystem` model. - rs = @reaction_network begin - (p,d), 0 <--> X - end - diffusion_rx = @transport_reaction D X - for lattice in [CartesianGrid(3), [true, true, false]] - lrs = LatticeReactionSystem(rs, [diffusion_rx], lattice) - - # Simulates the model (using ODE and jumps). - u0 = [:X => [1, 2, 3]] - tspan = (0.0, 1.0) - ps = [:p => 1.0, :d => 1.0, :D => 0.2] - oprob = ODEProblem(lrs, u0, tspan, ps) - osol = solve(oprob, Tsit5()) - dprob = DiscreteProblem(lrs, u0, tspan, ps) - jprob = JumpProblem(lrs, dprob, NSM()) - jsol = solve(jprob, SSAStepper()) - - for sol in [osol, jsol] - # Plots the simulation and checks that a stored value is correct. - fig, ax, plt = lattice_plot(sol, :X, lrs; t = 1.0) - @test plt[1].val[1][2] ≈ sol.u[end][1] - - # Attempts to animate the simulation (using various arguments). Deletes the saved file. - lattice_animation(sol, :X, lrs, "animation_tmp.mp4"; nframes = 10, framerate = 10, colormap = :BuGn_6) - @test isfile("animation_tmp.mp4") - rm("animation_tmp.mp4") - - # Plots the kymograph and checks that a stored value is correct. - fig, ax, hm = lattice_kymograph(sol, :X, lrs) - hm[3].val[end,1] ≈ sol.u[end][1] - end - end -end - -# Basic test for animations and plots of 2d Cartesian and masked lattice simulations. -# Checks both animations and plots. -# Checks for both ODE and jump simulations. -# TODO: Should be expanded and made more comprehensive. -let - # Creates the `LatticeReactionSystem` model. - rs = @reaction_network begin - (p,d), 0 <--> X - end - diffusion_rx = @transport_reaction D X - for lattice in [CartesianGrid((2,2)), [true true; false true]] - lrs = LatticeReactionSystem(rs, [diffusion_rx], lattice) - - # Simulates the model (using ODE and jumps). - u0 = [:X => [1 2; 3 4]] - tspan = (0.0, 1.0) - ps = [:p => 1.0, :d => 1.0, :D => 0.2] - oprob = ODEProblem(lrs, u0, tspan, ps) - osol = solve(oprob, Tsit5()) - dprob = DiscreteProblem(lrs, u0, tspan, ps) - jprob = JumpProblem(lrs, dprob, NSM()) - jsol = solve(jprob, SSAStepper()) - - for sol in [osol, jsol] - # Plots the simulation and checks that a stored value is correct. - fig, ax, hm = lattice_plot(sol, :X, lrs; t = 1.0) - @test hm[3].val[1] ≈ sol.u[end][1] - - # Attempts to animate the simulation (using various arguments). Deletes the saved file. - lattice_animation(sol, :X, lrs, "animation_tmp.mp4"; nframes = 10, framerate = 10, colormap = :BuGn_6) - @test isfile("animation_tmp.mp4") - rm("animation_tmp.mp4") - end - end -end - -# Basic tests that plotting functions yield correct errors for 3d Cartesian and masked lattice simulations. -let - rs = @reaction_network begin - d, X --> 0 - end - diffusion_rx = @transport_reaction D X - lattice = CartesianGrid((2,2,2)) - lrs = LatticeReactionSystem(rs, [diffusion_rx], lattice) - oprob = ODEProblem(lrs, [:X => 1.0], 1.0, [:d => 1.0, :D => 0.2]) - osol = solve(oprob) - - @test_throws ArgumentError lattice_plot(osol, :X, lrs) - @test_throws ArgumentError lattice_animation(osol, :X, lrs, "animation_tmp.mp4") -end - -# Basic test for animations and plots of graph lattices simulations. -# Checks both animations and plots. -# Checks for both ODE and jump simulations. -# TODO: Should be expanded and made more comprehensive. -let - # Creates the `LatticeReactionSystem` model. - rs = @reaction_network begin - (p,d), 0 <--> X - end - diffusion_rx = @transport_reaction D X - lattice = Graphs.SimpleGraphs.cycle_graph(4) - lrs = LatticeReactionSystem(rs, [diffusion_rx], lattice) - - # Simulates the model (using ODE and jumps). - u0 = [:X => [1, 2, 3, 4]] - tspan = (0.0, 1.0) - ps = [:p => 1.0, :d => 1.0, :D => 0.2] - oprob = ODEProblem(lrs, u0, tspan, ps) - osol = solve(oprob, Tsit5()) - dprob = DiscreteProblem(lrs, u0, tspan, ps) - jprob = JumpProblem(lrs, dprob, NSM()) - jsol = solve(jprob, SSAStepper()) - - for sol in [osol, jsol] - # Plots the simulation and checks that a stored value is correct. - fig, ax, plt = lattice_plot(sol, :X, lrs; t = 0.0) - @test plt.node_color[] == osol.u[1] - - # Attempts to animate the simulation (using various arguments). Deletes the saved file. - lattice_animation(sol, :X, lrs, "animation_tmp.mp4"; nframes = 10, framerate = 10, colormap = :BuGn_6) - @test isfile("animation_tmp.mp4") - rm("animation_tmp.mp4") - end -end \ No newline at end of file From 2120ee3ccfcb456add3363565656c7061573fa9e Mon Sep 17 00:00:00 2001 From: Sam Isaacson Date: Mon, 28 Oct 2024 11:09:31 -0400 Subject: [PATCH 3/7] remove coveralls --- .github/workflows/Test.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/workflows/Test.yml b/.github/workflows/Test.yml index 10a62eb3ec..2c9b4d3fdf 100644 --- a/.github/workflows/Test.yml +++ b/.github/workflows/Test.yml @@ -32,7 +32,3 @@ jobs: julia-version: "${{ matrix.version }}" group: "${{ matrix.group }}" secrets: "inherit" - uses: coverallsapp/github-action@master - with: - github-token: ${{ secrets.GITHUB_TOKEN }} - path-to-lcov: ./lcov.info From 1e1b27799e37787d5be9828edce5c09277ca1e24 Mon Sep 17 00:00:00 2001 From: Sam Isaacson Date: Mon, 28 Oct 2024 11:26:28 -0400 Subject: [PATCH 4/7] updates --- .github/workflows/Test.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/Test.yml b/.github/workflows/Test.yml index 2c9b4d3fdf..b6328c8d6d 100644 --- a/.github/workflows/Test.yml +++ b/.github/workflows/Test.yml @@ -4,10 +4,14 @@ on: pull_request: branches: - master + paths-ignore: + - 'docs/**' push: branches: - master - + paths-ignore: + - 'docs/**' + concurrency: # Skip intermediate builds: always, but for the master branch. # Cancel intermediate builds: always, but for the master branch. @@ -18,6 +22,7 @@ jobs: tests: name: "Tests" strategy: + fail-fast: false matrix: version: - "1" From 8caf54a5b9d49a983f8b0045be8d262f0fa4e1da Mon Sep 17 00:00:00 2001 From: Sam Isaacson Date: Mon, 28 Oct 2024 11:28:58 -0400 Subject: [PATCH 5/7] update targets --- Project.toml | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/Project.toml b/Project.toml index c100c1b450..104b09556a 100644 --- a/Project.toml +++ b/Project.toml @@ -71,13 +71,9 @@ Unitful = "1.12.4" julia = "1.10" [extras] -BifurcationKit = "0f109fa4-8a5d-4b75-95aa-f515264e7665" -CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0" DiffEqCallbacks = "459566f4-90b8-5000-8ac3-15dfb0a30def" DomainSets = "5b8099bc-c8ec-5219-889f-1d9e522a28bf" -GraphMakie = "1ecd5474-83a3-4783-bb4f-06765db800d2" Graphviz_jll = "3c863552-8265-54e4-a6dc-903eb78fde85" -HomotopyContinuation = "f213a82b-91d6-5c5d-acf7-10f1c761b327" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" Logging = "56ddb016-857b-54e1-b83d-db4d58db5568" NonlinearSolve = "8913a72c-1f9b-4ce2-8d82-65094dcecaec" @@ -92,9 +88,11 @@ StaticArrays = "90137ffa-7385-5640-81b9-e52037218182" Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" SteadyStateDiffEq = "9672c7b4-1e72-59bd-8a11-6ac3964bc41f" StochasticDiffEq = "789caeaf-c7a9-5a7d-9973-96adeb23e2a0" -# StructuralIdentifiability = "220ca800-aa68-49bb-acd8-6037fa93a544" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d" [targets] -test = ["BifurcationKit", "CairoMakie", "DiffEqCallbacks", "DomainSets", "Graphviz_jll", "HomotopyContinuation", "Logging", "GraphMakie", "NonlinearSolve", "OrdinaryDiffEq", "Plots", "Random", "SafeTestsets", "SciMLBase", "SciMLNLSolve", "StableRNGs", "StaticArrays", "Statistics", "SteadyStateDiffEq", "StochasticDiffEq", "Test", "Unitful"] +test = ["DiffEqCallbacks", "DomainSets", "Graphviz_jll", "Logging", "NonlinearSolve", + "OrdinaryDiffEq", "Plots", "Random", "SafeTestsets", "SciMLBase", "SciMLNLSolve", + "StableRNGs", "StaticArrays", "Statistics", "SteadyStateDiffEq", "StochasticDiffEq", + "Test", "Unitful"] From 8f20b4cf6db2b62edb59eed0dbd80e6c1abe4f5c Mon Sep 17 00:00:00 2001 From: Sam Isaacson Date: Mon, 28 Oct 2024 11:41:08 -0400 Subject: [PATCH 6/7] add Pkg --- test/runtests.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/runtests.jl b/test/runtests.jl index a893918172..ab3afab8c9 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,7 +1,7 @@ ### Preparations ### # Required for `@safetestset` and `@testset`, respectively. -using SafeTestsets, Test +using SafeTestsets, Test, Pkg # Required for running parallel test groups (copied from ModelingToolkit). const GROUP = get(ENV, "GROUP", "All") From 24b54365ee15947f51b71b90161f079f2e9e89d4 Mon Sep 17 00:00:00 2001 From: Sam Isaacson Date: Mon, 28 Oct 2024 11:53:01 -0400 Subject: [PATCH 7/7] make pkg a test dep --- Project.toml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 104b09556a..e87278e3d7 100644 --- a/Project.toml +++ b/Project.toml @@ -78,6 +78,7 @@ LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" Logging = "56ddb016-857b-54e1-b83d-db4d58db5568" NonlinearSolve = "8913a72c-1f9b-4ce2-8d82-65094dcecaec" OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed" +Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80" Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f" @@ -93,6 +94,6 @@ Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d" [targets] test = ["DiffEqCallbacks", "DomainSets", "Graphviz_jll", "Logging", "NonlinearSolve", - "OrdinaryDiffEq", "Plots", "Random", "SafeTestsets", "SciMLBase", "SciMLNLSolve", + "OrdinaryDiffEq", "Pkg", "Plots", "Random", "SafeTestsets", "SciMLBase", "SciMLNLSolve", "StableRNGs", "StaticArrays", "Statistics", "SteadyStateDiffEq", "StochasticDiffEq", "Test", "Unitful"]