Skip to content

Commit ca8d315

Browse files
committed
Use the scale to ensure dependencies connect to the right ancestor (or surrogate for soft dependencies to an internal multiscale hard dep) ; without scale it was possible in hard dependency configurations reusing the model at different scales to select the right model at the wrong scale
1 parent 278cefe commit ca8d315

2 files changed

Lines changed: 12 additions & 8 deletions

File tree

src/dependencies/hard_dependencies.jl

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,14 @@ function hard_dependencies(mapping::Dict{String,T}; verbose::Bool=true) where {T
124124
# Since the hard dependencies are inserted into the soft dependency graph as children and aren't referenced elsewhere
125125
# it becomes harder to keep track of them as needed without traversing the graph
126126
# so keep tabs on them during initialisation until they're no longer needed
127-
hard_dependency_dict = Dict{Symbol, HardDependencyNode}()
127+
hard_dependency_dict = Dict{Pair{Symbol, String}, HardDependencyNode}()
128128
hard_deps = Dict()
129129

130-
hard_deps = Dict(organ => hard_dependencies(mods_scale, scale=organ, verbose=false) for (organ, mods_scale) in mods)
130+
hard_deps = Dict()
131+
132+
for (organ, mods_scale) in mods
133+
hard_deps[organ] = hard_dependencies(mods_scale, scale=organ, verbose=false)
134+
end
131135

132136
# Compute the inputs and outputs of all "root" node of the hard dependencies, so the root
133137
# node that takes control over other models appears to have the union of its own inputs (resp. outputs)
@@ -207,15 +211,15 @@ function hard_dependencies(mapping::Dict{String,T}; verbose::Bool=true) where {T
207211
# previously created nested hard dependency nodes' ancestors that have the new_node model as their caller now point to an outdated parent
208212
# (and hard dependency node in an outdated state), so their grandparent when traversing upwards might incorrectly be set to nothing
209213
# update their parent to the correct new node
210-
for (hd_sym, hd_node) in hard_dependency_dict
214+
for ((hd_sym, hd_scale), hd_node) in hard_dependency_dict
211215

212-
if hd_node.parent.process == p
216+
if (hd_node.parent.process == p) && (hd_node.parent.scale == hd_scale)
213217
hd_node.parent = new_node
214218
end
215219
end
216220

217221
# add the new node to the flat list of hard deps, as they aren't trivial to access in the dep graph, and we might need them later for a couple of things
218-
hard_dependency_dict[p] = new_node
222+
hard_dependency_dict[Pair(p, new_node.scale)] = new_node
219223

220224
# If it was a root node, we delete it as a root node.
221225
if dep_node_model in values(hard_deps[s].roots)

src/dependencies/soft_dependencies.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ function soft_dependencies(d::DependencyGraph{Dict{Symbol,HardDependencyNode}},
138138
end
139139

140140
# For multiscale mapping:
141-
function soft_dependencies_multiscale(soft_dep_graphs_roots::DependencyGraph{Dict{String,Any}}, mapping::Dict{String,A}, hard_dep_dict::Dict{Symbol, HardDependencyNode}) where {A<:Any}
141+
function soft_dependencies_multiscale(soft_dep_graphs_roots::DependencyGraph{Dict{String,Any}}, mapping::Dict{String,A}, hard_dep_dict::Dict{Pair{Symbol, String}, HardDependencyNode}) where {A<:Any}
142142
mapped_vars = mapped_variables(mapping, soft_dep_graphs_roots, verbose=false)
143143
rev_mapping = reverse_mapping(mapped_vars, all=false)
144144

@@ -178,7 +178,7 @@ function soft_dependencies_multiscale(soft_dep_graphs_roots::DependencyGraph{Dic
178178
roots_at_given_scale = soft_dep_graphs_roots.roots[i.scale][:soft_dep_graph]
179179
if !(parent_soft_dep in keys(roots_at_given_scale))
180180
master_node = ()
181-
for (hd_key, hd) in hard_dep_dict
181+
for ((hd_key, hd_scale), hd) in hard_dep_dict
182182
if parent_soft_dep == hd_key
183183
master_node = hd
184184
depth = 0
@@ -257,7 +257,7 @@ function soft_dependencies_multiscale(soft_dep_graphs_roots::DependencyGraph{Dic
257257
roots_at_given_scale = soft_dep_graphs_roots.roots[org][:soft_dep_graph]
258258
if !(parent_soft_dep in keys(roots_at_given_scale))
259259
master_node = ()
260-
for (hd_key, hd) in hard_dep_dict
260+
for ((hd_key, hd_scale), hd) in hard_dep_dict
261261
if parent_soft_dep == hd_key
262262
master_node = hd
263263
depth = 0

0 commit comments

Comments
 (0)