MPh-py / MPh

Pythonic scripting interface for Comsol Multiphysics
https://mph.readthedocs.io
MIT License
265 stars 67 forks source link

How to pickle the mph object? #179

Closed HYB777 closed 2 months ago

HYB777 commented 2 months ago

Hi, I want to use ray for multi-nodes parallel computing on the cluster. And the ray use cloudpickle to serializate the object.

But the mph object is java object, so I use JPickle for serialization.

But it raise the following error

Traceback (most recent call last): File "org.jpype.pickle.Encoder.java", line -1, in org.jpype.pickle.Encoder.pack Exception: Java Exception

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "/home/hyb/hyb/ShapeOptDemos/shape-rl/rl-project/test_pickle.py", line 33, in inband = pickle.dumps( File "/home/hyb/anaconda3/envs/hyb/lib/python3.9/site-packages/ray/cloudpickle/cloudpickle.py", line 1481, in dumps cp.dump(obj) File "/home/hyb/anaconda3/envs/hyb/lib/python3.9/site-packages/jpype/pickle.py", line 102, in reduce byte = bytes(self._encoder.pack(obj)) java.io.java.io.NotSerializableException: java.io.NotSerializableException: com.comsol.clientapi.impl.ModelClient

Thrameos commented 2 months ago

This is an issue with the jar file. Only classes marked Serializable can be serialized. Either the class needs to be marked appropriately for serialization or the field holding it must be transient.

HYB777 commented 2 months ago

This is an issue with the jar file. Only classes marked Serializable can be serialized. Either the class needs to be marked appropriately for serialization or the field holding it must be transient.

@Thrameos Thanks for your reply, I'm not very familiar with these, is there any solution for this?