File size: 2,519 Bytes
5fed0fc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
"""

Abstract base class for evaluation runners.

"""

from abc import ABC, abstractmethod
from dataclasses import dataclass, field
from enum import Enum
from pathlib import Path
from typing import Any, Dict, Optional


class EvaluationStatus(Enum):
    """Status of an evaluation."""
    SUCCESS = "success"
    ERROR = "error"
    TIMEOUT = "timeout"
    SKIPPED = "skipped"


@dataclass
class EvaluationResult:
    """Result of an evaluation run."""

    problem_id: str
    score: Optional[float] = None
    status: EvaluationStatus = EvaluationStatus.SUCCESS
    message: Optional[str] = None
    logs: Optional[str] = None
    duration_seconds: Optional[float] = None
    metadata: Dict[str, Any] = field(default_factory=dict)

    @property
    def success(self) -> bool:
        return self.status == EvaluationStatus.SUCCESS

    def __repr__(self) -> str:
        if self.success:
            return f"EvaluationResult(problem={self.problem_id}, score={self.score})"
        return f"EvaluationResult(problem={self.problem_id}, status={self.status.value}, message={self.message})"


class Runner(ABC):
    """Abstract base class for evaluation runners."""

    @abstractmethod
    def evaluate(

        self,

        problem_id: str,

        solution_code: str,

        *,

        timeout: Optional[int] = None,

    ) -> EvaluationResult:
        """

        Evaluate a solution for a given problem.



        Args:

            problem_id: Problem identifier (e.g., "flash_attn", "gemm_optimization/squares")

            solution_code: Solution source code

            timeout: Optional timeout in seconds



        Returns:

            EvaluationResult with score and status

        """
        pass

    @abstractmethod
    def evaluate_file(

        self,

        problem_id: str,

        solution_path: Path,

        *,

        timeout: Optional[int] = None,

    ) -> EvaluationResult:
        """

        Evaluate a solution file for a given problem.



        Args:

            problem_id: Problem identifier

            solution_path: Path to solution file

            timeout: Optional timeout in seconds



        Returns:

            EvaluationResult with score and status

        """
        pass

    def get_problem_path(self, problem_id: str) -> Path:
        """Get the path to a problem directory."""
        # Will be implemented by subclasses based on their base directory
        raise NotImplementedError