Commit 0d0ce9ca authored by jameskrw's avatar jameskrw
Browse files

tested navigation

parent 563e45e7
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
from .sokoban import SokobanEnv,SokobanEnvConfig
from .frozenlake import FrozenLakeEnv,FrozenLakeEnvConfig, FrozenLakeService
from .navigation import NavigationEnv, NavigationEnvConfig
from .navigation import NavigationEnv, NavigationEnvConfig, NavigationServiceConfig, NavigationService
from .svg import SVGEnv, SvgEnvConfig, SVGService

REGISTERED_ENV = {
@@ -15,7 +15,9 @@ REGISTERED_ENV = {
    },
    "navigation": {
        "env_cls": NavigationEnv,
        "config_cls": NavigationEnvConfig
        "config_cls": NavigationEnvConfig,
        "service_cls": NavigationService,
        "service_config_cls": NavigationServiceConfig
    },
    "svg": {
        "env_cls": SVGEnv,
+2 −0
Original line number Diff line number Diff line
from .env import NavigationEnv
from .env_config import NavigationEnvConfig
from .service_config import NavigationServiceConfig
from .service import NavigationService
 No newline at end of file
+2 −1
Original line number Diff line number Diff line
@@ -11,9 +11,10 @@ class NavigationEnvConfig(BaseEnvConfig):
    fov: int = 100
    multiview: bool = False
    visual_env: bool = True
    max_actions_per_step: int = 1
    max_actions_per_step: int = 10
    max_action_penalty: float = -0.1
    format_reward: float = 0.5
    gpu_device: int = 0

    def config_id(self) -> str:
        """Generate a unique identifier for this configuration."""
+8 −41
Original line number Diff line number Diff line
@@ -42,24 +42,16 @@ class NavigationService(BaseService):
            if env_name != 'navigation':
                return env_id, None, f"Expected environment type 'navigation', got '{env_name}'"
            
            try:
                # Get Navigation specific configuration
                env_config_dict = config.get('env_config', {})
                
                # Create environment config
            env_config_dict = config['env_config']
            env_config = NavigationEnvConfig(**env_config_dict)
                
                # Create environment
            env = NavigationEnv(env_config)
                
            return env_id, (env, env_config), None
            except Exception as e:
                return env_id, None, str(e)
           
        
        for i, env_id in enumerate(ids2configs.keys()):
            # Select GPU with the least load
            selected_gpu = min(self.device_status, key=lambda x: len(self.device_status[x]))
            ids2configs[env_id]['gpu_device'] = selected_gpu
            ids2configs[env_id]['env_config']['gpu_device'] = selected_gpu
            self.device_status[selected_gpu].add(env_id)
            
        # Use ThreadPoolExecutor for parallel creation
@@ -97,16 +89,11 @@ class NavigationService(BaseService):
        
        # Define worker function
        def reset_single_env(env_id, seed):     
            try:
                if env_id not in self.environments:
                    return env_id, None, f"Environment {env_id} not found"
                
            env = self.environments[env_id]
            observation, info = env.reset(seed=seed)
            serialized_observation = serialize_observation(observation)
            return env_id, (serialized_observation, info), None
            except Exception as e:
                return env_id, None, str(e)
            
        
        # Use ThreadPoolExecutor for parallel reset
        with ThreadPoolExecutor(max_workers=self.max_workers) as executor:
@@ -143,16 +130,11 @@ class NavigationService(BaseService):
        
        # Define worker function
        def step_single_env(env_id, action):
            try:
                if env_id not in self.environments:
                    return env_id, None, f"Environment {env_id} not found"
                
            env = self.environments[env_id]
            observation, reward, done, info = env.step(action)
            serialized_observation = serialize_observation(observation)
            return env_id, (serialized_observation, reward, done, info), None
            except Exception as e:
                return env_id, None, str(e)
            
        
        # Use ThreadPoolExecutor for parallel step
        with ThreadPoolExecutor(max_workers=self.max_workers) as executor:
@@ -188,14 +170,9 @@ class NavigationService(BaseService):
        
        # Define worker function
        def compute_reward_single_env(env_id):
            try:
                if env_id not in self.environments:
                    return env_id, None, f"Environment {env_id} not found"
                
            env = self.environments[env_id]
            return env_id, env.compute_reward(), None
            except Exception as e:
                return env_id, None, str(e)
           
        
        # Use ThreadPoolExecutor for parallel computation
        with ThreadPoolExecutor(max_workers=self.max_workers) as executor:
@@ -231,14 +208,9 @@ class NavigationService(BaseService):
        
        # Define worker function
        def get_system_prompt_single_env(env_id):
            try:
                if env_id not in self.environments:
                    return env_id, None, f"Environment {env_id} not found"
                
            env = self.environments[env_id]
            return env_id, env.system_prompt(), None
            except Exception as e:
                return env_id, None, str(e)
       
        
        # Use ThreadPoolExecutor for parallel retrieval
        with ThreadPoolExecutor(max_workers=self.max_workers) as executor:
@@ -273,15 +245,10 @@ class NavigationService(BaseService):
        
        # Define worker function
        def close_single_env(env_id):                
            try:
                if env_id not in self.environments:
                    return f"Environment {env_id} not found"
                
            env = self.environments[env_id]
            env.close()
            return None
            except Exception as e:
                return str(e)
            
        
        # Use ThreadPoolExecutor for parallel closing
        with ThreadPoolExecutor(max_workers=self.max_workers) as executor:
+1 −1
Original line number Diff line number Diff line
@@ -3,4 +3,4 @@ from dataclasses import dataclass, fields,field

@dataclass
class NavigationServiceConfig(BaseServiceConfig):
    devices=[0]
 No newline at end of file
    devices: list = field(default_factory=lambda: [0])
 No newline at end of file
Loading