question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot serialize Queue

See original GitHub issue

The following code works with bayesian-optimization==1.2.0, but fails with bayesian-optimization==1.3.0 (or the latest one).

import ray
from ray import tune
from ray.tune.search import ConcurrencyLimiter
from ray.tune.search.bayesopt import BayesOptSearch


def scoreFn(config):
    print(config)
    tune.report(
        ret=config['x'] * 1.2 + config['y'] * 1.2
    )

bo = BayesOptSearch(
    space={
        'x': (0.2, 0.95),
        'y': (0.5, 2.5),
    },
    metric='ret',
    mode='min',
)

tuner = tune.Tuner(
    scoreFn,
    tune_config=tune.TuneConfig(
        num_samples=24,
        search_alg=ConcurrencyLimiter(bo, max_concurrent=4),
    ),
)
results = tuner.fit()

The error in bayesian-optimization==1.3.0:

Traceback (most recent call last):
  File "/run/media/adam/Data/search_bo.py", line 38, in <module>
    tuner = tune.Tuner(
  File "/run/media/adam/Data/venv-py310/lib/python3.10/site-packages/ray/tune/tuner.py", line 152, in __init__
    self._local_tuner = TunerInternal(**kwargs)
  File "/run/media/adam/Data/venv-py310/lib/python3.10/site-packages/ray/tune/impl/tuner_internal.py", line 123, in __init__
    pickle.dump(self, fp)
  File "/run/media/adam/Data/venv-py310/lib/python3.10/site-packages/ray/cloudpickle/cloudpickle_fast.py", line 57, in dump
    ).dump(obj)
  File "/run/media/adam/Data/venv-py310/lib/python3.10/site-packages/ray/cloudpickle/cloudpickle_fast.py", line 627, in dump
    return Pickler.dump(self, obj)
TypeError: cannot pickle '_thread.lock' object

After bisecting, the code works if I revert commit 8cc8d9b. A quick fix would be reverting that commit in the master branch.

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:6

github_iconTop GitHub Comments

1reaction
bwheelz36commented, Oct 26, 2022

OK @chengscott - I think may ray issues were I started with python 3.11 which wouldn’t install ray at all, then I went to 3.6 which installed but but must have been 1.x. With 3.10 it worked fine.

I’ve done what you suggested and reverted back to the old Queue implementation. I have also added a test based on @cosmicBboy’s code to ensure that the the BayesianOptimization can be serialized. I will release this under 1.3.1 shortly.

1reaction
cosmicBboycommented, Oct 26, 2022

can confirm this issue comes up when trying to pickle the BayesianOptimization object:

import pickle
from bayes_opt import BayesianOptimization

optimizer = BayesianOptimization(
    f=None,
    pbounds={"x": (-2, 2), "y": (-3, 3)},
    verbose=2,
    random_state=1,
)

pickle.dump(optimizer, open('p', 'w'))
Read more comments on GitHub >

github_iconTop Results From Across the Web

In C#, How can I serialize Queue<>? (.Net 2.0)
A queue is pretty trivial to implement. You can easily create your own that also implements IList so that it will be serializable....
Read more >
[MySQL] Queuing database migration gives me "You ...
You cannot serialize or unserialize PDO instances. Comming from src\Illuminate\Queue\Queue.php:139 . This is my configuration:.
Read more >
Unable to De-Serialize Encrypted Generic Queue - MSDN
I think the problem must be that I can not serialize a collection. Is there any way to serialize a collection, like in...
Read more >
Cannot serialize the DataTable - Studio
Hello Team, I'm creating a orchestration process, after adding items to the queue, while creating task based on transaction item getting ...
Read more >
You cannot serialize or unserialize PDO instances
You need to find the place where you are serializing a pdo instance. Perhaps you are sending a connection or similar to a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found