I am trying to simulate multiple Modelica FMUs in parallel using python/pyfmi and multiprocessing. However I am not able to return any pyfmi FMI objects from the subprocesses once the FMUs are initialized. It seems that pyfmi FMI objects (e.g. pyfmi.fmi.FMUModelCS2 or pyfmi.fmi.FMUState2) are not pickable. I also tried dill to pickle, which doesn't work for me eather. With dill the objects are picklable though, meaning no error, but somehow corrupted if I try to reload them afterwards. Does anyone have an idea of how to solve this issue? Thanks!
相关问题
- Flush single app django 1.9
- Abstract switch in Modelica
- Modelica libraries use different MSL version
- How to stop a dbus gobject loop
- Python's difflib SequenceMatcher speed up
相关文章
- Is there a size limit for HTTP response headers on
- Does there exist empty class in python?
- ImportError: No module named twisted.persisted.sty
- Get a header with Python and convert in JSON (requ
- python unit testing methods inside of classes
- Requiring tensorflow with Python 2.7.11 occurs Imp
- Generate Fortran subroutine with SymPy codegen for
- Python - What is a lazy property?
The pathos module allows multiprocessing with a similar interface as the
multiprocessing
but relies on dill instead ofpickle
for serialisation. ThePool
method works for parallel execution ofmodel.simulate
, provided that results are handled in memory:Note in the above snippet that it is necessary to handle results in memory :
options=dict(result_handling="memory")
. The default is to use temporary files which works for when the amount of simulations is small. However, the longer the queue, the higher the chance to get something likewhich I fail to grasp.
I faced a similar problem when I created EstimationPy. I ended up creating a wrapper for running parallel simulation of the same FMU using multiple processes.
I suggest you to look at the implementation here https://github.com/lbl-srg/EstimationPy/blob/master/estimationpy/fmu_utils/fmu_pool.py
And to the example http://lbl-srg.github.io/EstimationPy/modules/examples/first_order.html#run-multiple-simulations
The problem is that pyfmi.fmiFMUModelCS2 is a Cython class dependent on external libraries which makes it unpickable. So it is not possible unfortunately.
If you want to use multiprocessing the only way forward that I see is that you first create the processes and then load the FMUs into the separate processes. In this way you do not need to pickle the classes.