Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vectorization of environment using cpu in windows #581

Open
j-thapa opened this issue Sep 26, 2024 · 0 comments
Open

Vectorization of environment using cpu in windows #581

j-thapa opened this issue Sep 26, 2024 · 0 comments

Comments

@j-thapa
Copy link

j-thapa commented Sep 26, 2024

Hello,

I am trying to train RL models using vectorized environments on CPU in windows, is it feasible or not; while I am trying to do so am getting RuntimeError: Some environments have an observation space different.

I am using custom environment but even when using existing environment like PushCube am getting the same error.

For reference here is the section of code where am trying to create the vectorized environments.

Define the environment

env_id = "PickCube-v1" # Your chosen environment
obs_mode = "rgbd" # Observation mode
control_mode = "pd_ee_delta_pos" # Control mode
reward_mode = "normalized_dense" # Reward mode
robot_uids = "panda" # Robot type

def cpu_make_env(env_id, env_kwargs=dict()):
def thunk():
env = gym.make(env_id,
obs_mode=obs_mode,
reward_mode=reward_mode,
control_mode=control_mode,
robot_uids=robot_uids)
env = CPUGymWrapper(env)
return env
return thunk

if __name__ == "__main__":
import multiprocessing as mp
mp.freeze_support()  # Necessary for Windows

num_eval_envs = 8
env_kwargs = dict(obs_mode="rgbd")  # Modify your env_kwargs here

vector_cls = gym.vector.SyncVectorEnv if num_eval_envs == 1 else lambda x: gym.vector.AsyncVectorEnv(x, context="spawn")

eval_envs = vector_cls([cpu_make_env(env_id, env_kwargs) for _ in range(num_eval_envs)])

# Evaluation loop
obs, _ = eval_envs.reset(seed=0)

for _ in range(400):
    action = eval_envs.action_space.sample()  # Replace with your policy action
    obs, rew, terminated, truncated, info = eval_envs.step(action)
    print(rew)

I followed and made some changes as required from the example shown in https://maniskill.readthedocs.io/en/latest/user_guide/reinforcement_learning/setup.html#evaluation

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant