Skip to content

BaseTask

evotoolkit.core.BaseTask

Bases: ABC

Abstract base class for evolutionary optimization tasks.

This class unifies the functionality of BaseEvaluator and BaseTaskConfig into a single concept, providing both evaluation capabilities and task configuration in one place.

Source code in src/evotoolkit/core/base_task.py
class BaseTask(ABC):
    """
    Abstract base class for evolutionary optimization tasks.

    This class unifies the functionality of BaseEvaluator and BaseTaskConfig
    into a single concept, providing both evaluation capabilities and task
    configuration in one place.
    """

    def __init__(self, data):
        """
        Initialize the task with input data.

        Args:
            data (Any): Task-specific input data (format varies by task type).
        """
        self._process_data(data)

    def _process_data(self, data):
        """
        Process input data and set up task_info.

        This method should be overridden by subclasses to handle
        task-specific data processing and create the task_info dict.

        Args:
            data (Any): Task-specific input data.
        """
        self.data = data
        self.task_info = {}  # Subclasses should populate this

    # === Abstract methods from BaseEvaluator ===

    @abstractmethod
    def evaluate_code(self, candidate_code: str) -> EvaluationResult:
        """
        Evaluate a candidate code solution and return evaluation result.

        Args:
            candidate_code: The code to evaluate

        Returns:
            EvaluationResult: Result of the evaluation
        """
        pass

    # === Abstract methods from BaseTaskConfig ===

    @abstractmethod
    def get_base_task_description(self) -> str:
        """
        Get the base task description for prompt generation.

        Returns:
            str: Task description text
        """
        pass

    @abstractmethod
    def make_init_sol_wo_other_info(self) -> Solution:
        """
        Create initial solution from task info without other_info.

        Returns:
            Solution: Initial solution for this task
        """
        pass

    # === Optional methods that subclasses can override ===

    def get_task_type(self) -> str:
        """
        Get the type of this task (e.g., 'Python', 'Cuda').

        Default implementation returns 'Python'. Subclasses should
        override if they represent different task types.

        Returns:
            str: Task type identifier
        """
        return "Python"

    def get_task_info(self) -> dict:
        """
        Get the task_info dictionary.

        Returns:
            dict: Task information dictionary
        """
        return self.task_info

__init__

__init__(data)

Initialize the task with input data.

Parameters:

Name Type Description Default
data Any

Task-specific input data (format varies by task type).

required
Source code in src/evotoolkit/core/base_task.py
def __init__(self, data):
    """
    Initialize the task with input data.

    Args:
        data (Any): Task-specific input data (format varies by task type).
    """
    self._process_data(data)

evaluate_code abstractmethod

evaluate_code(candidate_code: str) -> EvaluationResult

Evaluate a candidate code solution and return evaluation result.

Parameters:

Name Type Description Default
candidate_code str

The code to evaluate

required

Returns:

Name Type Description
EvaluationResult EvaluationResult

Result of the evaluation

Source code in src/evotoolkit/core/base_task.py
@abstractmethod
def evaluate_code(self, candidate_code: str) -> EvaluationResult:
    """
    Evaluate a candidate code solution and return evaluation result.

    Args:
        candidate_code: The code to evaluate

    Returns:
        EvaluationResult: Result of the evaluation
    """
    pass

get_base_task_description abstractmethod

get_base_task_description() -> str

Get the base task description for prompt generation.

Returns:

Name Type Description
str str

Task description text

Source code in src/evotoolkit/core/base_task.py
@abstractmethod
def get_base_task_description(self) -> str:
    """
    Get the base task description for prompt generation.

    Returns:
        str: Task description text
    """
    pass

make_init_sol_wo_other_info abstractmethod

make_init_sol_wo_other_info() -> Solution

Create initial solution from task info without other_info.

Returns:

Name Type Description
Solution Solution

Initial solution for this task

Source code in src/evotoolkit/core/base_task.py
@abstractmethod
def make_init_sol_wo_other_info(self) -> Solution:
    """
    Create initial solution from task info without other_info.

    Returns:
        Solution: Initial solution for this task
    """
    pass

get_task_type

get_task_type() -> str

Get the type of this task (e.g., 'Python', 'Cuda').

Default implementation returns 'Python'. Subclasses should override if they represent different task types.

Returns:

Name Type Description
str str

Task type identifier

Source code in src/evotoolkit/core/base_task.py
def get_task_type(self) -> str:
    """
    Get the type of this task (e.g., 'Python', 'Cuda').

    Default implementation returns 'Python'. Subclasses should
    override if they represent different task types.

    Returns:
        str: Task type identifier
    """
    return "Python"

get_task_info

get_task_info() -> dict

Get the task_info dictionary.

Returns:

Name Type Description
dict dict

Task information dictionary

Source code in src/evotoolkit/core/base_task.py
def get_task_info(self) -> dict:
    """
    Get the task_info dictionary.

    Returns:
        dict: Task information dictionary
    """
    return self.task_info

See the Custom Task Tutorial for a complete guide.