Commit fc5b0428 authored by jameskrw's avatar jameskrw
Browse files

new env set up

parent 4e486991
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
from abc import ABC, abstractmethod
import re
from typing import Optional, List, Tuple, Any, Dict
from copy import deepcopy
from transformers import AutoTokenizer
import torch
from PIL import Image
import numpy as np
from dataclasses import dataclass, field


@dataclass
class BaseConifg():
    init_config:Any # for interface initialization
    reset_config:Any # for interface reset
 No newline at end of file
+38 −0
Original line number Diff line number Diff line
from abc import ABC, abstractmethod
from typing import Optional, List, Tuple, Any, Dict

class BaseEnv(ABC):
    def __init__(self, env_config):
        self.env_config = env_config    
    
    
    @abstractmethod
    def step(self, action) -> Tuple[Any, float, bool, Dict]:
        """
        Execute one step in the environment.
        NOTE should also handle predefined invalid action (0)
        Args:
            action: Action to take, must be in action space, or default invalid action
            
        Returns:
            obs, reward, done, info
        """
        pass
    
    @abstractmethod
    def close(self):
        """Close the environment."""
        pass
    
    @abstractmethod
    def reset(self, seed: Optional[int] = None) -> Tuple[Any, Dict]:
        """
        Reset the environment.
        NOTE: the environment should be same for the same seed
        Args:
            seed: Seed for the environment
            
        Returns:
            obs,info
        """
        pass
 No newline at end of file
+4 −71
Original line number Diff line number Diff line
@@ -11,78 +11,11 @@ from dataclasses import dataclass, field

IMAGE_PLACEHOLDER = "<image>"    
        
@dataclass
class EnvConfig:
    """
    Dataclass for managing environment configuration.
    """
    env_name: str
    env_config: Dict[str, Any]
    interface_config: Dict[str, Any]
    seed: int

class BaseEnv(ABC):
    @abstractmethod
    def _reset(self, seed: Optional[int] = None) -> Any:
        """
        Reset the environment.
        NOTE: the environment should be same for the same seed
        Args:
            seed: Seed for the environment
            
        Returns:
            rendered environment
        """
        pass
    
    @abstractmethod
    def _step(self, action) -> Tuple[Any, float, bool, Dict]:
        """
        Execute one step in the environment.
        NOTE should also handle predefined invalid action (0)
        Args:
            action: Action to take, must be in action space, or default invalid action
            
        Returns:
            observation (rendered environment), reward, done, info
        """
        pass
    
    @abstractmethod
    def close(self):
        """Close the environment."""
        pass
    
    
    def step(self, action:Any) -> Tuple[Any, Any, Any, Any]:
        """
        Execute one step in the environment.
        Args:
            action: Action to take, must be in action space, or default invalid action
            
        Returns:
            observation (rendered environment), reward, done, info
        """
        obs,reward,done,info = self._step(action)
        return obs, reward, done, info
    
    def reset(self, seed: Optional[int] = None) -> Any:
        """
        Reset the environment.
        NOTE: the environment should be same for the same seed
        Args:
            seed: Seed for the environment  
        Returns:
            obs,info
        """
        obs,info = self._reset(seed)
        return obs,info
    
        
class BaseInterface(ABC):
    def __init__(self, env_config: Dict, interface_config: Dict = None):
        self.env_config = env_config
        self.interface_config = interface_config
    
    @classmethod
    def __init__(self, config):
        self.config = config
        
    @classmethod
    def name_repr(cls) -> str:
+0 −0

Empty file added.

Loading