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.

`StopIteration: Queue is empty` error in optimizer.maximize()

See original GitHub issue

I am running into the error StopIteration: Queue is empty, no more objects to retrieve when I run optimizer.maximize(...). Specifically, the traceback is as follows (with pieces referring to my code removed).

Traceback (most recent call last):
  File "/mnt/mesos/sandbox/.local/lib/python3.8/site-packages/bayes_opt/bayesian_optimization.py", line 179, in maximize
    x_probe = next(self._queue)
  File "/mnt/mesos/sandbox/.local/lib/python3.8/site-packages/bayes_opt/bayesian_optimization.py", line 25, in __next__
    raise StopIteration("Queue is empty, no more objects to retrieve.")
StopIteration: Queue is empty, no more objects to retrieve.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
[ ... ]
  File "/mnt/mesos/sandbox/.local/lib/python3.8/site-packages/bayes_opt/bayesian_optimization.py", line 182, in maximize
    x_probe = self.suggest(util)
  File "/mnt/mesos/sandbox/.local/lib/python3.8/site-packages/bayes_opt/bayesian_optimization.py", line 131, in suggest
    suggestion = acq_max(
  File "/mnt/mesos/sandbox/.local/lib/python3.8/site-packages/bayes_opt/util.py", line 55, in acq_max
    res = minimize(lambda x: -ac(x.reshape(1, -1), gp=gp, y_max=y_max),
  File "/mnt/mesos/sandbox/.local/lib/python3.8/site-packages/scipy/optimize/_minimize.py", line 617, in minimize
    return _minimize_lbfgsb(fun, x0, args, jac, bounds,
  File "/mnt/mesos/sandbox/.local/lib/python3.8/site-packages/scipy/optimize/lbfgsb.py", line 294, in _minimize_lbfgsb
    raise ValueError("LBFGSB - one of the lower bounds is greater than an upper bound.")
ValueError: LBFGSB - one of the lower bounds is greater than an upper bound.

I found another instance of this issue on StackOverflow. As a commenter mentioned, I am usually able to solve this problem by tweaking the values of pbounds, but it’s not a robust solution.

Thanks in advance!

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:5
  • Comments:17

github_iconTop GitHub Comments

8reactions
lingxiaolyu191231commented, Mar 2, 2022

I also faced this problem and solved this problem by downgrading scipy==1.7.3. But there were some difference. My “another exception” was:

File` "/app/docker-local-test/my_bayes_opt.py", line 885, in main
    optimizer = Bayesian_Opt(gprs=gprs, pbounds=pbounds,init_points=init_points, n_iter=n_iter, 
  File "/app/docker-local-test/my_bayes_opt.py", line 285, in Bayesian_Opt
    optimizer.maximize(init_points=init_points, n_iter=n_iter)
  File "/app/src/bayesian-optimization/bayes_opt/bayesian_optimization.py", line 268, in maximize
    x_probe = self.suggest(util)
  File "/app/src/bayesian-optimization/bayes_opt/bayesian_optimization.py", line 182, in suggest
    suggestion = acq_max(
  File "/app/src/bayesian-optimization/bayes_opt/util.py", line 65, in acq_max
    if max_acq is None or -res.fun[0] >= max_acq:
TypeError: 'float' object is not subscriptable

Tracing back to bayes-opt package, I found that minimize func from scipy.optimize package was used: see here. The latest scipy.optimize.minimize object returns fun (referred to res.fun in this line in bayes-opt pkg) as string (seen in scipy official doc) which caused my “another exception”.

Try downgrading scipy==1.7.3 might help.

3reactions
noa-codescommented, Feb 10, 2021

Ugh, and now the problem is back. No idea why.

Read more comments on GitHub >

github_iconTop Results From Across the Web

python - Queue is empty while using Bayesian optimization
StopIteration : Queue is empty, no more objects to retrieve. My code is as following: from bayes_opt import BayesianOptimization import time # ...
Read more >
bayesian-optimization 1.2.0 - PythonFix.com
The target value in the logs is wrong; How to code discrete bounds of parameters? StopIteration: Queue is empty error in optimizer.maximize().
Read more >
Complete Guide to Python StopIteration - eduCBA
Guide to Python StopIteration. Here we discuss how StopIteration works in python and how to avoid StopIteration exceptions with examples.
Read more >
Change history — Kombu 5.2.4 documentation - Celery
Add possibility to optimize lookup for queue in direct exchange set. ... This allows calling celery.bin.celery.main() to revive a worker in the same...
Read more >
tf.keras.utils.GeneratorEnqueuer | TensorFlow v2.11.0
Builds a queue out of a data generator. ... provided generator can be finite in which case the class will throw a StopIteration...
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