jMetal / jMetalPy

A framework for single/multi-objective optimization with metaheuristics
https://jmetal.github.io/jMetalPy/index.html
MIT License
529 stars 150 forks source link

Default observable list is not emptied on Jupyter Notebooks #37

Closed benhid closed 5 years ago

benhid commented 5 years ago

Optimization algorithms internally use a default observable implementation from the Store:

https://github.com/jMetal/jMetalPy/blob/fcb9e6704b432e6bf63c8326e334d91394f8dd57/jmetal/config.py#L22

Every time a new observer (e.g., termination criterion, progress bar) is registered to an algorithm, it is added to a private list of the observable class.

In Jupyter notebooks, the re-run of a cell of the code does not empty the internal list of observables from the default observable of the algorithm, dealing with new observers being added to the list every single time. This is due to Jupyter storing the session in memory.

As for now, it is necessary to manually empty the list on every new execution:

algorithm = NSGAII(...)
+algorithm.observable.observers = []

progress_bar = ProgressBarObserver(max=max_evaluations)
algorithm.observable.register(observer=progress_bar)
benhid commented 5 years ago

By manually emptying the observers list, the termination criterion (which is added to the list in the algorithm's constructor) is never triggered.

As for now, resetting the Kernel should do the trick.

benhid commented 5 years ago

Should be fixed in b01de86