Skip to content

BUG: Deterministic variables with dims containing None break model_to_graphviz #6335

Closed
@michaelosthege

Description

@michaelosthege

Describe the issue:

When a Deterministic variable is created, one may pass a dims=(None, "time") which is a valid dims tuple.

However, when attempting a pm.model_to_graphviz later, a KeyError: None is encountered when accessing Model.dim_lengths.

Reproduceable code example:

import numpy as np
import pymc as pm

with pm.Model(coords=dict(time=np.arange(5))) as pmodel:
    data = at.as_tensor(np.ones((3, 5)))
    # This works:
    # pm.Normal("n", data, dims=(None, "time"))

    # This does not:
    pm.Deterministic("n", data, dims=(None, "time"))
    
pm.model_to_graphviz(pmodel)

Error message:

File pymc\model_graph.py:198, in <genexpr>(.0)
    195 v = self.model[var_name]
    196 if var_name in self.model.RV_dims:
    197     plate_label = " x ".join(
--> 198         f"{d} ({self._eval(self.model.dim_lengths[d])})"
    199         for d in self.model.RV_dims[var_name]
    200     )
    201 else:
    202     plate_label = " x ".join(map(str, self._eval(v.shape)))

KeyError: None

PyMC version information:

4.1.7

Context for the issue:

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions