@@ -8,12 +8,17 @@ using ComponentArrays
88
99@reexport using GeneratedExpressions
1010
11- const SampleableValues = Union{Expr, Symbol, AbstractString, Float64, Int, Function}
12- const ActionableValues = Union{Function, Symbol, Float64, Int}
13-
14- const SampleableRange = Union{Float64, Int64, AbstractString, Expr, Symbol,
15- Tuple{Float64,
16- Union{Float64, Int64, AbstractString, Expr, Symbol}}}
11+ const SampleableValues = Union{Expr,Symbol,AbstractString,Float64,Int,Function}
12+ const ActionableValues = Union{Function,Symbol,Float64,Int}
13+
14+ const SampleableRange = Union{
15+ Float64,
16+ Int64,
17+ AbstractString,
18+ Expr,
19+ Symbol,
20+ Tuple{Float64,Union{Float64,Int64,AbstractString,Expr,Symbol}},
21+ }
1722
1823Base. convert (:: Type{SampleableRange} , x:: Tuple ) = (Float64 (x[1 ]), x[2 ])
1924
2631@present TheoryReactionNetwork (FreeSchema) begin
2732 (S, T):: Ob # species, transitions
2833
29- (SymbolicAttributeT, DescriptiveAttributeT, SampleableAttributeT,
30- ModalityAttributeT, PcsOptT, PrmAttributeT):: AttrType
34+ (
35+ SymbolicAttributeT,
36+ DescriptiveAttributeT,
37+ SampleableAttributeT,
38+ ModalityAttributeT,
39+ PcsOptT,
40+ PrmAttributeT,
41+ ):: AttrType
3142
3243 specName:: Attr (S, SymbolicAttributeT)
3344 specModality:: Attr (S, ModalityAttributeT)
@@ -64,112 +75,150 @@ end
6475
6576@acset_type FoldedReactionNetworkType (TheoryReactionNetwork)
6677
67- const ReactionNetwork = FoldedReactionNetworkType{Symbol, Union{String, Symbol, Missing},
68- SampleableValues, Set{Symbol},
69- FoldedObservable, Any}
78+ const ReactionNetwork = FoldedReactionNetworkType{
79+ Symbol,
80+ Union{String,Symbol,Missing},
81+ SampleableValues,
82+ Set{Symbol},
83+ FoldedObservable,
84+ Any,
85+ }
7086
7187Base. convert (:: Type{Symbol} , ex:: String ) = Symbol (ex)
7288
73- function Base. convert (:: Type{Union{String, Symbol, Missing}} , ex:: String )
89+ Base. convert (:: Type{Union{String,Symbol,Missing}} , ex:: String ) =
7490 try
7591 Symbol (ex)
7692 catch
7793 string (ex)
7894 end
79- end
8095
8196Base. convert (:: Type{SampleableValues} , ex:: String ) = MacroTools. striplines (Meta. parse (ex))
8297Base. convert (:: Type{Set{Symbol}} , ex:: String ) = eval (Meta. parse (ex))
8398Base. convert (:: Type{FoldedObservable} , ex:: String ) = eval (Meta. parse (ex))
8499
85- prettynames = Dict (:transRate => [:rate ],
86- :specInitUncertainty => [:uncertainty , :stoch , :stochasticity ],
87- :transPostAction => [:postAction , :post ],
88- :transName => [:name , :interpretation ],
89- :transPriority => [:priority ],
90- :transProbOfSuccess => [:probability , :prob , :pos ],
91- :transCapacity => [:cap , :capacity ],
92- :transCycleTime => [:ct , :cycletime ],
93- :transMaxLifeTime => [:lifetime , :maxlifetime , :maxtime , :timetolive ])
94-
95- defargs = Dict (:T => Dict {Symbol, Any} (:transPriority => 1 , :transProbOfSuccess => 1 ,
96- :transCapacity => Inf , :transCycleTime => 0.0 ,
97- :transMaxLifeTime => Inf , :transMultiplier => 1 ,
98- :transPostAction => :(), :transName => missing ),
99- :S => Dict {Symbol, Any} (:specInitUncertainty => 0.0 , :specInitVal => 0.0 ,
100- :specCost => 0.0 , :specReward => 0.0 ,
101- :specValuation => 0.0 ),
102- :P => Dict {Symbol, Any} (:prmVal => missing ),
103- :M => Dict {Symbol, Any} (:metaVal => missing ))
104-
105- compilable_attrs = filter (attr -> eltype (attr) == SampleableValues,
106- propertynames (ReactionNetwork ()))
100+ prettynames = Dict (
101+ :transRate => [:rate ],
102+ :specInitUncertainty => [:uncertainty , :stoch , :stochasticity ],
103+ :transPostAction => [:postAction , :post ],
104+ :transName => [:name , :interpretation ],
105+ :transPriority => [:priority ],
106+ :transProbOfSuccess => [:probability , :prob , :pos ],
107+ :transCapacity => [:cap , :capacity ],
108+ :transCycleTime => [:ct , :cycletime ],
109+ :transMaxLifeTime => [:lifetime , :maxlifetime , :maxtime , :timetolive ],
110+ )
111+
112+ defargs = Dict (
113+ :T => Dict {Symbol,Any} (
114+ :transPriority => 1 ,
115+ :transProbOfSuccess => 1 ,
116+ :transCapacity => Inf ,
117+ :transCycleTime => 0.0 ,
118+ :transMaxLifeTime => Inf ,
119+ :transMultiplier => 1 ,
120+ :transPostAction => :(),
121+ :transName => missing ,
122+ ),
123+ :S => Dict {Symbol,Any} (
124+ :specInitUncertainty => 0.0 ,
125+ :specInitVal => 0.0 ,
126+ :specCost => 0.0 ,
127+ :specReward => 0.0 ,
128+ :specValuation => 0.0 ,
129+ ),
130+ :P => Dict {Symbol,Any} (:prmVal => missing ),
131+ :M => Dict {Symbol,Any} (:metaVal => missing ),
132+ )
133+
134+ compilable_attrs =
135+ filter (attr -> eltype (attr) == SampleableValues, propertynames (ReactionNetwork ()))
107136
108137species_modalities = [:nonblock , :conserved , :rate ]
109138
110139function assign_defaults! (acs:: ReactionNetwork )
111140 for (_, v_) in defargs, (k, v) in v_
112- for i in 1 : length (subpart (acs, k))
141+ for i = 1 : length (subpart (acs, k))
113142 isnothing (acs[i, k]) && (subpart (acs, k)[i] = v)
114143 end
115144 end
116145
117- foreach (i -> ! isnothing (acs[i, :specModality ]) ||
118- (subpart (acs, :specModality )[i] = Set {Symbol} ()), 1 : nparts (acs, :S ))
146+ foreach (
147+ i ->
148+ ! isnothing (acs[i, :specModality ]) ||
149+ (subpart (acs, :specModality )[i] = Set {Symbol} ()),
150+ 1 : nparts (acs, :S ),
151+ )
119152 k = [:specCost , :specReward , :specValuation ]
120- foreach (k -> foreach (i -> ! isnothing (acs[i, k]) || (subpart (acs, k)[i] = 0.0 ),
121- 1 : nparts (acs, :S )), k)
122-
123- acs
153+ foreach (
154+ k -> foreach (
155+ i -> ! isnothing (acs[i, k]) || (subpart (acs, k)[i] = 0.0 ),
156+ 1 : nparts (acs, :S ),
157+ ),
158+ k,
159+ )
160+
161+ return acs
124162end
125163
126164function ReactionNetwork (transitions, reactants, obs, events)
127- merge_acs! (ReactionNetwork (), transitions, reactants, obs, events)
165+ return merge_acs! (ReactionNetwork (), transitions, reactants, obs, events)
128166end
129167
130168function ReactionNetwork (transitions, reactants, obs)
131- merge_acs! (ReactionNetwork (), transitions, reactants, obs, [])
169+ return merge_acs! (ReactionNetwork (), transitions, reactants, obs, [])
132170end
133171
134172function add_obs! (acs, obs)
135173 for p in obs
136174 sym = p. args[3 ]. value
137175 i = incident (acs, sym, :obsName )
138- i = isempty (incident (acs, sym, :obsName )) ?
139- add_part! (acs, :obs ; obsName = sym, obsOpts = FoldedObservable ()) : i[1 ]
176+ i = if isempty (incident (acs, sym, :obsName ))
177+ add_part! (acs, :obs ; obsName = sym, obsOpts = FoldedObservable ())
178+ else
179+ i[1 ]
180+ end
140181 for opt in p. args[4 : end ]
141182 if isexpr (opt, :(= )) && (opt. args[1 ] ∈ fieldnames (FoldedObservable))
142183 opt. args[1 ] == :every &&
143184 (acs[i, :obsOpts ]. every = min (acs[i, :obsOpts ]. every, opt. args[2 ]))
144185 opt. args[1 ] == :on && union! (acs[i, :obsOpts ]. on, [opt. args[2 ]])
145186 elseif isexpr (opt, :tuple ) || opt isa SampleableValues
146- push! (acs[i, :obsOpts ]. range,
147- isexpr (opt, :tuple ) ? tuple (opt. args... ) : opt)
187+ push! (
188+ acs[i, :obsOpts ]. range,
189+ isexpr (opt, :tuple ) ? tuple (opt. args... ) : opt,
190+ )
148191 end
149192 end
150193 end
151194
152- acs
195+ return acs
153196end
154197
155198function merge_acs! (acs:: ReactionNetwork , transitions, reactants, obs, events)
156- foreach (t -> add_part! (acs, :T ; trans = t[1 ][2 ], transRate = t[1 ][1 ], t[2 ]. .. ),
157- transitions)
199+ foreach (
200+ t -> add_part! (acs, :T ; trans = t[1 ][2 ], transRate = t[1 ][1 ], t[2 ]. .. ),
201+ transitions,
202+ )
158203 add_obs! (acs, obs)
159204 unique! (reactants)
160- foreach (ev -> add_part! (acs, :E ; eventTrigger = ev. trigger, eventAction = ev. action),
161- events)
162- foreach (r -> isempty (incident (acs, r, :specName )) && add_part! (acs, :S ; specName = r),
163- reactants)
164-
165- assign_defaults! (acs)
205+ foreach (
206+ ev -> add_part! (acs, :E ; eventTrigger = ev. trigger, eventAction = ev. action),
207+ events,
208+ )
209+ foreach (
210+ r -> isempty (incident (acs, r, :specName )) && add_part! (acs, :S ; specName = r),
211+ reactants,
212+ )
213+
214+ return assign_defaults! (acs)
166215end
167216
168217include (" state.jl" )
169218include (" compilers.jl" )
170- include .(readdir (joinpath (@__DIR__ , " interface" ), join = true ))
171- include .(readdir (joinpath (@__DIR__ , " utils" ), join = true ))
172- include .(readdir (joinpath (@__DIR__ , " operators" ), join = true ))
219+ include .(readdir (joinpath (@__DIR__ , " interface" ); join = true ))
220+ include .(readdir (joinpath (@__DIR__ , " utils" ); join = true ))
221+ include .(readdir (joinpath (@__DIR__ , " operators" ); join = true ))
173222include (" solvers.jl" )
174223include (" optim.jl" )
175224include (" loadsave.jl" )
0 commit comments