evox.core.components#

Module Contents#

Classes#

Algorithm

Base class for all algorithms

Problem

Base class for all problems

Workflow

The base class for workflow.

Monitor

The monitor base class.

API#

class evox.core.components.Algorithm[source]#

Bases: evox.core.module.ModuleBase, abc.ABC

Base class for all algorithms

Notice

If a subclass have defined trace_impl of step, its corresponding init_step must be overwritten even though nothing special is to be included due to Python’s object-oriented limitations.

Initialization

Initialize the ModuleBase.

Parameters:
  • *args – Variable length argument list, passed to the parent class initializer.

  • **kwargs – Arbitrary keyword arguments, passed to the parent class initializer.

Attributes: static_names (list): A list to store static member names.

step() None[source]#

Execute the algorithm procedure for one step.

init_step() None[source]#

Initialize the algorithm and execute the algorithm procedure for the first step.

abstract evaluate(pop: torch.Tensor) torch.Tensor[source]#

Evaluate the fitness at given points. This function is a proxy function of Problem.evaluate set by workflow. By default, this functions raises NotImplementedError.

Parameters:

pop – The population.

Returns:

The fitness.

record_step() None[source]#

Record the current step.

class evox.core.components.Problem[source]#

Bases: evox.core.module.ModuleBase, abc.ABC

Base class for all problems

Initialization

Initialize the ModuleBase.

Parameters:
  • *args – Variable length argument list, passed to the parent class initializer.

  • **kwargs – Arbitrary keyword arguments, passed to the parent class initializer.

Attributes: static_names (list): A list to store static member names.

evaluate(pop: torch.Tensor) torch.Tensor[source]#

Evaluate the fitness at given points

Parameters:

pop – The population.

Returns:

The fitness.

Notice

If this function contains external evaluations that cannot be JIT by torch.jit, please wrap it with torch.jit.ignore.

class evox.core.components.Workflow(*args, **kwargs)[source]#

Bases: evox.core.module.ModuleBase, abc.ABC

The base class for workflow.

Initialization

Initialize the ModuleBase.

Parameters:
  • *args – Variable length argument list, passed to the parent class initializer.

  • **kwargs – Arbitrary keyword arguments, passed to the parent class initializer.

Attributes: static_names (list): A list to store static member names.

init_step() None[source]#

Perform the first optimization step of the workflow.

step() None[source]#

The basic function to step a workflow.

class evox.core.components.Monitor(*args, **kwargs)[source]#

Bases: evox.core.module.ModuleBase, abc.ABC

The monitor base class.

Monitors are used to monitor the evolutionary process. They contains a set of callbacks, which will be called at specific points during the execution of the workflow. Monitor itself lives outside the main workflow, so jit is not required.

To implements a monitor, implement your own callbacks and override the hooks method. The hooks method should return a list of strings, which are the names of the callbacks. Currently the supported callbacks are:

post_ask, pre_eval, post_eval, and pre_tell.

Initialization

Initialize the ModuleBase.

Parameters:
  • *args – Variable length argument list, passed to the parent class initializer.

  • **kwargs – Arbitrary keyword arguments, passed to the parent class initializer.

Attributes: static_names (list): A list to store static member names.

set_config(**config) evox.core.components.Monitor[source]#

Set the static variables according to config.

Parameters:

config – The configuration.

Returns:

This module.

record_auxiliary(aux: Dict[str, torch.Tensor]) None[source]#

Record the auxiliary information.

Parameters:

aux – The auxiliary information.

post_ask(candidate_solution: torch.Tensor) None[source]#

The hook function to be executed before the solution transformation.

Parameters:

candidate_solution – The population (candidate solutions) before the solution transformation.

pre_eval(transformed_candidate_solution: Any) None[source]#

The hook function to be executed after the solution transformation.

Parameters:

transformed_candidate_solution – The population (candidate solutions) after the solution transformation.

post_eval(fitness: torch.Tensor) None[source]#

The hook function to be executed before the fitness transformation.

Parameters:

fitness – The fitnesses before the fitness transformation.

pre_tell(transformed_fitness: torch.Tensor) None[source]#

The hook function to be executed after the fitness transformation.

Parameters:

transformed_fitness – The fitnesses after the fitness transformation.