evox.workflows.std_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)[源代码]¶
Bases:
evox.core.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 ...
初始化
使用静态参数初始化标准工作流。
- 参数:
algorithm -- 在工作流中要使用的算法。
problem -- 在工作流中要使用的问题。
monitor -- 在工作流中使用的监视器。默认值为 None。
opt_direction -- 优化方向只能是“min”或“max”。默认为“min”。如果是“max”,适应度将在
fitness_transform
和monitor
之前取反。solution_transform -- 解决方案转换函数。必须是可编译兼容的模块/函数。默认值为 None。
fitness_transforms -- 适应度转换函数。必须是可编译兼容的模块/函数。默认值为 None。
device -- 工作流的设备。默认为 None。
enable_distributed -- 是否启用分布式工作流。默认值为 False。
group -- 在分布式工作流中使用的组名。默认为 None。
备注
algorithm
、problem
、solution_transform
和fitness_transform
将会被原地移动到由device
指定的设备上。备注
opt_direction
参数决定了优化的方向。由于 EvoX 算法默认设计为最小化,因此设置opt_direction="max"
会在将适应度值传递给fitness_transform
和监视器之前将其取反。