esa / pygmo2

A Python platform to perform parallel computations of optimisation tasks (global and local) via the asynchronous generalized island model.
https://esa.github.io/pygmo2/
Mozilla Public License 2.0
415 stars 56 forks source link

MBH invalid search space bounds [BUG] #163

Open alopezrivera opened 2 months ago

alopezrivera commented 2 months ago

Describe the bug I am running into an invalid search space bound error (Cannot generate a random real if the lower bound is larger than the upper bound, raised by the uniform_real_from_range_checks function declared in pagmo/utils/generic.hpp) when using the Monotonic Basin Hopping meta-algorithm, wrapping the NLOPT NEWUOA algorithm.

The bug happens after many successful iterations (196847 objective function evaluations as per the get_log method of the pg.mbh object), and I can consistently replicate it in my machine.

To Reproduce Single-objective optimization using:

  1. Archipelago with
    • 64 islands
    • 10000 individuals in each island
    • Unconnected topology (pygmo.unconnected) - the error replicates as well when using other topologies such as pg.fully_connected
    • Evolution for 1 evolutionary period (archi.evolve(n=1))
  2. Problem search space is n-dimensional unit hypercube. Input is bounded to the unit hypercube by implementing the get_bounds method (see code block below) of the UDP
  3. MBH wrapping NLOPT NEWUOA algorithm

get_bounds implemented in my UDP:

    def get_bounds(self) -> list[list[float]]:
        """Search space bounds"""
        return ([0]*self.problem_dimension, [1]*self.problem_dimension)

Expected behavior Optimization completes without raising errors.

Error log The following error is raised after 196847 objective function evaluations:

Traceback (most recent call last):
File "<string>", line 1, in <module>
RuntimeError: The asynchronous evolution of a pythonic island of type 'Multiprocessing island' raised an error:
multiprocessing.pool.RemoteTraceback: 
"""
Traceback (most recent call last):
File "c:\Users\antonio.lopez\AppData\Local\miniconda3\envs\combinatorial\lib\multiprocessing\pool.py", line 125, in worker
    result = (True, func(*args, **kwds))
File "c:\Users\antonio.lopez\AppData\Local\miniconda3\envs\combinatorial\lib\site-packages\pygmo\_py_islands.py", line 26, in _evolve_func_mp_pool
    new_pop = algo.evolve(pop)
ValueError: 
function: uniform_real_from_range_checks
where: D:\bld\pagmo_1684216380930\work\include\pagmo/utils/generic.hpp, 79
what: Cannot generate a random real if the lower bound is larger than the upper bound

"""

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "c:\Users\antonio.lopez\AppData\Local\miniconda3\envs\combinatorial\lib\site-packages\pygmo\_py_islands.py", line 246, in run_evolve
    return loads(res.get())
File "c:\Users\antonio.lopez\AppData\Local\miniconda3\envs\combinatorial\lib\multiprocessing\pool.py", line 774, in get
    raise self._value
ValueError: 
function: uniform_real_from_range_checks
where: D:\bld\pagmo_1684216380930\work\include\pagmo/utils/generic.hpp, 79
what: Cannot generate a random real if the lower bound is larger than the upper bound

Environment (please complete the following information):

Additional context Can provide more information as needed.

alopezrivera commented 2 months ago

I have run into the same bug when using MBH wrapping the Scipy CG optimizer. I will update this comment to include all inner optimizers with which I've ran into this problem: