Skip to content

Commit e19d67d

Browse files
committed
format, improve writing
1 parent 37a14d0 commit e19d67d

11 files changed

+50
-51
lines changed

src/spatial_reaction_systems/lattice_jump_systems.jl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ function JumpProcesses.JumpProblem(lrs::LatticeReactionSystem, dprob, aggregator
3737

3838
# Computes hopping constants and mass action jumps (requires some internal juggling).
3939
# Currently, the resulting JumpProblem does not depend on parameters (no way to incorporate these).
40-
# Hence the parameters of this one does not actually matter. If at some point JumpProcess can
40+
# Hence the parameters of this one do not actually matter. If at some point JumpProcess can
4141
# handle parameters this can be updated and improved.
4242
# The non-spatial DiscreteProblem have a u0 matrix with entries for all combinations of species and vertexes.
4343
hopping_constants = make_hopping_constants(dprob, lrs)
@@ -54,7 +54,7 @@ end
5454
# Creates the hopping constants from a discrete problem and a lattice reaction system.
5555
function make_hopping_constants(dprob::DiscreteProblem, lrs::LatticeReactionSystem)
5656
# Creates the all_diff_rates vector, containing for each species, its transport rate across all edges.
57-
# If transport rate is uniform for one species, the vector have a single element, else one for each edge.
57+
# If the transport rate is uniform for one species, the vector has a single element, else one for each edge.
5858
spatial_rates_dict = Dict(compute_all_transport_rates(Dict(dprob.p), lrs))
5959
all_diff_rates = [haskey(spatial_rates_dict, s) ? spatial_rates_dict[s] : [0.0]
6060
for s in species(lrs)]
@@ -77,7 +77,7 @@ function make_hopping_constants(dprob::DiscreteProblem, lrs::LatticeReactionSyst
7777
end
7878

7979
# Creates a SpatialMassActionJump struct from a (spatial) DiscreteProblem and a LatticeReactionSystem.
80-
# Could implementation a version which, if all reaction's rates are uniform, returns a MassActionJump.
80+
# Could implement a version which, if all reactions' rates are uniform, returns a MassActionJump.
8181
# Not sure if there is any form of performance improvement from that though. Likely not the case.
8282
function make_spatial_majumps(dprob, lrs::LatticeReactionSystem)
8383
# Creates a vector, storing which reactions have spatial components.
@@ -143,7 +143,6 @@ end
143143
# return ModelingToolkit.assemble_maj(eqs.x[1], statetoid, majpmapper)
144144
# end
145145

146-
147146
### Problem & Integrator Rebuilding ###
148147

149148
# Currently not implemented.

src/spatial_reaction_systems/lattice_solution_interfacing.jl

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
### Rudimentary Interfacing Function ###
2-
# A single function, `get_lrs_vals`, which contain all interfacing functionality. However,
3-
# long-term it should be replaced with a sleeker interface. Ideally as MTK-wider support for
4-
# lattice problems and solutions are introduced.
2+
# A single function, `get_lrs_vals`, which contains all interfacing functionality. However,
3+
# long-term it should be replaced with a sleeker interface. Ideally as MTK-wide support for
4+
# lattice problems and solutions is introduced.
55

66
"""
77
get_lrs_vals(sol, sp, lrs::LatticeReactionSystem; t = nothing)
@@ -11,7 +11,7 @@ desired forms. Generally, for `LatticeReactionSystem`s, the values in `sol` is o
1111
way which is not directly interpretable by the user. Furthermore, the normal Catalyst interface
1212
for solutions (e.g. `sol[:X]`) does not work for these solutions. Hence this function is used instead.
1313
14-
The output is a vector, which in each position contain sp's value (either at a time step of time,
14+
The output is a vector, which in each position contains sp's value (either at a time step of time,
1515
depending on the input `t`). Its shape depends on the lattice (using a similar form as heterogeneous
1616
initial conditions). I.e. for a NxM cartesian grid, the values are NxM matrices. For a masked grid,
1717
the values are sparse matrices. For a graph lattice, the values are vectors (where the value in
@@ -22,8 +22,8 @@ Arguments:
2222
- `sp`: The species which values we wish to retrieve. Can be either a symbol (e.g. `:X`) or a symbolic
2323
variable (e.g. `X`).
2424
- `lrs`: The `LatticeReactionSystem` which was simulated to generate the solution.
25-
- `t = nothing`: If `nothing`, we simply returns the solution across all saved timesteps. If `t`
26-
instead is a vector (or range of values), returns the solutions interpolated at these timepoints.
25+
- `t = nothing`: If `nothing`, we simply return the solution across all saved time steps. If `t`
26+
instead is a vector (or range of values), returns the solutions interpolated at these time points.
2727
2828
Notes:
2929
- The `get_lrs_vals` is not optimised for performance. However, it should still be quite performant,
@@ -48,7 +48,7 @@ ps = [:k1 => 1, :k2 => 2.0, :D => 0.1]
4848
4949
oprob = ODEProblem(lrs1, u0, tspan, ps)
5050
osol = solve(oprob1, Tsit5())
51-
get_lrs_vals(osol, :X1, lrs) # Returns the value of X1 at each timestep.
51+
get_lrs_vals(osol, :X1, lrs) # Returns the value of X1 at each time step.
5252
get_lrs_vals(osol, :X1, lrs; t = 0.0:10.0) # Returns the value of X1 at times 0.0, 1.0, ..., 10.0
5353
```
5454
"""
@@ -61,7 +61,7 @@ function get_lrs_vals(sol, sp, lrs::LatticeReactionSystem; t = nothing)
6161
# Extracts the lattice and calls the next function. Masked grids (Array of Bools) are converted
6262
# to sparse array using the same template size as we wish to shape the data to.
6363
lattice = Catalyst.lattice(lrs)
64-
if has_masked_lattice(lrs)
64+
if has_masked_lattice(lrs)
6565
if grid_dims(lrs) == 3
6666
error("The `get_lrs_vals` function is not defined for systems based on 3d sparse arrays. Please raise an issue at the Catalyst GitHub site if this is something which would be useful to you.")
6767
end
@@ -79,15 +79,16 @@ function get_lrs_vals(sol, lattice, t::Nothing, sp_idx, sp_tot)
7979
if sol.prob isa ODEProblem
8080
return [reshape_vals(vals[sp_idx:sp_tot:end], lattice) for vals in sol.u]
8181
elseif sol.prob isa DiscreteProblem
82-
return [reshape_vals(vals[sp_idx,:], lattice) for vals in sol.u]
82+
return [reshape_vals(vals[sp_idx, :], lattice) for vals in sol.u]
8383
else
8484
error("Unknown type of solution provided to `get_lrs_vals`. Only ODE or Jump solutions are supported.")
8585
end
8686
end
8787

8888
# Function which handles the input in the case where `t` is a range of values (i.e. return `sp`s
8989
# value at all designated time points.
90-
function get_lrs_vals(sol, lattice, t::AbstractVector{T}, sp_idx, sp_tot) where {T <: Number}
90+
function get_lrs_vals(
91+
sol, lattice, t::AbstractVector{T}, sp_idx, sp_tot) where {T <: Number}
9192
if (minimum(t) < sol.t[1]) || (maximum(t) > sol.t[end])
9293
error("The range of the t values provided for sampling, ($(minimum(t)),$(maximum(t))) is not fully within the range of the simulation time span ($(sol.t[1]),$(sol.t[end])).")
9394
end
@@ -98,15 +99,15 @@ function get_lrs_vals(sol, lattice, t::AbstractVector{T}, sp_idx, sp_tot) where
9899
if sol.prob isa ODEProblem
99100
return [reshape_vals(sol(ti)[sp_idx:sp_tot:end], lattice) for ti in t]
100101
elseif sol.prob isa DiscreteProblem
101-
return [reshape_vals(sol(ti)[sp_idx,:], lattice) for ti in t]
102+
return [reshape_vals(sol(ti)[sp_idx, :], lattice) for ti in t]
102103
else
103104
error("Unknown type of solution provided to `get_lrs_vals`. Only ODE or Jump solutions are supported.")
104105
end
105106
end
106107

107-
# Functions which in each sample point reshapes the vector of values to the correct form (depending
108+
# Functions which in each sample point reshape the vector of values to the correct form (depending
108109
# on the type of lattice used).
109-
function reshape_vals(vals, lattice::CartesianGridRej{N, T}) where {N,T}
110+
function reshape_vals(vals, lattice::CartesianGridRej{N, T}) where {N, T}
110111
return reshape(vals, lattice.dims...)
111112
end
112113
function reshape_vals(vals, lattice::AbstractSparseArray{Bool, Int64, 1})
@@ -118,4 +119,3 @@ end
118119
function reshape_vals(vals, lattice::DiGraph)
119120
return vals
120121
end
121-

src/spatial_reaction_systems/spatial_ODE_systems.jl

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ struct LatticeTransportODEFunction{P, Q, R, S, T}
2626
mtk_ps::Q
2727
"""
2828
Stores a SymbolicIndexingInterface `setp` function for each heterogeneous vertex parameter (i.e.
29-
vertex parameter which value is not identical across the lattice). The `setp` function at index
29+
vertex parameter whose value is not identical across the lattice). The `setp` function at index
3030
i of `p_setters` corresponds to the parameter in index i of `heterogeneous_vert_p_idxs`.
3131
"""
3232
p_setters::R
@@ -82,7 +82,7 @@ struct LatticeTransportODEFunction{P, Q, R, S, T}
8282
end
8383
end
8484

85-
# `LatticeTransportODEFunction` helper functions (re used by rebuild function later on).
85+
# `LatticeTransportODEFunction` helper functions (re-used by rebuild function later on).
8686

8787
# Creates a vector with the heterogeneous vertex parameters' indexes in the full parameter vector.
8888
function make_heterogeneous_vert_p_idxs(ps, lrs)
@@ -226,7 +226,7 @@ function build_odefunction(lrs::LatticeReactionSystem, vert_ps::Vector{Pair{R, V
226226
ofunc_sparse = ODEFunction(osys; jac = true, sparse = true)
227227
transport_rates = make_sidxs_to_transrate_map(vert_ps, edge_ps, lrs)
228228

229-
# Depending on Jacobian and sparsity options, computes the Jacobian transport matrix and prototype.
229+
# Depending on Jacobian and sparsity options, compute the Jacobian transport matrix and prototype.
230230
if !sparse && !jac
231231
jac_transport = nothing
232232
jac_prototype = nothing
@@ -249,7 +249,7 @@ function build_odefunction(lrs::LatticeReactionSystem, vert_ps::Vector{Pair{R, V
249249
return ODEFunction(f; jac = J, jac_prototype, sys)
250250
end
251251

252-
# Builds a jacobian prototype.
252+
# Builds a Jacobian prototype.
253253
# If requested, populate it with the constant values of the Jacobian's transportation part.
254254
function build_jac_prototype(ns_jac_prototype::SparseMatrixCSC{Float64, Int64},
255255
transport_rates::Vector{Pair{Int64, SparseMatrixCSC{T, Int64}}},
@@ -328,19 +328,19 @@ end
328328
"""
329329
rebuild_lat_internals!(sciml_struct)
330330
331-
Rebuilds the internal functions for simulating a LatticeReactionSystem. WHenever a problem or
332-
integrator have had its parameter values updated, thus function should be called for the update to
331+
Rebuilds the internal functions for simulating a LatticeReactionSystem. Wenever a problem or
332+
integrator has had its parameter values updated, this function should be called for the update to
333333
be taken into account. For ODE simulations, `rebuild_lat_internals!` needs only to be called when
334-
- An edge parameter have been updated.
335-
- When a parameter with spatially homogeneous values have been given spatially heterogeneous values
334+
- An edge parameter has been updated.
335+
- When a parameter with spatially homogeneous values has been given spatially heterogeneous values
336336
(or vice versa).
337337
338338
Arguments:
339339
- `sciml_struct`: The problem (e.g. an `ODEProblem`) or an integrator which we wish to rebuild.
340340
341341
Notes:
342342
- Currently does not work for `DiscreteProblem`s, `JumpProblem`s, or their integrators.
343-
- The function is not build with performance in mind, so avoid calling it multiple times in
343+
- The function is not built with performance in mind, so avoid calling it multiple times in
344344
performance-critical applications.
345345
346346
Example:

src/spatial_reaction_systems/spatial_reactions.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,15 @@ function check_spatial_reaction_validity(rs::ReactionSystem, tr::TransportReacti
9999

100100
# Checks that the species does not exist in the system with different metadata.
101101
if any(isequal(tr.species, s) && !isequivalent(tr.species, s) for s in species(rs))
102-
error("A transport reaction used a species, $(tr.species), with metadata not matching its lattice reaction system. Please fetch this species from the reaction system and used in transport reaction creation.")
102+
error("A transport reaction used a species, $(tr.species), with metadata not matching its lattice reaction system. Please fetch this species from the reaction system and use it during transport reaction creation.")
103103
end
104104
# No `for` loop, just weird formatting by the formatter.
105105
if any(isequal(rs_p, tr_p) && !isequivalent(rs_p, tr_p)
106106
for rs_p in parameters(rs), tr_p in Symbolics.get_variables(tr.rate))
107-
error("A transport reaction used a parameter with metadata not matching its lattice reaction system. Please fetch this parameter from the reaction system and used in transport reaction creation.")
107+
error("A transport reaction used a parameter with metadata not matching its lattice reaction system. Please fetch this parameter from the reaction system and use it during transport reaction creation.")
108108
end
109109

110-
# Checks that no edge parameter occur among rates of non-spatial reactions.
110+
# Checks that no edge parameter occurs among rates of non-spatial reactions.
111111
# No `for` loop, just weird formatting by the formatter.
112112
if any(!isempty(intersect(Symbolics.get_variables(r.rate), edge_parameters))
113113
for r in reactions(rs))

src/spatial_reaction_systems/utility.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ function get_transport_rate(transport_rate::SparseMatrixCSC{T, Int64},
269269
return t_rate_idx_types ? transport_rate[1, 1] : transport_rate[edge[1], edge[2]]
270270
end
271271

272-
# For a `LatticeTransportODEFunction`, updates its stored parameters (in `mtk_ps`) so that they
272+
# For a `LatticeTransportODEFunction`, update its stored parameters (in `mtk_ps`) so that they
273273
# the heterogeneous parameters' values correspond to the values in the specified vertex.
274274
function update_mtk_ps!(lt_ofun::LatticeTransportODEFunction, all_ps::Vector{T},
275275
vert::Int64) where {T}
@@ -278,7 +278,7 @@ function update_mtk_ps!(lt_ofun::LatticeTransportODEFunction, all_ps::Vector{T},
278278
end
279279
end
280280

281-
# For an expression, computes its values using the provided state and parameter vectors.
281+
# For an expression, compute its values using the provided state and parameter vectors.
282282
# The expression is assumed to be valid in vertexes (and can have vertex parameter and state components).
283283
# If at least one component is non-uniform, output is a vector of length equal to the number of vertexes.
284284
# If all components are uniform, the output is a length one vector.
@@ -289,7 +289,7 @@ function compute_vertex_value(exp, lrs::LatticeReactionSystem; u = [], ps = [])
289289
throw(ArgumentError("An edge parameter was encountered in expressions: $exp. Here, only vertex-based components are expected."))
290290
end
291291

292-
# Creates a Function that computes the expressions value for a parameter set.
292+
# Creates a Function that computes the expression value for a parameter set.
293293
exp_func = drop_expr(@RuntimeGeneratedFunction(build_function(exp, relevant_syms...)))
294294

295295
# Creates a dictionary with the value(s) for all edge parameters.
@@ -305,7 +305,7 @@ end
305305

306306
### System Property Checks ###
307307

308-
# For a Symbolic expression, and a parameter set, checks if any relevant parameters have a
308+
# For a Symbolic expression, and a parameter set, check if any relevant parameters have a
309309
# spatial component. Filters out any parameters that are edge parameters.
310310
function has_spatial_vertex_component(exp, ps)
311311
relevant_syms = Symbolics.get_variables(exp)

test/spatial_modelling/lattice_reaction_systems.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ end
298298

299299
### Tests Edge Value Computation Helper Functions ###
300300

301-
# Checks that computes the correct values across various types of grids.
301+
# Checks that we compute the correct values across various types of grids.
302302
let
303303
# Prepares the model and the function that determines the edge values.
304304
rn = @reaction_network begin
@@ -323,7 +323,7 @@ let
323323
end
324324
end
325325

326-
# Checks that all species ends up in the correct place in in a pure flow system (checking various dimensions).
326+
# Checks that all species end up in the correct place in a pure flow system (checking various dimensions).
327327
let
328328
# Prepares a system with a single species which is transported only.
329329
rn = @reaction_network begin

test/spatial_modelling/lattice_reaction_systems_ODEs.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ rng = StableRNG(12345)
1414
# Sets defaults
1515
t = default_t()
1616

17-
### Tests Simulations Don't Error ###
17+
### Tests Simulations Do Not Error ###
1818
let
1919
for grid in [small_1d_cartesian_grid, small_1d_masked_grid, small_1d_graph_grid]
2020
for srs in [Vector{TransportReaction}(), SIR_srs_1, SIR_srs_2]
@@ -186,7 +186,7 @@ let
186186
@test all(isapprox.(ss, solve(oprob_sparse_jac, Rosenbrock23(); abstol = 1e-10, reltol = 1e-10).u[end]; rtol = 0.0001))
187187
end
188188

189-
# Compares Catalyst-generated to hand written one for the brusselator for a line of cells.
189+
# Compares Catalyst-generated to hand-written one for the Brusselator for a line of cells.
190190
let
191191
function spatial_brusselator_f(du, u, p, t)
192192
# Non-spatial
@@ -534,7 +534,7 @@ end
534534

535535
# Checks that the `rebuild_lat_internals!` function is correctly applied to an ODEProblem.
536536
let
537-
# Creates a brusselator `LatticeReactionSystem`.
537+
# Creates a Brusselator `LatticeReactionSystem`.
538538
lrs = LatticeReactionSystem(brusselator_system, brusselator_srs_2, very_small_2d_cartesian_grid)
539539

540540
# Checks for all combinations of Jacobian and sparsity.
@@ -572,7 +572,7 @@ end
572572

573573
# Checks that the `rebuild_lat_internals!` function is correctly applied to an integrator.
574574
# Does through by applying it within a callback, and compare to simulations without callback.
575-
# To keep test faster, only checks for `jac = sparse = true`.
575+
# To keep test faster, only check for `jac = sparse = true` only.
576576
let
577577
# Prepares problem inputs.
578578
lrs = LatticeReactionSystem(brusselator_system, brusselator_srs_2, very_small_2d_cartesian_grid)
@@ -624,7 +624,7 @@ end
624624

625625
### Tests Special Cases ###
626626

627-
# Create network using either graphs or di-graphs.
627+
# Create networks using either graphs or di-graphs.
628628
let
629629
lrs_digraph = LatticeReactionSystem(SIR_system, SIR_srs_2, complete_digraph(3))
630630
lrs_graph = LatticeReactionSystem(SIR_system, SIR_srs_2, complete_graph(3))

test/spatial_modelling/lattice_reaction_systems_jumps.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ end
8888

8989
### SpatialMassActionJump Testing ###
9090

91-
# Checks that the correct structure;s is produced.
91+
# Checks that the correct structures are produced.
9292
let
9393
# Network for reference:
9494
# A, ∅ → X
@@ -113,7 +113,7 @@ let
113113
# @test isequal(to_int(getfield.(reactions(reactionsystem(lrs)), :netstoich)), jprob.massaction_jump.net_stoch)
114114
# @test isequal(to_int(Pair.(getfield.(reactions(reactionsystem(lrs)), :substrates),getfield.(reactions(reactionsystem(lrs)), :substoich))), jprob.massaction_jump.net_stoch)
115115

116-
# Checks that problem can be simulated.
116+
# Checks that problems can be simulated.
117117
@test SciMLBase.successful_retcode(solve(jprob, SSAStepper()))
118118
end
119119

@@ -203,7 +203,7 @@ end
203203

204204
### JumpProblem & Integrator Interfacing ###
205205

206-
# Currently not supported, check that corresponding functions yields errors.
206+
# Currently not supported, check that corresponding functions yield errors.
207207
let
208208
# Prepare `LatticeReactionSystem`.
209209
rs = @reaction_network begin

test/spatial_modelling/lattice_reaction_systems_lattice_types.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ include("../spatial_test_networks.jl")
99

1010
### Run Tests ###
1111

12-
# Test errors when attempting to create networks with dimension > 3.
12+
# Test errors when attempting to create networks with dimensions > 3.
1313
let
1414
@test_throws Exception LatticeReactionSystem(brusselator_system, brusselator_srs_1, CartesianGrid((5, 5, 5, 5)))
1515
@test_throws Exception LatticeReactionSystem(brusselator_system, brusselator_srs_1, fill(true, 5, 5, 5, 5))

0 commit comments

Comments
 (0)