Source code for evorl.ec.optimizers.ec_optimizer

 1from abc import ABCMeta, abstractmethod
 2
 3import chex
 4
 5from evorl.types import PyTreeNode, PyTreeData, PyTreeDict
 6
 7ECState = PyTreeData | PyTreeDict  # used for type hinting
 8
 9
[docs] 10class EvoOptimizer(PyTreeNode, metaclass=ABCMeta): 11 """By default, all EvoOptimizer maximize the fitness. 12 13 This is different from the behavior in EvoX. 14 """ 15
[docs] 16 @abstractmethod 17 def init(self, *args, **kwargs) -> ECState: 18 raise NotImplementedError
19
[docs] 20 @abstractmethod 21 def ask(self, state: ECState) -> tuple[chex.ArrayTree, ECState]: 22 """Generate new candidate solutions.""" 23 raise NotImplementedError
24
[docs] 25 @abstractmethod 26 def tell( 27 self, state: ECState, fitnesses: chex.ArrayTree 28 ) -> tuple[PyTreeDict, ECState]: 29 """Update the optimizer state based on the fitnesses of the candidate solutions. 30 31 Args: 32 state: The current optimizer state 33 fitnesses: The fitnesses of the candidate solutions 34 """ 35 raise NotImplementedError