Skip to content

Calling rvs_to_value_vars modifies model.free_RVs #5172

@michaelosthege

Description

@michaelosthege

This error was found while working on #5170:

Please provide a minimal, self-contained, and reproducible example.

with pm.Model() as pmodel:
    hyper = pm.LogNormal("hyper", mu=0)
    group = pm.LogNormal("group", mu=at.log(hyper))

    # We add potentials or deterministics that are not in topological order
    pm.Potential('group_pot', group)
    pm.Potential("hyper_pot", hyper)

    before = len(FunctionGraph(outputs=pmodel.free_RVs).toposort())

    # This call will change the model free_RVs in place!
    # rvs_to_value_vars(pmodel.deterministics, apply_transforms=True)
    rvs_to_value_vars(pmodel.potentials, apply_transforms=True)

    after = len(FunctionGraph(outputs=pmodel.free_RVs).toposort())

    assert before == after
Traceback (most recent call last):
  File "/home/ricardo/Documents/Projects/pymc3-venv/lib/python3.8/site-packages/IPython/core/interactiveshell.py", line 3418, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-9-66cc9d4cc5c8>", line 37, in <module>
    assert before == after
AssertionError

The same happens with the Deterministics, and can be checked by flipping the commented lines and commenting those referring to Potentials

Versions and main components

  • PyMC/PyMC3 Version: main
  • Aesara/Theano Version: 2.2.6

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions