Iterating over Dict spaces in aicrowd-gym

I am trying to iterate over the spaces the Dict space has (see submission #152436), but aicrowd-gym does not seem to support iteration, whereas the original Gym Dict space supports it. Would it be possible to have this feature in aicrowd-gym?

On a similar note, is there public code for aicrowd-gym available which is used on the servers so one can debug these errors locally? The pypi version seems to be just a wrap around normal Gym.

I managed to workaround these issues for now.

Here are some comments for aicrowd-gym devs they might want to look at (overall works quite well too! I bet it makes doing your eval server secrets much easier :slight_smile: )

  • Allow access to observation/action space variables that exist in normal Gym (e.g. spaces for Dict obs)
  • If possible, wrap your underlying obs/action spaces to use the original Gym’s obs/action space classes (e.g. if you have a Discrete action space, it should appear as instance of gym.spaces.Discrete instead of something else). Otherwise checks like isinstance(space, gym.spaces.Discrete) fail.
  • This is perhaps result of bad programming from my end, but make sure variables that do not exist in the environment return appropriate exceptions. For example, I did hasattr("something", env). something was not a variable in the environment, but with aicrowd-gym it was set to None. This caused hasattr to return True and subsequently things failing.
1 Like

Hello @anssi

Thanks for sharing this with us.

  • Allow access to observation/action space variables that exist in normal Gym (e.g. spaces for Dict obs)

We will soon update the evaluator to allow access to a few more attributes. At the moment the following attributes/methods can be accessed.

On action space:

(
    "contains",
    "dtype",
    "sample",
    "shape",
    "n",
)

On observation space:

(
    "bounded_above",
    "bounded_below",
    "contains",
    "dtype",
    "high",
    "is_bounded",
    "low",
    "sample",
    "shape",
    "n",
)


  • This is perhaps result of bad programming from my end, but make sure variables that do not exist in the environment return appropriate exceptions. For example, I did hasattr("something", env). something was not a variable in the environment, but with aicrowd-gym it was set to None. This caused hasattr to return True and subsequently things failing.

I believe this happens with gym.Env objects as well. For example, if I do

import gym
env = gym.make("CartPolve-v0")
setattr(env, "something", "some value")

it doesn’t return any error. If possible, can you share with a simple example the expected behaviour?

Note: During the evaluation, the env object you have access to is a proxy object and not the actual gym.Env instance. So setting attributes from your code will not set any attributes on the actual env object. If you have any specific use case for doing this, please feel free to reach out to us and we can try to accommodate your use case.

Edit: Sorry, misread the last part. We will try to get the read access to all the env attributes in our future releases.

1 Like

Thanks for the reply! :slight_smile:

Edit: Sorry, misread the last part. We will try to get the read access to all the env attributes in our future releases.

:+1: , but for clarity, let me lay out the issue I was having.
My code has a following check for environments:

is_multiagent = hasattr("num_agents", env) and env.num_agents > 1

The environment does not have num_agents attribute. On normal Gym this check will correctly result in is_multiagent = False. However on aicrowd-gym it raises

TypeError: '>' not supported between instances of 'NoneType' and 'int'

This is because the hasattr returns True when it should return False, and aicrowd-gym seems to be setting env.num_agents to None, while in reality it should be unset.

1 Like