Skip to content

Commit

Permalink
up compats, reformat
Browse files Browse the repository at this point in the history
  • Loading branch information
thevolatilebit committed Aug 31, 2023
1 parent 0ae65d0 commit d0e195b
Show file tree
Hide file tree
Showing 31 changed files with 1,492 additions and 873 deletions.
11 changes: 10 additions & 1 deletion .JuliaFormatter.toml
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
style = "sciml"
remove_extra_newlines=true
long_to_short_function_def=true
format_docstrings=true
normalize_line_endings="unix"
separate_kwargs_with_semicolon=true
trailing_comma=true
conditional_to_if=true
yas_style_nesting=true
short_to_long_function_def=true
always_use_return=true
2 changes: 1 addition & 1 deletion .github/workflows/CompatHelper.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: Install Julia, but only if it is not already available in the PATH
uses: julia-actions/setup-julia@v1
with:
version: '1.8'
version: '1.9'
arch: ${{ runner.arch }}
if: steps.julia_in_path.outcome != 'success'
- name: "Add the General registry via Git"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/Documenter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- uses: actions/checkout@v3
- uses: julia-actions/setup-julia@latest
with:
version: '1.8'
version: '1.9'
- uses: actions/cache@v3
env:
cache-name: cache-artifacts
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/Tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
strategy:
fail-fast: false
matrix:
julia_version: ['1.8']
julia_version: ['1.9']
os: [ubuntu-latest]
steps:
- uses: actions/checkout@v3
Expand Down
45 changes: 23 additions & 22 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "ReactiveDynamics"
uuid = "c7456e7d-545a-4b79-91ea-6e93d96dd4d4"
version = "0.2.6"
version = "0.2.7"

[deps]
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
Expand Down Expand Up @@ -33,30 +33,31 @@ Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[compat]
CSV = "0.10"
Catlab = "0.14.13"
ComponentArrays = "0.13"
Crayons = "4.1"
DataFrames = "1.4"
DiffEqBase = "6.114"
DifferentialEquations = "7.6"
Distributions = "0.25"
Documenter = "0.27"
julia = "1.9"
DifferentialEquations = "7.9"
StatsFuns = "1.3"
Catlab = "0.14"
DataFrames = "1.6"
PlutoUI = "0.7"
Statistics = "1.9"
DocumenterMarkdown = "0.2"
GeneratedExpressions = "0.1"
IJulia = "1.24"
ComponentArrays = "0.14"
JLD2 = "0.4"
GeneratedExpressions = "0.1"
DiffEqBase = "6.128"
JSON = "0.21"
MacroTools = "0.5"
NLopt = "0.6"
OrdinaryDiffEq = "6.38"
Plots = "1.38"
Pluto = "0.19"
PlutoUI = "0.7"
NLopt = "1.0"
OrdinaryDiffEq = "6.55"
Symbolics = "5.5"
IJulia = "1.24"
SafeTestsets = "0.1"
CSV = "0.10"
Plots = "1.39"
Reexport = "1.2"
SafeTestsets = "0.0"
StatsFuns = "1.1"
Symbolics = "4.14, 5"
TOML = "1.0"
MacroTools = "0.5"
Crayons = "4.1"
Documenter = "0.27"
Tables = "1.10"
julia = "1.8"
Distributions = "0.25"
Pluto = "0.19"
9 changes: 6 additions & 3 deletions docs/make.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
using Documenter, DocumenterMarkdown
using ReactiveDynamics

makedocs(format = Documenter.HTML(prettyurls = false, edit_link = "main"),
sitename = "ReactiveDynamics.jl API Documentation", pages = ["index.md"])
makedocs(;
format = Documenter.HTML(; prettyurls = false, edit_link = "main"),
sitename = "ReactiveDynamics.jl API Documentation",
pages = ["index.md"],
)

deploydocs(repo = "github.com/Merck/ReactiveDynamics.jl.git")
deploydocs(; repo = "github.com/Merck/ReactiveDynamics.jl.git")
169 changes: 109 additions & 60 deletions src/ReactiveDynamics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,17 @@ using ComponentArrays

@reexport using GeneratedExpressions

const SampleableValues = Union{Expr, Symbol, AbstractString, Float64, Int, Function}
const ActionableValues = Union{Function, Symbol, Float64, Int}

const SampleableRange = Union{Float64, Int64, AbstractString, Expr, Symbol,
Tuple{Float64,
Union{Float64, Int64, AbstractString, Expr, Symbol}}}
const SampleableValues = Union{Expr,Symbol,AbstractString,Float64,Int,Function}
const ActionableValues = Union{Function,Symbol,Float64,Int}

