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

TypeError: cannot pickle 'ThreadLocalSampler' object: Cannot serialize AutoSampler due to ThreadLocalSampler #76

Closed
muhlbach opened this issue Jan 13, 2025 · 3 comments

Comments

@muhlbach
Copy link

Hi!

Please note that the AutoSampler cannot be serialized because at instantiation, it sets self._thread_local_sampler = ThreadLocalSampler(), and this instantiates threading.local. I think __get_state__ and __setstate__ should be updated to account for serialization of ThreadLocalSampler() attributes.

To reproduce the error, run

import dill
import optunahub

sampler = optunahub.load_module("samplers/auto_sampler").AutoSampler()
dill.dumps(sampler)

and it will fail with TypeError: cannot pickle 'ThreadLocalSampler' object.

@nabenabe0928
Copy link
Contributor

Hi @muhlbach!

Thank you for the report:)
I am working on this issue now!

@nabenabe0928
Copy link
Contributor

I will close this issue as it's been addressed by:

@muhlbach
Copy link
Author

muhlbach commented Mar 4, 2025

Amazing, thanks @nabenabe0928

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