Skip to content

recompute_test_point fails after pickling #5090

Closed
@ferrine

Description

@ferrine

Recompute_test_point fails after pickling

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

def test_pickling():
    import cloudpickle
    with pm.Model() as model:
        pm.Normal("one")
    model = cloudpickle.loads(cloudpickle.dumps(model))
    model.recompute_initial_point()

Please provide the full traceback.

Complete error traceback
>       model.recompute_initial_point()

pymc/tests/test_initial_point.py:74:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
pymc/model.py:945: in recompute_initial_point
    fn = make_initial_point_fn(model=self, return_transformed=True)
pymc/initial_point.py:185: in make_initial_point_fn
    graph.replace_all(zip(rng_nodes, new_rng_nodes), import_missing=True)
../../.pyenv/versions/3.8.7/envs/pymc3/lib/python3.8/site-packages/aesara/graph/fg.py:554: in replace_all
    self.replace(var, new_var, **kwargs)
../../.pyenv/versions/3.8.7/envs/pymc3/lib/python3.8/site-packages/aesara/graph/fg.py:515: in replace
    new_var = var.type.filter_variable(new_var, allow_convert=True)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = RandomStateType, other = RandomStateSharedVariable(<RandomState(PCG64) at 0x7FEE7A091240>), allow_convert = True

    def filter_variable(
        self, other: Union[Variable, D], allow_convert: bool = True
    ) -> Variable:
        r"""Convert a symbolic variable into this `Type`, if compatible.

        For the moment, the only `Type`\s compatible with one another are
        `TensorType` and `GpuArrayType`, provided they have the same number of
        dimensions, same broadcasting pattern, and same dtype.

        If `Type`\s are not compatible, a ``TypeError`` should be raised.

        """
        if not isinstance(other, Variable):
            # The value is not a Variable: we cast it into
            # a Constant of the appropriate Type.
            other = self.Constant(type=self, data=other)

        if other.type != self and allow_convert:
            other2 = self.convert_variable(other)
            if other2 is not None:
                return other2

        if other.type != self:
>           raise TypeError(
                "Cannot convert Type %(othertype)s "
                "(of Variable %(other)s) into Type %(self)s. "
                "You can try to manually convert %(other)s into a %(self)s."
                % dict(othertype=other.type, other=other, self=self)
            )
E           TypeError: Cannot convert Type RandomStateType (of Variable RandomStateSharedVariable(<RandomState(PCG64) at 0x7FEE7A091240>)) into Type RandomStateType. You can try to manually co
nvert RandomStateSharedVariable(<RandomState(PCG64) at 0x7FEE7A091240>) into a RandomStateType.

Related to #4582

Versions and main components

  • PyMC/PyMC3 Version: master
  • Aesara/Theano Version: master
  • Python Version: 3.9
  • Operating system: Linux
  • How did you install PyMC/PyMC3: development

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions