Evolutionary-Intelligence / pypop

PyPop7: A Pure-Python Library for POPulation-based Black-Box Optimization (BBO), especially their *Large-Scale* versions/variants (evolutionary algorithms/swarm-based optimizers/pattern search/...). [https://pypop.rtfd.io/]
https://pypop.readthedocs.io/
GNU General Public License v3.0
186 stars 27 forks source link

How to get candidate solutions from each iteration? #72

Open BruthYU opened 1 year ago

BruthYU commented 1 year ago

Thanks for the excellent work :partying_face:

  1. I'm looking for black-box optimization algorithms to perform prompt tuning on my neural network, which requires candidate solutions from each iteration.
  2. Following the “ask-tell” form of pycma, the pseudo-code is shown as below:
    while not es.stop():
    solutions = es.ask()
    fitness = [cma.ff.rosen(s) for s in solutions]
    es.tell(solutions, fitness)
  3. Question: How can I obtain the solutions from each iteration to calculate new fitness (e.g. loss functions)?
Evolutionary-Intelligence commented 1 year ago

Thanks for your interest. Currently this libaray does not return the solution from each iteration by default. We only return the solution value for saving memory. For large-scale black-box optimization, typically returning the solutions from each iteration is memory-expensive ().

However, it is possible to do this via slightly modifying the code. Here is a related example: https://github.com/Evolutionary-Intelligence/pypop/blob/main/pypop7/optimizers/es/_repeat_fmaes.py#L74

In fact, you only need to add a variable to record it (I think this is a very simple coding task since all the optimizer class are OOP).

Evolutionary-Intelligence commented 1 year ago

If you still have questions, you can write a simple demo. And I can help to add them. Thanks for your interest again.

twoletters commented 1 year ago

I find myself in the same situation. My fitness function is costly and its computation needs to be distributed. The ask/tell interface of pycma makes it easy to do so, but I cannot see an easy way to achieve the same with pypop. Overriding method iterate might work but not without deep changes to my code base. I understand the philosophy behind the current design choices. However, providing a ask/tell interface compatible with pycma's would encourage pycma users to swap it out for pypop. Seeing that this is one of the very best BBO libraries around, it would surely attract users. What do you think?