@@ -11,7 +11,9 @@ using ComponentArrays
1111const SampleableValues = Union{Expr, Symbol, AbstractString, Float64, Int, Function}
1212const ActionableValues = Union{Function, Symbol, Float64, Int}
1313
14- const SampleableRange = Union{Float64, Int64, AbstractString, Expr, Symbol, Tuple{Float64, Union{Float64, Int64, AbstractString, Expr, Symbol}}}
14+ const SampleableRange = Union{Float64, Int64, AbstractString, Expr, Symbol,
15+ Tuple{Float64,
16+ Union{Float64, Int64, AbstractString, Expr, Symbol}}}
1517
1618Base. convert (:: Type{SampleableRange} , x:: Tuple ) = (Float64 (x[1 ]), x[2 ])
1719
2426@present TheoryReactionNetwork (FreeSchema) begin
2527 (S, T):: Ob # species, transitions
2628
27- (SymbolicAttributeT, DescriptiveAttributeT, SampleableAttributeT,
28- ModalityAttributeT, PcsOptT, PrmAttributeT):: AttrType
29+ (SymbolicAttributeT, DescriptiveAttributeT, SampleableAttributeT,
30+ ModalityAttributeT, PcsOptT, PrmAttributeT):: AttrType
2931
3032 specName:: Attr (S, SymbolicAttributeT)
3133 specModality:: Attr (S, ModalityAttributeT)
6264
6365@acset_type FoldedReactionNetworkType (TheoryReactionNetwork)
6466
65- const ReactionNetwork = FoldedReactionNetworkType{Symbol, Union{String, Symbol, Missing}, SampleableValues, Set{Symbol}, FoldedObservable, Any}
67+ const ReactionNetwork = FoldedReactionNetworkType{Symbol, Union{String, Symbol, Missing},
68+ SampleableValues, Set{Symbol},
69+ FoldedObservable, Any}
6670
6771Base. convert (:: Type{Symbol} , ex:: String ) = Symbol (ex)
68- Base. convert (:: Type{Union{String, Symbol, Missing}} , ex:: String ) = try Symbol (ex) catch ; string (ex) end
72+ Base. convert (:: Type{Union{String, Symbol, Missing}} , ex:: String ) =
73+ try
74+ Symbol (ex)
75+ catch
76+ string (ex)
77+ end
6978Base. convert (:: Type{SampleableValues} , ex:: String ) = MacroTools. striplines (Meta. parse (ex))
7079Base. convert (:: Type{Set{Symbol}} , ex:: String ) = eval (Meta. parse (ex))
7180Base. convert (:: Type{FoldedObservable} , ex:: String ) = eval (Meta. parse (ex))
7281
73- prettynames = Dict (
74- :transRate => [:rate ],
75- :specInitUncertainty => [:uncertainty , :stoch , :stochasticity ],
76- :transPostAction => [:postAction , :post ],
77- :transName => [:name , :interpretation ],
78- :transPriority => [:priority ],
79- :transProbOfSuccess => [:probability , :prob , :pos ],
80- :transCapacity => [:cap , :capacity ],
81- :transCycleTime => [:ct , :cycletime ],
82- :transMaxLifeTime => [:lifetime , :maxlifetime , :maxtime , :timetolive ]
83- )
84-
85- defargs = Dict (
86- :T => Dict {Symbol, Any} (:transPriority => 1 , :transProbOfSuccess => 1 , :transCapacity => Inf , :transCycleTime => 0. ,
87- :transMaxLifeTime => Inf , :transMultiplier => 1 , :transPostAction => :(), :transName => missing ),
88- :S => Dict {Symbol, Any} (:specInitUncertainty => .0 , :specInitVal => .0 , :specCost => .0 , :specReward => .0 , :specValuation => .0 ),
89- :P => Dict {Symbol, Any} (:prmVal => missing ),
90- :M => Dict {Symbol, Any} (:metaVal => missing )
91- )
92-
93- compilable_attrs = filter (attr -> eltype (attr) == SampleableValues, propertynames (ReactionNetwork ()))
82+ prettynames = Dict (:transRate => [:rate ],
83+ :specInitUncertainty => [:uncertainty , :stoch , :stochasticity ],
84+ :transPostAction => [:postAction , :post ],
85+ :transName => [:name , :interpretation ],
86+ :transPriority => [:priority ],
87+ :transProbOfSuccess => [:probability , :prob , :pos ],
88+ :transCapacity => [:cap , :capacity ],
89+ :transCycleTime => [:ct , :cycletime ],
90+ :transMaxLifeTime => [:lifetime , :maxlifetime , :maxtime , :timetolive ])
91+
92+ defargs = Dict (:T => Dict {Symbol, Any} (:transPriority => 1 , :transProbOfSuccess => 1 ,
93+ :transCapacity => Inf , :transCycleTime => 0.0 ,
94+ :transMaxLifeTime => Inf , :transMultiplier => 1 ,
95+ :transPostAction => :(), :transName => missing ),
96+ :S => Dict {Symbol, Any} (:specInitUncertainty => 0.0 , :specInitVal => 0.0 ,
97+ :specCost => 0.0 , :specReward => 0.0 ,
98+ :specValuation => 0.0 ),
99+ :P => Dict {Symbol, Any} (:prmVal => missing ),
100+ :M => Dict {Symbol, Any} (:metaVal => missing ))
101+
102+ compilable_attrs = filter (attr -> eltype (attr) == SampleableValues,
103+ propertynames (ReactionNetwork ()))
94104
95105species_modalities = [:nonblock , :conserved , :rate ]
96106
@@ -101,26 +111,36 @@ function assign_defaults!(acs::ReactionNetwork)
101111 end
102112 end
103113
104- foreach (i -> isassigned (subpart (acs, :specModality ), i) || (subpart (acs, :specModality )[i] = Set {Symbol} ()), 1 : nparts (acs, :S ))
114+ foreach (i -> isassigned (subpart (acs, :specModality ), i) ||
115+ (subpart (acs, :specModality )[i] = Set {Symbol} ()), 1 : nparts (acs, :S ))
105116 k = [:specCost , :specReward , :specValuation ]
106- foreach (k -> foreach (i -> isassigned (subpart (acs, k), i) || (subpart (acs, k)[i] = .0 ), 1 : nparts (acs, :S )), k)
117+ foreach (k -> foreach (i -> isassigned (subpart (acs, k), i) || (subpart (acs, k)[i] = 0.0 ),
118+ 1 : nparts (acs, :S )), k)
107119
108120 acs
109121end
110122
111- ReactionNetwork (transitions, reactants, obs, events) = merge_acs! (ReactionNetwork (), transitions, reactants, obs, events)
112- ReactionNetwork (transitions, reactants, obs) = merge_acs! (ReactionNetwork (), transitions, reactants, obs, [])
123+ function ReactionNetwork (transitions, reactants, obs, events)
124+ merge_acs! (ReactionNetwork (), transitions, reactants, obs, events)
125+ end
126+ function ReactionNetwork (transitions, reactants, obs)
127+ merge_acs! (ReactionNetwork (), transitions, reactants, obs, [])
128+ end
113129
114130function add_obs! (acs, obs)
115- for p in obs
116- sym = p. args[3 ]. value; i = incident (acs, sym, :obsName )
117- i = isempty (incident (acs, sym, :obsName )) ? add_part! (acs, :obs ; obsName= sym, obsOpts= FoldedObservable ()) : i[1 ]
131+ for p in obs
132+ sym = p. args[3 ]. value
133+ i = incident (acs, sym, :obsName )
134+ i = isempty (incident (acs, sym, :obsName )) ?
135+ add_part! (acs, :obs ; obsName = sym, obsOpts = FoldedObservable ()) : i[1 ]
118136 for opt in p. args[4 : end ]
119137 if isexpr (opt, :(= )) && (opt. args[1 ] ∈ fieldnames (FoldedObservable))
120- opt. args[1 ] == :every && (acs[i, :obsOpts ]. every = min (acs[i, :obsOpts ]. every, opt. args[2 ]))
138+ opt. args[1 ] == :every &&
139+ (acs[i, :obsOpts ]. every = min (acs[i, :obsOpts ]. every, opt. args[2 ]))
121140 opt. args[1 ] == :on && union! (acs[i, :obsOpts ]. on, [opt. args[2 ]])
122141 elseif isexpr (opt, :tuple ) || opt isa SampleableValues
123- push! (acs[i, :obsOpts ]. range, isexpr (opt, :tuple ) ? tuple (opt. args... ) : opt)
142+ push! (acs[i, :obsOpts ]. range,
143+ isexpr (opt, :tuple ) ? tuple (opt. args... ) : opt)
124144 end
125145 end
126146 end
@@ -129,24 +149,30 @@ function add_obs!(acs, obs)
129149end
130150
131151function merge_acs! (acs:: ReactionNetwork , transitions, reactants, obs, events)
132- foreach (t -> add_part! (acs, :T ; trans= t[1 ][2 ], transRate= t[1 ][1 ], t[2 ]. .. ), transitions)
133- add_obs! (acs, obs); unique! (reactants)
134- foreach (ev -> add_part! (acs, :E ; eventTrigger= ev. trigger, eventAction= ev. action), events)
135- foreach (r -> isempty (incident (acs, r, :specName )) && add_part! (acs, :S ; specName= r), reactants)
152+ foreach (t -> add_part! (acs, :T ; trans = t[1 ][2 ], transRate = t[1 ][1 ], t[2 ]. .. ),
153+ transitions)
154+ add_obs! (acs, obs)
155+ unique! (reactants)
156+ foreach (ev -> add_part! (acs, :E ; eventTrigger = ev. trigger, eventAction = ev. action),
157+ events)
158+ foreach (r -> isempty (incident (acs, r, :specName )) && add_part! (acs, :S ; specName = r),
159+ reactants)
136160
137161 assign_defaults! (acs)
138162end
139163
140- include (" state.jl" ); include (" compilers.jl" )
141- include .(readdir (joinpath (@__DIR__ , " interface" ), join= true ))
142- include .(readdir (joinpath (@__DIR__ , " utils" ), join= true ))
143- include .(readdir (joinpath (@__DIR__ , " operators" ), join= true ))
144- include (" solvers.jl" ); include (" optim.jl" )
164+ include (" state.jl" )
165+ include (" compilers.jl" )
166+ include .(readdir (joinpath (@__DIR__ , " interface" ), join = true ))
167+ include .(readdir (joinpath (@__DIR__ , " utils" ), join = true ))
168+ include .(readdir (joinpath (@__DIR__ , " operators" ), join = true ))
169+ include (" solvers.jl" )
170+ include (" optim.jl" )
145171include (" loadsave.jl" )
146172
147173# Catlab.jl hack: bypass @isdefined check
148174function Base. getindex (m:: Catlab.ColumnImplementations.PartialVecMap , x:: Int )
149175 m. v[x]
150176end
151177
152- end
178+ end
0 commit comments