HumanCompatibleAI / overcooked_ai

A benchmark environment for fully cooperative human-AI performance.
https://arxiv.org/abs/1910.05789
MIT License
714 stars 152 forks source link

Pass action into env.step for gym env #113

Closed RupaliBhati closed 1 year ago

RupaliBhati commented 1 year ago

The action should be a tuple with the joint action of the primary and secondary agents in index format. I tried the following code:

mdp = OvercookedGridworld.from_layout_name("cramped_room") base_env = OvercookedEnv.from_mdp(mdp, horizon=500) env = gym.make("Overcooked-v0",base_env = base_env, featurize_fn =base_env.featurize_state_mdp) env.reset() env.step((0,0))

I got the following error:

AttributeError Traceback (most recent call last) Cell In[5], line 1 ----> 1 env.step((0,0))

File ~/.pyenv/versions/3.9.1/envs/myvenv/lib/python3.9/site-packages/gym/wrappers/order_enforcing.py:37, in OrderEnforcing.step(self, action) 35 if not self._has_reset: 36 raise ResetNeeded("Cannot call env.step() before calling env.reset()") ---> 37 return self.env.step(action)

File ~/.pyenv/versions/3.9.1/envs/myvenv/lib/python3.9/site-packages/gym/wrappers/step_api_compatibility.py:52, in StepAPICompatibility.step(self, action) 43 def step(self, action): 44 """Steps through the environment, returning 5 or 4 items depending on new_step_api. 45 46 Args: (...) 50 (observation, reward, terminated, truncated, info) or (observation, reward, done, info) 51 """ ---> 52 step_returns = self.env.step(action) 53 if self.new_step_api: 54 return step_to_new_api(step_returns)

File ~/.pyenv/versions/3.9.1/envs/myvenv/lib/python3.9/site-packages/gym/wrappers/env_checker.py:39, in PassiveEnvChecker.step(self, action) 37 return env_step_passive_checker(self.env, action) 38 else: ... -> 1851 for obj in state.objects.values(): 1852 if obj.position in counters_considered: 1853 counter_objects_dict[obj.name].append(obj.position)

AttributeError: 'OvercookedGridworld' object has no attribute 'objects'

I tried many alternatives but none of them worked. Can you share an example of what I should pass in the env.step function?

jyan1999 commented 1 year ago

Hi,

Thanks for bringing this issue up. I looked into this briefly and it looks like it is a hidden bug in the code. There is a quick one-line fix for this issue. If you go to overcooked_env.py, you just need to change

ob_p0, ob_p1 = self.featurize_fn(self.mdp, next_state)

to

ob_p0, ob_p1 = self.featurize_fn(next_state)

I apologize for this issue and will push a fix asap. The gym environment is not very well maintained and is mostly there for reference. If you run into any other problems please let me know!

RupaliBhati commented 1 year ago

Thanks a lot @jyan1999!