File size: 1,573 Bytes
3b2789b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""
Abstract base class defining the standard interface for all agents.

All miner-submitted agents must implement this interface to be evaluated.
"""

from abc import ABC, abstractmethod

import gymnasium as gym
import numpy as np
import torch


class AgentInterface(ABC):
    """
    Standard interface that all miner implementations must follow.

    This ensures a consistent contract between the evaluator and any submitted agent,
    regardless of the underlying model architecture or implementation details.
    """

    def __init__(
        self,
        observation_space: gym.Space | None = None,
        action_space: gym.Space | None = None,
        seed: int | None = None,
        **kwargs,
    ):
        self.observation_space = observation_space or gym.spaces.Box(
            low=-1, high=1, shape=(100,), dtype=np.float32
        )
        self.action_space = action_space or gym.spaces.Box(
            low=-1, high=1, shape=(4,), dtype=np.float32
        )
        self.seed = seed or np.random.randint(0, 1000000)
        self.rng = np.random.default_rng(seed)

    @abstractmethod
    def act(self, obs: dict, **kwargs) -> torch.Tensor:
        """
        Take action given current observation and any additional arguments.
        """
        pass

    def reset(self) -> None:
        """
        Reset agent state for new episode.

        This is called at the beginning of each episode. Stateless agents
        can implement this as a no-op. Agents with internal memory/history
        should reset their state here.
        """
        pass