Skip to content

Commit c2b8654

Browse files
committed
Merge branch 'master' into graph-docs
2 parents 32e4c73 + e357827 commit c2b8654

File tree

8 files changed

+46
-46
lines changed

8 files changed

+46
-46
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ an ordinary differential equation.
9292

9393
```julia
9494
# Fetch required packages.
95-
using Catalyst, OrdinaryDiffEq, Plots
95+
using Catalyst, OrdinaryDiffEqDefault, Plots
9696

9797
# Create model.
9898
model = @reaction_network begin

ext/CatalystGraphMakieExtension/rn_graph_plot.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ Notes:
7676
red arrow from `A` to the reaction node. In `k*A, A+B --> C`, there would be
7777
red and black arrows from `A` to the reaction node.
7878
"""
79-
# TODO: update docs for interacting with plots. The `interactive` flag sets the ability to interactively drag nodes and edges in the generated plot. Only allowed if `GLMakie` is the loaded Makie backend.
8079
function Catalyst.plot_network(rn::ReactionSystem)
8180
srg = SRGraphWrap(rn)
8281
ns = length(species(rn))

src/spatial_reaction_systems/lattice_reaction_systems.jl

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const GridLattice{N, T} = Union{Array{Bool, N}, CartesianGridRej{N, T}}
88
"""
99
$(TYPEDEF)
1010
11-
A representation of a spatial system of chemical reactions on a discrete (lattice) space.
11+
A representation of a spatial system of chemical reactions on a discrete (lattice) space.
1212
1313
# Fields
1414
$(FIELDS)
@@ -20,7 +20,7 @@ Arguments:
2020
to which the non-spatial model is expanded.
2121
2222
Keyword Arguments:
23-
- `diagonal_connections = false`: Only relevant for Cartesian and masked lattices. If `true`,
23+
- `diagonal_connections = false`: Only relevant for Cartesian and masked lattices. If `true`,
2424
diagonally adjacent compartments are considered adjacent, and spatial reactions in between these
2525
are possible.
2626
@@ -82,12 +82,12 @@ struct LatticeReactionSystem{Q, R, S, T} <: MT.AbstractTimeDependentSystem
8282
"""
8383
parameters::Vector{Any}
8484
"""
85-
Parameters which values are tied to vertices,
85+
Parameters which values are tied to vertices,
8686
e.g. that possibly could have unique values at each vertex of the system.
8787
"""
8888
vertex_parameters::Vector{Any}
8989
"""
90-
Parameters whose values are tied to edges (adjacencies),
90+
Parameters whose values are tied to edges (adjacencies),
9191
e.g. that possibly could have unique values at each edge of the system.
9292
"""
9393
edge_parameters::Vector{Any}
@@ -108,23 +108,23 @@ struct LatticeReactionSystem{Q, R, S, T} <: MT.AbstractTimeDependentSystem
108108
if !iscomplete(rs)
109109
throw(ArgumentError("A non-complete `ReactionSystem` was used as input, this is not permitted."))
110110
end
111-
if !isempty(MT.get_systems(rs))
112-
throw(ArgumentError("A non-flattened (hierarchical) `ReactionSystem` was used as input. `LatticeReactionSystem`s can only be based on non-hierarchical `ReactionSystem`s."))
113-
end
114111
if length(reactions(rs)) != length(equations(rs))
115112
throw(ArgumentError("The `ReactionSystem` used as input contain equations (in addition to reactions). This is not permitted."))
116113
end
117114
if length(species(rs)) != length(unknowns(rs))
118115
throw(ArgumentError("The `ReactionSystem` used as input contain variable unknowns (in addition to species unknowns). This is not permitted (the input `ReactionSystem` must contain species unknowns only)."))
119116
end
120117
if !isempty(MT.continuous_events(rs)) || !isempty(MT.discrete_events(rs))
121-
throw(ArgumentError("The `ReactionSystem` used as input to `LatticeReactionSystem contain events. These will be ignored in any simulations based on the created `LatticeReactionSystem`."))
118+
throw(ArgumentError("The `ReactionSystem` used as input to `LatticeReactionSystem` contain events. These will be ignored in any simulations based on the created `LatticeReactionSystem`."))
119+
end
120+
if !isnothing(MT.get_parent(rs)) && !isempty(MT.get_systems(MT.get_parent(rs)))
121+
@warn "The `ReactionSystem` used as input to `LatticeReactionSystem` was originally created as a hierarchical model. While this won't necessarily result in errors, it has not been well-tested, and is not recommended."
122122
end
123123
if !isempty(observed(rs))
124-
@warn "The `ReactionSystem` used as input to `LatticeReactionSystem contain observables. It will not be possible to access these from the created `LatticeReactionSystem`."
124+
@warn "The `ReactionSystem` used as input to `LatticeReactionSystem` contain observables. It will not be possible to access these from the created `LatticeReactionSystem`."
125125
end
126126

