Skip to content

TypeError: self._context,self._fmu,self.callBackFunctions,self.callbacks cannot be converted to a Python object for pickling #363

Description

@jschueller

Describe the bug
PyFMI model objects cannot be serialized, which makes it impossible from using multiprocessing-like parallel evaluations (joblib etc)

To Reproduce

import pyfmi
import pickle
model = pyfmi.load_fmu("BouncingBall.fmu")
with open("study.pkl", "wb") as f:
    pickle.dump(model, f)
with open("study.pkl", "rb") as f:
    model2 = pickle.load(f)

Observed behavior

model = <pyfmi.fmi2.FMUModelCS2 object at 0x5fe351a1a6d0>
>   ???
E   TypeError: self._context,self._fmu,self.callBackFunctions,self.callbacks cannot be converted to a Python object for pickling

Expected behavior
script passes

Versions

  • PyFMI 2.18.3 (latest)
  • openmodelica fmu

additional context
what usually causes pain is the cython attributes
maybe a path forward is override getstate/setstate operators, pass pure-python arguments only and recreate a model instance from scratch so that cython attributes are not really copied but reinstanciated

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugIssue or PR covers a bug.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions