@@ -8,12 +8,17 @@ using ComponentArrays
8
8
9
9
@reexport using GeneratedExpressions
10
10
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
+ }
17
22
18
23
Base. convert (:: Type{SampleableRange} , x:: Tuple ) = (Float64 (x[1 ]), x[2 ])
19
24
26
31
@present TheoryReactionNetwork (FreeSchema) begin
27
32
(S, T):: Ob # species, transitions
28
33
29
- (SymbolicAttributeT, DescriptiveAttributeT, SampleableAttributeT,
30
- ModalityAttributeT, PcsOptT, PrmAttributeT):: AttrType
34
+ (
35
+ SymbolicAttributeT,
36
+ DescriptiveAttributeT,
37
+ SampleableAttributeT,
38
+ ModalityAttributeT,
39
+ PcsOptT,
40
+ PrmAttributeT,
41
+ ):: AttrType
31
42
32
43
specName:: Attr (S, SymbolicAttributeT)
33
44
specModality:: Attr (S, ModalityAttributeT)
@@ -64,112 +75,150 @@ end
64
75
65
76
@acset_type FoldedReactionNetworkType (TheoryReactionNetwork)
66
77
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
+ }
70
86
71
87
Base. convert (:: Type{Symbol} , ex:: String ) = Symbol (ex)
72
88
73
- function Base. convert (:: Type{Union{String, Symbol, Missing}} , ex:: String )
89
+ Base. convert (:: Type{Union{String,Symbol,Missing}} , ex:: String ) =
74
90
try
75
91
Symbol (ex)
76
92
catch
77
93
string (ex)
78
94
end
79
- end
80
95
81
96
Base. convert (:: Type{SampleableValues} , ex:: String ) = MacroTools. striplines (Meta. parse (ex))
82
97
Base. convert (:: Type{Set{Symbol}} , ex:: String ) = eval (Meta. parse (ex))
83
98
Base. convert (:: Type{FoldedObservable} , ex:: String ) = eval (Meta. parse (ex))
84
99
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 ()))
107
136
108
137
species_modalities = [:nonblock , :conserved , :rate ]
109
138
110
139
function assign_defaults! (acs:: ReactionNetwork )
111
140
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))
113
142
isnothing (acs[i, k]) && (subpart (acs, k)[i] = v)
114
143
end
115
144
end
116
145
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
+ )
119
152
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
124
162
end
125
163
126
164
function ReactionNetwork (transitions, reactants, obs, events)
127
- merge_acs! (ReactionNetwork (), transitions, reactants, obs, events)
165
+ return merge_acs! (ReactionNetwork (), transitions, reactants, obs, events)
128
166
end
129
167
130
168
function ReactionNetwork (transitions, reactants, obs)
131
- merge_acs! (ReactionNetwork (), transitions, reactants, obs, [])
169
+ return merge_acs! (ReactionNetwork (), transitions, reactants, obs, [])
132
170
end
133
171
134
172
function add_obs! (acs, obs)
135
173
for p in obs
136
174
sym = p. args[3 ]. value
137
175
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
140
181
for opt in p. args[4 : end ]
141
182
if isexpr (opt, :(= )) && (opt. args[1 ] ∈ fieldnames (FoldedObservable))
142
183
opt. args[1 ] == :every &&
143
184
(acs[i, :obsOpts ]. every = min (acs[i, :obsOpts ]. every, opt. args[2 ]))
144
185
opt. args[1 ] == :on && union! (acs[i, :obsOpts ]. on, [opt. args[2 ]])
145
186
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
+ )
148
191
end
149
192
end
150
193
end
151
194
152
- acs
195
+ return acs
153
196
end
154
197
155
198
function 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
+ )
158
203
add_obs! (acs, obs)
159
204
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)
166
215
end
167
216
168
217
include (" state.jl" )
169
218
include (" 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 ))
173
222
include (" solvers.jl" )
174
223
include (" optim.jl" )
175
224
include (" loadsave.jl" )
0 commit comments