127-
# Computes the species which are parts of spatial reactions. Also counts the total number of
127+
# Computes the species which are parts of spatial reactions. Also counts the total number of
128128
# species types.
129129
if isempty(spatial_reactions)
130130
spat_species = Vector{BasicSymbolic{Real}}[]
@@ -171,7 +171,7 @@ function LatticeReactionSystem(rs, srs, lattice::SimpleGraph)
171171
LatticeReactionSystem(rs, srs, DiGraph(lattice))
172172
end
173173

174-
# Creates a LatticeReactionSystem from a CartesianGrid lattice (cartesian grid) or a Boolean Array
174+
# Creates a LatticeReactionSystem from a CartesianGrid lattice (cartesian grid) or a Boolean Array
175175
# lattice (masked grid). These two are quite similar, so much code can be reused in a single interface.
176176
function LatticeReactionSystem(rs, srs, lattice::GridLattice{N, T};
177177
diagonal_connections = false) where {N, T}
@@ -226,7 +226,7 @@ function count_edges(grid::CartesianGridRej{N, T};
226226
return num_edges
227227
end
228228

229-
# Counts and edges on a masked grid. Does so by looping through all the vertices of the grid,
229+
# Counts and edges on a masked grid. Does so by looping through all the vertices of the grid,
230230
# finding their neighbours, and updating the edge count accordingly.
231231
function count_edges(grid::Array{Bool, N}; diagonal_connections = false) where {N}
232232
g_size = grid_size(grid)
@@ -239,7 +239,7 @@ function count_edges(grid::Array{Bool, N}; diagonal_connections = false) where {
239239
return num_edges
240240
end
241241

242-
# For a (1d, 2d, or 3d) (Cartesian or masked) grid, returns a vector and an array, permitting the
242+
# For a (1d, 2d, or 3d) (Cartesian or masked) grid, returns a vector and an array, permitting the
243243
# conversion between a vertex's flat (scalar) and grid indices. E.g. for a 2d grid, if grid point (3,2)
244244
# corresponds to the fifth vertex, then `flat_to_grid_idx[5] = (3,2)` and `grid_to_flat_idx[3,2] = 5`.
245245
function get_index_converters(grid::GridLattice{N, T}, num_verts) where {N, T}
@@ -335,7 +335,7 @@ num_verts(lrs::LatticeReactionSystem) = getfield(lrs, :num_verts)
335335
"""
336336
num_edges(lrs::LatticeReactionSystem)
337337
338-
Returns the number of edges (i.e. connections between vertices) in the lattice stored in a
338+
Returns the number of edges (i.e. connections between vertices) in the lattice stored in a
339339
`LatticeReactionSystem`.
340340
"""
341341
num_edges(lrs::LatticeReactionSystem) = getfield(lrs, :num_edges)
@@ -392,7 +392,7 @@ end
392392
"""
393393
has_cartesian_lattice(lrs::LatticeReactionSystem)
394394
395-
Returns `true` if `lrs` was created using a cartesian grid lattice (e.g. created via `CartesianGrid(5,5)`).
395+
Returns `true` if `lrs` was created using a cartesian grid lattice (e.g. created via `CartesianGrid(5,5)`).
396396
Otherwise, returns `false`.
397397
"""
398398
has_cartesian_lattice(lrs::LatticeReactionSystem) = lattice(lrs) isa
@@ -401,7 +401,7 @@ has_cartesian_lattice(lrs::LatticeReactionSystem) = lattice(lrs) isa
401401
"""
402402
has_masked_lattice(lrs::LatticeReactionSystem)
403403
404-
Returns `true` if `lrs` was created using a masked grid lattice (e.g. created via `[true true; true false]`).
404+
Returns `true` if `lrs` was created using a masked grid lattice (e.g. created via `[true true; true false]`).
405405
Otherwise, returns `false`.
406406
"""
407407
has_masked_lattice(lrs::LatticeReactionSystem) = lattice(lrs) isa Array{Bool, N} where {N}
@@ -418,15 +418,15 @@ end
418418
"""
419419
has_graph_lattice(lrs::LatticeReactionSystem)
420420
421-
Returns `true` if `lrs` was created using a graph grid lattice (e.g. created via `path_graph(5)`).
421+
Returns `true` if `lrs` was created using a graph grid lattice (e.g. created via `path_graph(5)`).
422422
Otherwise, returns `false`.
423423
"""
424424
has_graph_lattice(lrs::LatticeReactionSystem) = lattice(lrs) isa SimpleDiGraph
425425

426426
"""
427427
grid_size(lrs::LatticeReactionSystem)
428428
429-
Returns the size of `lrs`'s lattice (only if it is a cartesian or masked grid lattice).
429+
Returns the size of `lrs`'s lattice (only if it is a cartesian or masked grid lattice).
430430
E.g. for a lattice `CartesianGrid(4,6)`, `(4,6)` is returned.
431431
"""
432432
grid_size(lrs::LatticeReactionSystem) = grid_size(lattice(lrs))
@@ -439,7 +439,7 @@ end
439439
"""
440440
grid_dims(lrs::LatticeReactionSystem)
441441
442-
Returns the number of dimensions of `lrs`'s lattice (only if it is a cartesian or masked grid lattice).
442+
Returns the number of dimensions of `lrs`'s lattice (only if it is a cartesian or masked grid lattice).
443443
The output is either `1`, `2`, or `3`.
444444
"""
445445
grid_dims(lrs::LatticeReactionSystem) = grid_dims(lattice(lrs))
@@ -506,19 +506,19 @@ end
506506
"""
507507
make_edge_p_values(lrs::LatticeReactionSystem, make_edge_p_value::Function)
508508
509-
Generates edge parameter values for a lattice reaction system. Only work for (Cartesian or masked)
510-
grid lattices (without diagonal adjacencies).
509+
Generates edge parameter values for a lattice reaction system. Only work for (Cartesian or masked)
510+
grid lattices (without diagonal adjacencies).
511511
512512
Input:
513513
- `lrs`: The lattice reaction system for which values should be generated.
514514
- `make_edge_p_value`: a function describing a rule for generating the edge parameter values.
515515
516516
Output:
517-
- `ep_vals`: A sparse matrix of size (num_verts,num_verts) (where num_verts is the number of
518-
vertices in `lrs`). Here, `eps[i,j]` is filled only if there is an edge going from vertex i to
517+
- `ep_vals`: A sparse matrix of size (num_verts,num_verts) (where num_verts is the number of
518+
vertices in `lrs`). Here, `eps[i,j]` is filled only if there is an edge going from vertex i to
519519
vertex j. The value of `eps[i,j]` is determined by `make_edge_p_value`.
520520
521-
Here, `make_edge_p_value` should take two arguments, `src_vert` and `dst_vert`, which correspond to
521+
Here, `make_edge_p_value` should take two arguments, `src_vert` and `dst_vert`, which correspond to
522522
the grid indices of an edge's source and destination vertices, respectively. It outputs a single value,
523523
which is the value assigned to that edge.
524524
@@ -568,34 +568,34 @@ function make_edge_p_values(lrs::LatticeReactionSystem, make_edge_p_value::Funct
568568
end
569569

570570
"""
571-
make_directed_edge_values(lrs::LatticeReactionSystem, x_vals::Tuple{T,T}, y_vals::Tuple{T,T} = (undef,undef),
571+
make_directed_edge_values(lrs::LatticeReactionSystem, x_vals::Tuple{T,T}, y_vals::Tuple{T,T} = (undef,undef),
572572
z_vals::Tuple{T,T} = (undef,undef)) where {T}
573573
574-
Generates edge parameter values for a lattice reaction system. Only work for (Cartesian or masked)
575-
grid lattices (without diagonal adjacencies). Each dimension (x, and possibly y and z), and
574+
Generates edge parameter values for a lattice reaction system. Only work for (Cartesian or masked)
575+
grid lattices (without diagonal adjacencies). Each dimension (x, and possibly y and z), and
576576
direction has assigned its own constant edge parameter value.
577577
578578
Input:
579579
- `lrs`: The lattice reaction system for which values should be generated.
580-
- `x_vals::Tuple{T,T}`: The values in the increasing (from a lower x index to a higher x index)
580+
- `x_vals::Tuple{T,T}`: The values in the increasing (from a lower x index to a higher x index)
581581
and decreasing (from a higher x index to a lower x index) direction along the x dimension.
582-
- `y_vals::Tuple{T,T}`: The values in the increasing and decreasing direction along the y dimension.
582+
- `y_vals::Tuple{T,T}`: The values in the increasing and decreasing direction along the y dimension.
583583
Should only be used for 2 and 3-dimensional grids.
584-
- `z_vals::Tuple{T,T}`: The values in the increasing and decreasing direction along the z dimension.
584+
- `z_vals::Tuple{T,T}`: The values in the increasing and decreasing direction along the z dimension.
585585
Should only be used for 3-dimensional grids.
586586
587587
Output:
588-
- `ep_vals`: A sparse matrix of size (num_verts,num_verts) (where num_verts is the number of
589-
vertices in `lrs`). Here, `eps[i,j]` is filled only if there is an edge going from vertex i to
590-
vertex j. The value of `eps[i,j]` is determined by the `x_vals`, `y_vals`, and `z_vals` Tuples,
588+
- `ep_vals`: A sparse matrix of size (num_verts,num_verts) (where num_verts is the number of
589+
vertices in `lrs`). Here, `eps[i,j]` is filled only if there is an edge going from vertex i to
590+
vertex j. The value of `eps[i,j]` is determined by the `x_vals`, `y_vals`, and `z_vals` Tuples,
591591
and vertices i and j's relative position in the grid.
592592
593-
It should be noted that two adjacent vertices will always be different in exactly a single dimension
593+
It should be noted that two adjacent vertices will always be different in exactly a single dimension
594594
(x, y, or z). The corresponding tuple determines which value is assigned.
595595
596596
Example:
597597
In the following example, we wish to have diffusion in the x dimension, but a constant flow from
598-
low y values to high y values (so not transportation from high to low y). We achieve it in the
598+
low y values to high y values (so not transportation from high to low y). We achieve it in the
599599
following manner:
600600
```julia
601601
using Catalyst

test/extensions/Project.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
[deps]
22
BifurcationKit = "0f109fa4-8a5d-4b75-95aa-f515264e7665"
3-
Catalyst = "479239e8-5488-4da2-87a7-35f2df7eef83"
43
CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0"
5-
GLMakie = "e9467ef8-e4e7-5192-8a1a-b1aee30e663a"
4+
Catalyst = "479239e8-5488-4da2-87a7-35f2df7eef83"
65
GraphMakie = "1ecd5474-83a3-4783-bb4f-06765db800d2"
76
Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"
87
HomotopyContinuation = "f213a82b-91d6-5c5d-acf7-10f1c761b327"
98
JumpProcesses = "ccbc3e58-028d-4f4c-8cd5-9ae44345cda5"
109
ModelingToolkit = "961ee093-0014-501f-94e3-6117800e7a78"
11-
OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed"
10+
OrdinaryDiffEqDefault = "50262376-6c5a-4cf5-baba-aaf4f84d72d7"
11+
OrdinaryDiffEqTsit5 = "b1df2697-797e-41e3-8120-5422d3b24e4a"
1212
SteadyStateDiffEq = "9672c7b4-1e72-59bd-8a11-6ac3964bc41f"
13-
# StructuralIdentifiability = "220ca800-aa68-49bb-acd8-6037fa93a544"
13+
# StructuralIdentifiability = "220ca800-aa68-49bb-acd8-6037fa93a544"

test/extensions/graphmakie.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,3 @@ let
103103
@test count(==(Graphs.Edge(1, s+2)), edges(srg)) == 2
104104
@test count(==(Graphs.Edge(2, s+3)), edges(srg)) == 2
105105
end
106-

test/extensions/lattice_simulation_plotting.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
### Preparations ###
22

33
# Fetch packages.
4-
using Catalyst, CairoMakie, GraphMakie, Graphs, JumpProcesses, OrdinaryDiffEqDefault, OrdinaryDiffEq, Test
4+
using Catalyst, CairoMakie, GraphMakie, Graphs
5+
using JumpProcesses, OrdinaryDiffEqDefault, OrdinaryDiffEqTsit5, Test
56

67

78
### Checks Basic Plot Cases ###

test/runtests.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,15 @@ end
7979
if GROUP == "All" || GROUP == "Extensions"
8080
activate_extensions_env()
8181

82+
@time @safetestset "Graph visualization" begin include("extensions/graphmakie.jl") end
8283
@time @safetestset "BifurcationKit Extension" begin include("extensions/bifurcation_kit.jl") end
8384
@time @safetestset "HomotopyContinuation Extension" begin include("extensions/homotopy_continuation.jl") end
8485

8586
# BROKEN
8687
# @time @safetestset "Structural Identifiability Extension" begin include("extensions/structural_identifiability.jl") end
8788

8889
# Tests stability computation (but requires the HomotopyContinuation extension).
89-
# @time @safetestset "Steady State Stability Computations" begin include("extensions/stability_computation.jl") end
90+
#@time @safetestset "Steady State Stability Computations" begin include("extensions/stability_computation.jl") end
9091

9192
# Test spatial plotting, using CarioMakie and GraphMakie
9293
@time @safetestset "Lattice Simulation Plotting" begin include("extensions/lattice_simulation_plotting.jl") end

test/spatial_modelling/lattice_reaction_systems.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ end
248248
@test_logs (:warn, r"The `ReactionSystem` used as input to `LatticeReactionSystem contain observables. It *") match_mode=:any LatticeReactionSystem(rs4, [tr], short_path)
249249
end
250250

251-
# Tests for hierarchical input system.
251+
# Tests for hierarchical input system (should yield a warning).
252252
let
253253
t = default_t()
254254
@parameters d D
@@ -257,7 +257,7 @@ let
257257
@named rs1 = ReactionSystem(rxs, t)
258258
@named rs2 = ReactionSystem(rxs, t; systems = [rs1])
259259
rs2 = complete(rs2)
260-
@test_throws ArgumentError LatticeReactionSystem(rs2, [TransportReaction(D, X)], CartesianGrid((2,2)))
260+
@test_logs (:warn, r"The `ReactionSystem` used as input to `LatticeReactionSystem` was originally created as a hierarchical model. While *") match_mode=:any LatticeReactionSystem(rs2, [TransportReaction(D, X)], CartesianGrid((2,2)))
261261
end
262262

263263
# Tests for non-complete input `ReactionSystem`.

0 commit comments

Comments
 (0)