Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add errors for array species/parameters when submitted to LatticeReactionSystems #1148

Merged
merged 1 commit into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/spatial_reaction_systems/lattice_reaction_systems.jl
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,13 @@ struct LatticeReactionSystem{Q, R, S, T} <: MT.AbstractTimeDependentSystem
sr -> check_spatial_reaction_validity(rs, sr; edge_parameters = edge_parameters),
spatial_reactions)

# Additional error checks.
if any(haskey(Symbolics.unwrap(symvar).metadata, Symbolics.ArrayShapeCtx)
for symvar in [ps; species(rs)])
println([ps; species(rs)])
throw(ArgumentError("Some species and/or parameters used to create the `LatticeReactionSystem` are array variables ($(filter(symvar -> haskey(Symbolics.unwrap(symvar).metadata, Symbolics.ArrayShapeCtx), [ps; species(rs)]))). This is currently not supported."))
end

return new{Q, R, S, T}(
rs, spatial_reactions, lattice, num_verts, num_edges, num_species,
spat_species, ps, vertex_parameters, edge_parameters, edge_iterator)
Expand Down
19 changes: 19 additions & 0 deletions test/spatial_modelling/lattice_reaction_systems.jl
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,25 @@ let
@test_throws ArgumentError LatticeReactionSystem(rs, [tr], CartesianGrid((2,2)))
end

# Tests for array parameters/species.
let
tr = @transport_reaction D Y

rs1 = @reaction_network begin
@species X(t)[1:2] Y(t)
(k1,k2), X[1] <--> X[2]
end
@test_throws ArgumentError LatticeReactionSystem(rs1, [tr], CartesianGrid((2,2)))

rs2 = @reaction_network begin
@species Y(t)
@parameters k[1:2,1:2]
(k[1,1],k[1,2]), X11 <--> X12
(k[2,1],k[2,2]), X21 <--> X22
end
@test_throws ArgumentError LatticeReactionSystem(rs2, [tr], CartesianGrid((2,2)))
end

### Tests Grid Vertex and Edge Number Computation ###

# Tests that the correct numbers are computed for num_edges.
Expand Down
Loading