Skip to content

Commit 7ec8ec6

Browse files
committed
User provides an outputs Dict{String => Tuple{Vararg{Symbol}}}, which can get specialised to eg Dict{String => Tuple{Symbol, Symbol} }} if the # of output variables is the same for all scales. This causes problems when we add :node to the Tuples. Instead, convert the dict's tuples to vectors while we're editing it, and then convert it back to a tuple once the mutation period is done. All tests pass
1 parent ca7a5ec commit 7ec8ec6

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

src/mtg/save_results.jl

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,14 @@ julia> collect(keys(preallocated_vars["Leaf"]))
110110
```
111111
"""
112112
function pre_allocate_outputs(statuses, statuses_template, reverse_multiscale_mapping, vars_need_init, outs, nsteps; type_promotion=nothing, check=true)
113-
outs_ = copy(outs)
113+
114+
outs_ = Dict()#Dict{String, Vector{Symbol}}()
115+
for i in keys(outs)
116+
outs_[i] = [outs[i]...]
117+
end
118+
119+
#Dict(i => Vector(outs[i]...) for i in keys(outs)))
120+
114121
statuses_ = copy(statuses)
115122
# Checking that organs in outputs exist in the mtg (in the statuses):
116123
if !all(i in keys(statuses) for i in keys(outs_))
@@ -168,18 +175,20 @@ function pre_allocate_outputs(statuses, statuses_template, reverse_multiscale_ma
168175
delete!(outs_, organ)
169176
else
170177
# Some still exist, we only use the ones that do:
171-
outs_[organ] = (existing_vars_requested...,)
178+
outs_[organ] = [existing_vars_requested...]
172179
end
173180
end
174181
end
175182

176183
if :node outs_[organ]
177-
outs_[organ] = (outs_[organ]..., :node)
184+
push!(outs_[organ], :node)
178185
end
179186
end
180187

188+
outs_tuple = Dict(i => Tuple(x for x in outs_[i]) for i in keys(outs_))
189+
181190
# Making the pre-allocated outputs:
182-
Dict(organ => Dict(var => [typeof(statuses_[organ][1][var])[] for n in 1:nsteps] for var in vars) for (organ, vars) in outs_)
191+
Dict(organ => Dict(var => [typeof(statuses_[organ][1][var])[] for n in 1:nsteps] for var in vars) for (organ, vars) in outs_tuple)
183192
# Note: we use the type of the variable from the first status for each organ to pre-allocate the outputs, because they are
184193
# all the same type for others.
185194
end

0 commit comments

Comments
 (0)