const SampleableRange = Union{
Float64,
Int64,
AbstractString,
Expr,
Symbol,
Tuple{Float64,Union{Float64,Int64,AbstractString,Expr,Symbol}},
}

Base.convert(::Type{SampleableRange}, x::Tuple) = (Float64(x[1]), x[2])

Expand All @@ -26,8 +31,14 @@ end
@present TheoryReactionNetwork(FreeSchema) begin
(S, T)::Ob # species, transitions

(SymbolicAttributeT, DescriptiveAttributeT, SampleableAttributeT,
ModalityAttributeT, PcsOptT, PrmAttributeT)::AttrType
(
SymbolicAttributeT,
DescriptiveAttributeT,
SampleableAttributeT,
ModalityAttributeT,
PcsOptT,
PrmAttributeT,
)::AttrType

specName::Attr(S, SymbolicAttributeT)
specModality::Attr(S, ModalityAttributeT)
Expand Down Expand Up @@ -64,112 +75,150 @@ end

@acset_type FoldedReactionNetworkType(TheoryReactionNetwork)

const ReactionNetwork = FoldedReactionNetworkType{Symbol, Union{String, Symbol, Missing},
SampleableValues, Set{Symbol},
FoldedObservable, Any}
const ReactionNetwork = FoldedReactionNetworkType{
Symbol,
Union{String,Symbol,Missing},
SampleableValues,
Set{Symbol},
FoldedObservable,
Any,
}

Base.convert(::Type{Symbol}, ex::String) = Symbol(ex)

function Base.convert(::Type{Union{String, Symbol, Missing}}, ex::String)
Base.convert(::Type{Union{String,Symbol,Missing}}, ex::String) =
try
Symbol(ex)
catch
string(ex)
end
end

Base.convert(::Type{SampleableValues}, ex::String) = MacroTools.striplines(Meta.parse(ex))
Base.convert(::Type{Set{Symbol}}, ex::String) = eval(Meta.parse(ex))
Base.convert(::Type{FoldedObservable}, ex::String) = eval(Meta.parse(ex))

prettynames = Dict(:transRate => [:rate],
:specInitUncertainty => [:uncertainty, :stoch, :stochasticity],
:transPostAction => [:postAction, :post],
:transName => [:name, :interpretation],
:transPriority => [:priority],
:transProbOfSuccess => [:probability, :prob, :pos],
:transCapacity => [:cap, :capacity],
:transCycleTime => [:ct, :cycletime],
:transMaxLifeTime => [:lifetime, :maxlifetime, :maxtime, :timetolive])

defargs = Dict(:T => Dict{Symbol, Any}(:transPriority => 1, :transProbOfSuccess => 1,
:transCapacity => Inf, :transCycleTime => 0.0,
:transMaxLifeTime => Inf, :transMultiplier => 1,
:transPostAction => :(), :transName => missing),
:S => Dict{Symbol, Any}(:specInitUncertainty => 0.0, :specInitVal => 0.0,
:specCost => 0.0, :specReward => 0.0,
:specValuation => 0.0),
:P => Dict{Symbol, Any}(:prmVal => missing),
:M => Dict{Symbol, Any}(:metaVal => missing))

compilable_attrs = filter(attr -> eltype(attr) == SampleableValues,
propertynames(ReactionNetwork()))
prettynames = Dict(
:transRate => [:rate],
:specInitUncertainty => [:uncertainty, :stoch, :stochasticity],
:transPostAction => [:postAction, :post],
:transName => [:name, :interpretation],
:transPriority => [:priority],
:transProbOfSuccess => [:probability, :prob, :pos],
:transCapacity => [:cap, :capacity],
:transCycleTime => [:ct, :cycletime],
:transMaxLifeTime => [:lifetime, :maxlifetime, :maxtime, :timetolive],
)

defargs = Dict(
:T => Dict{Symbol,Any}(
:transPriority => 1,
:transProbOfSuccess => 1,
:transCapacity => Inf,
:transCycleTime => 0.0,
:transMaxLifeTime => Inf,
:transMultiplier => 1,
:transPostAction => :(),
:transName => missing,
),
:S => Dict{Symbol,Any}(
:specInitUncertainty => 0.0,
:specInitVal => 0.0,
:specCost => 0.0,
:specReward => 0.0,
:specValuation => 0.0,
),
:P => Dict{Symbol,Any}(:prmVal => missing),
:M => Dict{Symbol,Any}(:metaVal => missing),
)

