evox.workflows.std_workflow

Module Contents

Classes

StdWorkflow

The standard workflow.

API

class evox.workflows.std_workflow.StdWorkflow(algorithm: evox.core.Algorithm, problem: evox.core.Problem, monitor: evox.core.Monitor | None = None, opt_direction: str = 'min', solution_transform: torch.nn.Module | None = None, fitness_transform: torch.nn.Module | None = None, device: str | torch.device | int | None = None, enable_distributed: bool = False, group: Any = None)[source]

Bases: evox.core.Workflow

The standard workflow.

Usage:

algo = BasicAlgorithm(10)
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(
    algo,
    prob,
    monitor=monitor,
    solution_transform=solution_transform(),
    fitness_transform=fitness_transform(),
)
workflow.init_step()
print(monitor.get_topk_fitness())
workflow.step()
print(monitor.get_topk_fitness())
# run rest of the steps ...

Initialization

Initialize the standard workflow with static arguments.

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

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

  • monitor – The monitors to be used in the workflow. Defaults to None.

  • 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.

  • solution_transform – The solution transformation function. MUST be compile-compatible module/function. Defaults to None.

  • fitness_transforms – The fitness transformation function. MUST be compile-compatible module/function. Defaults to None.

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

  • enable_distributed – Whether to enable distributed workflow. Defaults to False.

  • group – The group name used in the distributed workflow. Defaults to None.

Note

The algorithm, problem, solution_transform, and fitness_transform will be IN-PLACE moved to the device specified by device.

Note

The opt_direction parameter determines the optimization direction. Since EvoX algorithms are designed to minimize by default, setting opt_direction="max" will cause the fitness values to be negated before being passed to fitness_transform and the monitor.

get_submodule(target: str) Any[source]
_evaluate(population: torch.Tensor) torch.Tensor[source]
_step(init: bool = False, final: bool = False)[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.

final_step()[source]

Perform the last optimization step of the workflow.

Calls the final_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.