Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion pymc/model_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,11 @@ def _filter_non_parameter_inputs(var):
# Otherwise return all inputs
return node.inputs

blockers = set(self.model.named_vars)

def _expand(x):
if x.name:
nonlocal blockers
if x.name in blockers:
return [x]
if isinstance(x.owner, Apply):
return reversed(_filter_non_parameter_inputs(x))
Expand Down
15 changes: 15 additions & 0 deletions pymc/tests/test_model_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,3 +407,18 @@ def test_subgraph(self, var_names, vars_to_plot, compute_graph):

class TestModelNonRandomVariableRVs(BaseModelGraphTest):
model_func = model_non_random_variable_rvs


def test_model_graph_with_intermediate_named_variables():
# Issue 6421
with pm.Model() as m1:
a = pm.Normal("a", 0, 1, shape=3)
pm.Normal("b", a.mean(axis=-1), 1)
assert dict(ModelGraph(m1).make_compute_graph()) == {"a": set(), "b": {"a"}}

with pm.Model() as m2:
a = pm.Normal("a", 0, 1)
b = a + 1
b.name = "b"
pm.Normal("c", b, 1)
assert dict(ModelGraph(m2).make_compute_graph()) == {"a": set(), "c": {"a"}}