evox.workflows.std_workflow
#
Module Contents#
Classes#
The standard workflow. |
API#
- 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 thussetup
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, thealgorithm.setup()
will not be invoked.problem_setup_params – The arguments to be passed to
problem.setup(**kwargs)
. If not provided, theproblem.setup()
will not be invoked.monitor_setup_params – The arguments to be passed to
monitor.setup(**kwargs)
. If not provided, themonitor.setup()
will not be invoked.
Notice
The algorithm, problem and monitor will be IN-PLACE transformed to the target device.
- __getattribute__(name: str)#