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

Change u₀ to u0 #107

Merged
merged 6 commits into from
Dec 30, 2023
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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Here `BNGNetwork` is a type specifying the file format that is being loaded.
`prnbng` is a `ParsedReactionNetwork` structure with the following fields:

- `rn`, a Catalyst `ReactionSystem`
- `u₀`, a `Dict` mapping initial condition symbolic variables to numeric values
- `u0`, a `Dict` mapping initial condition symbolic variables to numeric values
and/or symbolic expressions.
- `p`, a `Dict` mapping parameter symbolic variables to numeric values and/or
symbolic expressions.
Expand Down Expand Up @@ -221,4 +221,4 @@ initialconditionf = "PATH/TO/FILE"
networkf = "PATH/TO/FILE"
rssarn = loadrxnetwork(RSSANetwork(), "RSSARxSys", initialconditionf, networkf)
```
Here `RSSANetwork` specifies the type of the file to parse, and `RSSARxSys` gives the type of the generated `reaction_network`. `rssarn` is again a `ParsedReactionNetwork`, but only the `rn` and `u₀` fields will now be relevant (the remaining fields will be set to `nothing`). -->
Here `RSSANetwork` specifies the type of the file to parse, and `RSSARxSys` gives the type of the generated `reaction_network`. `rssarn` is again a `ParsedReactionNetwork`, but only the `rn` and `u0` fields will now be relevant (the remaining fields will be set to `nothing`). -->
2 changes: 1 addition & 1 deletion docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ Here `BNGNetwork` is a type specifying the file format that is being loaded.
`prnbng` is a `ParsedReactionNetwork` structure with the following fields:

- `rn`, a Catalyst `ReactionSystem`
- `u₀`, a `Dict` mapping initial condition symbolic variables to numeric values
- `u0`, a `Dict` mapping initial condition symbolic variables to numeric values
and/or symbolic expressions.
- `p`, a `Dict` mapping parameter symbolic variables to numeric values and/or
symbolic expressions.
Expand Down
2 changes: 1 addition & 1 deletion examples/not_updated_yet/bcr_odes_sparse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ reset_timer!(to)
# BioNetGen network
@timeit to "bionetgen" prnbng=loadrxnetwork(BNGNetwork(), string(networkname, "bng"), fname);
rnbng = prnbng.rn;
u0 = prnbng.u₀;
u0 = prnbng.u0;
p = prnbng.p;
@timeit to "baddodes" addodes!(rnbng; build_jac = build_jac, zeroout_jac = zeroout_jac,
sparse_jac = sparse_jac, build_symfuncs = false,
Expand Down
6 changes: 3 additions & 3 deletions examples/not_updated_yet/test_network.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,18 @@ reset_timer!(to)
@timeit to "netgen" prn=loadrxnetwork(RSSANetwork(), networkname, speciesf, rxsf;
printrxs = false)
rn = prn.rn
initialpop = prn.u₀
initialpop = prn.u0
println("network parsed")

# get the BioNetGen reaction network
@timeit to "bionetgen" prnbng=loadrxnetwork(BNGNetwork(), string(networkname, "bng"),
bngfname)
rnbng = prnbng.rn;
u₀ = prnbng.u₀;
u0 = prnbng.u0;
p = prnbng.p;
shortsymstosyms = prnbng.symstonames;

u0 = round.(Int, u₀)
u0 = round.(Int, u0)
println(typeof(u0))

# one simulation
Expand Down
2 changes: 1 addition & 1 deletion examples/not_updated_yet/test_odes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ reset_timer!(to)
# get the reaction network
@timeit to "netgen" prnbng=loadrxnetwork(BNGNetwork(), string(networkname, "bng"), fname);
rn = prnbng.rn;
u0 = prnbng.u₀;
u0 = prnbng.u0;
p = prnbng.p;
@timeit to "addodes" addodes!(rn; build_jac = build_jac, sparse_jac = sparse_jac,
build_symfuncs = false, build_paramjac = false)
Expand Down
2 changes: 1 addition & 1 deletion examples/not_updated_yet/test_odes_rssa.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ reset_timer!(to)
@timeit to "netgen" prn=loadrxnetwork(RSSAFile(), networkname, speciesf, rxsf;
printrxs = false)
rn = prn.rn;
initialpop = prn.u₀;
initialpop = prn.u0;
@timeit to "addodes" addodes!(rn; build_jac = false, build_symfuncs = false,
build_paramjac = false)
@timeit to "ODEProb" oprob=ODEProblem(rn, convert.(Float64, initialpop), (0.0, tf))
Expand Down
29 changes: 26 additions & 3 deletions src/ReactionNetworkImporters.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
rn::ReactionSystem

"Dict mapping initial condition symbolic variables to values."
u₀::Any
u0::Any

"Dict mapping parameter symbolic variables to values."
p::Any
Expand All @@ -35,9 +35,9 @@
"Dict from group name (as string) to corresponding symbolic variable"
groupstosyms::Any
end
function ParsedReactionNetwork(rn::ReactionSystem; u₀ = nothing, p = nothing,
function ParsedReactionNetwork(rn::ReactionSystem; u0 = nothing, p = nothing,
varstonames = nothing, groupstosyms = nothing)
ParsedReactionNetwork(rn, u₀, p, varstonames, groupstosyms)
ParsedReactionNetwork(rn, u0, p, varstonames, groupstosyms)
end

export BNGNetwork, MatrixNetwork, ParsedReactionNetwork, ComplexMatrixNetwork
Expand All @@ -48,4 +48,27 @@

export loadrxnetwork


# Overload ensuring that u0 and u₀ can be used interchangeably.
# (introduced when the u₀ field was changed to u0)
# Should be deleted whenever u₀ is fully deprecated.

# Ensures that `prnbng.u₀` works.
function Base.getproperty(prnbng::ParsedReactionNetwork, name::Symbol)
if name === :u₀
return getfield(prnbng, :u0)
else
return getfield(prnbng, name)
end
end

# Ensures that `prnbng.u₀ = ...` works.
function Base.setproperty!(prnbng::ParsedReactionNetwork, name::Symbol, x)
if name === :u₀
return setfield!(prnbng, :u0, x)

Check warning on line 68 in src/ReactionNetworkImporters.jl

View check run for this annotation

Codecov / codecov/patch

src/ReactionNetworkImporters.jl#L66-L68

Added lines #L66 - L68 were not covered by tests
else
return setfield!(prnbng, name, x)

Check warning on line 70 in src/ReactionNetworkImporters.jl

View check run for this annotation

Codecov / codecov/patch

src/ReactionNetworkImporters.jl#L70

Added line #L70 was not covered by tests
end
end

end # module
4 changes: 2 additions & 2 deletions src/parsing_routines_bngnetworkfiles.jl
Original file line number Diff line number Diff line change
Expand Up @@ -279,10 +279,10 @@ function loadrxnetwork(ft::BNGNetwork, rxfilename; name = gensym(:ReactionSystem
rn = ReactionSystem(rxs, t, specs, ps; name = name, observed = obseqs,
defaults = defmap, kwargs...)

# get numeric values for parameters and u₀
# get numeric values for parameters and u0
sm = speciesmap(rn)
@assert all(sm[funcsym(sym, t)] == i for (i, sym) in enumerate(idstoshortsyms))

ParsedReactionNetwork(rn; u₀ = u0map, p = pmap, varstonames = shortsymstosyms,
ParsedReactionNetwork(rn; u0 = u0map, p = pmap, varstonames = shortsymstosyms,
groupstosyms = groupstosyms)
end
3 changes: 3 additions & 0 deletions test/test_higherorder_odes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ prnbng = loadrxnetwork(BNGNetwork(), fname)
rn = prnbng.rn
boprob = ODEProblem(rn, Float64[], (0.0, tf), Float64[])

# Test that u0 == u₀ (used when the u0 indexing was introduced).
@test isequal(prnbng.u0, prnbng.u₀)

# BNG simulation data testing
@unpack A = rn
Asol = gdatdf[!, :A]
Expand Down
3 changes: 3 additions & 0 deletions test/test_nullrxs_odes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ u0 = Float64[];
p = Float64[];
boprob = ODEProblem(rn, u0, (0.0, tf), p)

# Test that u0 == u₀ (used when the u0 indexing was introduced).
@test isequal(prnbng.u0, prnbng.u₀)

# note solvers run _much_ faster the second time
bsol = solve(boprob, Tsit5(), abstol = 1e-12, reltol = 1e-12, saveat = tf / nsteps);

Expand Down
3 changes: 3 additions & 0 deletions test/test_repressilator_odes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ u0 = Float64[];
p = Float64[];
boprob = ODEProblem(rn, u0, (0.0, tf), p)

# Test that u0 == u₀ (used when the u0 indexing was introduced).
@test isequal(prnbng.u0, prnbng.u₀)

# BNG simulation data testing
bngsol = gdatdf[!, :pTetR]

Expand Down
Loading