evox.workflows.std_workflow#

Module Contents#

Classes#

_NegModule

StdWorkflow

The standard workflow.

API#

class evox.workflows.std_workflow._NegModule(*args, **kwargs)[source]#

Bases: torch.nn.Module

forward(x: torch.Tensor) torch.Tensor[source]#
class evox.workflows.std_workflow.StdWorkflow(opt_direction: str = 'min')[source]#

Bases: evox.core.Workflow

The standard workflow.

Usage:

algo = BasicAlgorithm(10)
algo.setup(-10 * torch.ones(2), 10 * torch.ones(2))
prob = BasicProblem()

class solution_transform(nn.Module):
    def forward(self, x: torch.Tensor):
        return x / 5
class fitness_transform(nn.Module):
    def forward(self, f: torch.Tensor):
        return -f

monitor = EvalMonitor(full_sol_history=True)
workflow = StdWorkflow()
workflow.setup(algo, prob, solution_transform=solution_transform(), fitness_transform=fitness_transform(), monitor=monitor)
monitor = workflow.get_submodule("monitor")
workflow.init_step()
print(monitor.topk_fitness)
workflow.step()
print(monitor.topk_fitness)
# run rest of the steps ...

Initialization

Initialize the standard workflow with static arguments.

Parameters:

opt_direction – The optimization direction, can only be “min” or “max”. Defaults to “min”. If “max”, the fitness will be negated prior to fitness_transform and monitor.

setup(algorithm: evox.core.Algorithm, problem: evox.core.Problem, monitor: evox.core.Monitor | None = None, solution_transform: torch.nn.Module | None = None, fitness_transform: torch.nn.Module | None = None, device: str | torch.device | int | None = None, algorithm_setup_params: Dict[str, Any] | None = None, problem_setup_params: Dict[str, Any] | None = None, monitor_setup_params: Dict[str, Any] | None = None)[source]#

Setup the module with submodule initialization. Since all of these arguments are mutable modules to be added as submodules, they are placed here instead of __init__ and thus setup MUST be invoked after __init__.

Parameters:
  • algorithm – The algorithm to be used in the workflow.

  • problem – The problem to be used in the workflow.

  • monitors – The monitors to be used in the workflow. Defaults to None. Notice: usually, monitors can only be used when using JIT script mode.

  • solution_transform – The solution transformation function. MUST be JIT-compatible module/function for JIT trace mode or a plain module for JIT script mode (default mode). Defaults to None.

  • fitness_transforms – The fitness transformation function. MUST be JIT-compatible module/function for JIT trace mode or a plain module for JIT script mode (default mode). Defaults to None.

  • device – The device of the workflow. Defaults to None.

  • algorithm_setup_params – The arguments to be passed to algorithm.setup(**kwargs). If not provided, the algorithm.setup() will not be invoked.

  • problem_setup_params – The arguments to be passed to problem.setup(**kwargs). If not provided, the problem.setup() will not be invoked.

  • monitor_setup_params – The arguments to be passed to monitor.setup(**kwargs). If not provided, the monitor.setup() will not be invoked.

Notice

The algorithm, problem and monitor will be IN-PLACE transformed to the target device.

__getattribute__(name: str)#
__sync_with__(jit_module)[source]#
get_submodule(target: str)[source]#
_evaluate(population: torch.Tensor) torch.Tensor[source]#
_step(init: bool)[source]#
init_step()[source]#

Perform the first optimization step of the workflow.

Calls the init_step of the algorithm if overwritten; otherwise, its step method will be invoked.

step()[source]#

Perform a single optimization step using the algorithm and the problem.