Commit 9634e2ac authored by jameskrw's avatar jameskrw
Browse files

minor

parent 4e5d430e
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -5,7 +5,7 @@ from typing import Dict, List, Optional, Tuple, Any
from gymnasium.utils import seeding
from vagen.env.utils.context_utils import parse_llm_raw_response, convert_numpy_to_PIL
from .env_config import PrimitiveSkillEnvConfig
from .maniskill.utils import build_env, handel_info, get_workspace_limits
from .maniskill.utils import build_env, handle_info, get_workspace_limits
from .prompts import system_prompt, init_observation_template, action_template
import vagen.env.primitive_skill.maniskill.env

@@ -71,6 +71,8 @@ class PrimitiveSkillEnv(BaseEnv):
        obs=self._render(info,init_obs=False,valid_actions=valid_actions)
        output_info["metrics"] = metrics
        self.total_reward += reward
        if isinstance(done, np.ndarray):
            done = done.item()
        return obs,reward,done,output_info
    
    def system_prompt(self):
@@ -106,7 +108,7 @@ class PrimitiveSkillEnv(BaseEnv):
    
    
    def _render(self,info,init_obs=False,valid_actions=None):
        new_info=handel_info(info.copy())
        new_info=handle_info(info.copy())
        object_positions=new_info['obj_positions']
        other_information=new_info['other_info']
        instruction=self.env.instruction()
+15 −5
Original line number Diff line number Diff line
@@ -26,27 +26,37 @@ def build_env(env_id, control_mode="pd_ee_delta_pose", stage=0, record_dir='./te
    return env


def handel_info(info):
def handle_info(info):
    obj_positions = {}
    other_info = {}
    
    # Remove specific keys
    info.pop('is_success', None)
    info.pop('num_timesteps', None)
    info.pop('elapsed_steps', None)
    info.pop('skill_success', None)
    info.pop('reward_components', None)
    
    for k, v in info.items():
        if k.endswith('_pos'):
            # convert to cm round to 2 decimal places
            obj_positions[k] = tuple(np.round(v*1000, 0).astype(int))
            # Convert position arrays to integer tuples in cm
            obj_positions[k] = tuple(np.round(v * 1000, 0).astype(int).tolist())
        elif k.endswith('_value'):
            # Convert value arrays to integers in cm
            other_info[k] = np.round(v * 1000, 0).astype(int).item()
        elif k.endswith('_size'):
            other_info[k] = tuple(np.round(v*1000, 0).astype(int))
            # Convert size arrays to integer tuples in cm
            other_info[k] = tuple(np.round(v * 1000, 0).astype(int).tolist())
        else:
            if isinstance(v, np.ndarray) and v.ndim == 0:
            # Handle all other cases
            if isinstance(v, np.ndarray):
                if v.ndim == 0:  # Scalar array
                    other_info[k] = v.item()
                else:  # Multi-dimensional array
                    other_info[k] = tuple(v.flatten().tolist())
            else:
                other_info[k] = v
    
    return {
        'obj_positions': obj_positions,
        'other_info': other_info