compilable_attrs =
filter(attr -> eltype(attr) == SampleableValues, propertynames(ReactionNetwork()))

species_modalities = [:nonblock, :conserved, :rate]

function assign_defaults!(acs::ReactionNetwork)
for (_, v_) in defargs, (k, v) in v_
for i in 1:length(subpart(acs, k))
for i = 1:length(subpart(acs, k))
isnothing(acs[i, k]) && (subpart(acs, k)[i] = v)
end
end

foreach(i -> !isnothing(acs[i, :specModality]) ||
(subpart(acs, :specModality)[i] = Set{Symbol}()), 1:nparts(acs, :S))
foreach(
i ->
!isnothing(acs[i, :specModality]) ||
(subpart(acs, :specModality)[i] = Set{Symbol}()),
1:nparts(acs, :S),
)
k = [:specCost, :specReward, :specValuation]
foreach(k -> foreach(i -> !isnothing(acs[i, k]) || (subpart(acs, k)[i] = 0.0),
1:nparts(acs, :S)), k)

acs
foreach(
k -> foreach(
i -> !isnothing(acs[i, k]) || (subpart(acs, k)[i] = 0.0),
1:nparts(acs, :S),
),
k,
)

return acs
end

function ReactionNetwork(transitions, reactants, obs, events)
merge_acs!(ReactionNetwork(), transitions, reactants, obs, events)
return merge_acs!(ReactionNetwork(), transitions, reactants, obs, events)
end

function ReactionNetwork(transitions, reactants, obs)
merge_acs!(ReactionNetwork(), transitions, reactants, obs, [])
return merge_acs!(ReactionNetwork(), transitions, reactants, obs, [])
end

function add_obs!(acs, obs)
for p in obs
sym = p.args[3].value
i = incident(acs, sym, :obsName)
i = isempty(incident(acs, sym, :obsName)) ?
add_part!(acs, :obs; obsName = sym, obsOpts = FoldedObservable()) : i[1]
i = if isempty(incident(acs, sym, :obsName))
add_part!(acs, :obs; obsName = sym, obsOpts = FoldedObservable())
else
i[1]
end
for opt in p.args[4:end]
if isexpr(opt, :(=)) && (opt.args[1] fieldnames(FoldedObservable))
opt.args[1] == :every &&
(acs[i, :obsOpts].every = min(acs[i, :obsOpts].every, opt.args[2]))
opt.args[1] == :on && union!(acs[i, :obsOpts].on, [opt.args[2]])
elseif isexpr(opt, :tuple) || opt isa SampleableValues
push!(acs[i, :obsOpts].range,
isexpr(opt, :tuple) ? tuple(opt.args...) : opt)
push!(
acs[i, :obsOpts].range,
isexpr(opt, :tuple) ? tuple(opt.args...) : opt,
)
end
end
end

acs
return acs
end

function merge_acs!(acs::ReactionNetwork, transitions, reactants, obs, events)
foreach(t -> add_part!(acs, :T; trans = t[1][2], transRate = t[1][1], t[2]...),
transitions)
foreach(
t -> add_part!(acs, :T; trans = t[1][2], transRate = t[1][1], t[2]...),
transitions,
)
add_obs!(acs, obs)
unique!(reactants)
foreach(ev -> add_part!(acs, :E; eventTrigger = ev.trigger, eventAction = ev.action),
events)
foreach(r -> isempty(incident(acs, r, :specName)) && add_part!(acs, :S; specName = r),
reactants)

assign_defaults!(acs)
foreach(
ev -> add_part!(acs, :E; eventTrigger = ev.trigger, eventAction = ev.action),
events,
)
foreach(
r -> isempty(incident(acs, r, :specName)) && add_part!(acs, :S; specName = r),
reactants,
)

return assign_defaults!(acs)
end

include("state.jl")
include("compilers.jl")
include.(readdir(joinpath(@__DIR__, "interface"), join = true))
include.(readdir(joinpath(@__DIR__, "utils"), join = true))
include.(readdir(joinpath(@__DIR__, "operators"), join = true))
include.(readdir(joinpath(@__DIR__, "interface"); join = true))
include.(readdir(joinpath(@__DIR__, "utils"); join = true))
include.(readdir(joinpath(@__DIR__, "operators"); join = true))
include("solvers.jl")
include("optim.jl")
include("loadsave.jl")
Expand Down
Loading

0 comments on commit d0e195b

Please sign in to comment.