evox.workflows.std_workflow
¶
Module Contents¶
Classes¶
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
, andfitness_transform
will be IN-PLACE moved to the device specified bydevice
.Note
The
opt_direction
parameter determines the optimization direction. Since EvoX algorithms are designed to minimize by default, settingopt_direction="max"
will cause the fitness values to be negated before being passed tofitness_transform
and the monitor.- init_step()[source]¶
Perform the first optimization step of the workflow.
Calls the
init_step
of the algorithm if overwritten; otherwise, itsstep
method will be invoked.