-
Notifications
You must be signed in to change notification settings - Fork 58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add pickle and unpickle support. #75
base: master
Are you sure you want to change the base?
Conversation
1. fcl.Transform 2. fcl.CollisionObject 3. fcl.BVHModel
Yeah it would be nice to make them serializable! It would be nice if it was defined on the original object though (vs a separate
|
But, you still need to create the FCL object in the Process right? then again, this re-occurs when you define the FCL object used the serialized dict. For example, using FCL in PyTorch's dataloader with multiprocessing support, I think it is still necessary to define a reduce method. |
Hi mikedh, I tried adding a def __iter__(self):
return iter([("a", 1), ("b", 2)]) but the object is not directly picklable: In [5]: import fcl
In [6]: tf_to_pickle = fcl.Transform(R, T)
In [7]: pickled_tf = pickle.dumps(tf_to_pickle)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[7], line 1
----> 1 pickled_tf = pickle.dumps(tf_to_pickle)
File stringsource:2, in fcl.fcl.Transform.__reduce_cython__()
TypeError: no default __reduce__ due to non-trivial __cinit__ Also, when I try to cache the data in the def __cinit__(self, *args):
self.args = args when creating the object, an In [5]: tf_to_pickle = fcl.Transform(R, T)
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Cell In[5], line 1
----> 1 tf_to_pickle = fcl.Transform(R, T)
File /mnt/e/Users/movic/python-fcl/src/fcl/fcl.pyx:56, in fcl.fcl.Transform.__cinit__()
54
55 def __cinit__(self, *args):
---> 56 self.args = args
57 if len(args) == 0:
58 self.thisptr = new defs.Transform3d()
AttributeError: 'fcl.fcl.Transform' object has no attribute 'args' so I guess the inheritance solution is still worth considering. |
Picklable objects for multithreading support.
Sometime we have a list of queries to run where each query is independent of each other. In such case, we can create a thread pool and copy the same environment in each thread to run queries in parallel. The following code gives an example of doing this:
However, objects like
fcl.BVHModel
,fcl.CollisionObject
are ==unpicklable==, making it unable to serialize them, and de-serialize them in threads:My solution to address this issue is to derive subclasses from those
Cython
class, add__init__
method to cache input arguments and__reduce__
method to return the cached data for pickling.Currently only support
fcl.Transform
,fcl.BVHModel
,fcl.CollisionObject
, with this commit and a simple magic import:from fcl import fcl2 as fcl
, the above example script can run in parallel.