Skip to content
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

Error while saving DaskContactFrequency & DaskContactTrajectory instances to pkl file #134

Open
varun-go opened this issue May 23, 2024 · 2 comments

Comments

@varun-go
Copy link

When attempting to save a DaskContactTrajectory instance or DaskContactTrajectory instance to a pkl file, I receive the following error message:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[13], line 1
----> 1 freq.save_to_file("contacts.p")

File /panfs/jay/groups/21/sarupria/gopal145/software/contact_map/contact_map/contact_map.py:371, in ContactObject.save_to_file(self, filename, mode)
    356 """Save this object to the given file.
    357 
    358 Parameters
   (...)
    368 from_file : load from generated file
    369 """
    370 with open(filename, mode+"b") as f:
--> 371     pickle.dump(self, f)

AttributeError: Can't pickle local object 'Client.__init__.<locals>.<lambda>'


 

From an online search, it appears that saving to a pkl file should avoid having lambda functions calls in the pickled data. I am unable to find any lambda function calls in the save_to_file method or in the dask_runner module.

@dwhswenson
Copy link
Owner

At a glance, it looks like the issue is that DaskContactTrajectory contains a reference to the Dask Client, which apparently can't be pickled.

Probably the solution here will be to add a method to convert a DaskContactTrajectory to a regular ContactTrajectory (after the computation is done). Then you should be able to pickle the ContactTrajectory as usual (and disable pickling of DaskContactTrajectory). My assumption is that once you're saving it, you're probably not worried about keeping details of the Dask Client, you just want to be able to reload your contacts!

Let me know if that sounds like a solution that would meet your needs -- or especially let me know if there's a reason that solution does not meet your needs. I probably won't have a chance to implement that until at least Monday/Tuesday at the earliest.

@varun-go
Copy link
Author

Thank you for your response!

Your solution is exactly what I had in mind, and that works for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants