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

Possible to define an action spec of dictionary? #10

Closed
IanQS opened this issue May 4, 2022 · 2 comments
Closed

Possible to define an action spec of dictionary? #10

IanQS opened this issue May 4, 2022 · 2 comments

Comments

@IanQS
Copy link

IanQS commented May 4, 2022

Hey there!

How might I go about defining an action spec that is part of a dictionary? Say an action in a parameterized action space? In OpenAI gym something like this has the following signature:

class gym.spaces.Dict(spaces: Optional[dict[str, gym.spaces.space.Space]] = None, seed: Optional[Union[dict, int, gym.utils.seeding.RandomNumberGenerator]] = None, **spaces_kwargs: gym.spaces.space.Space)

and an example of

self.nested_observation_space = spaces.Dict({
    'sensors':  spaces.Dict({
        'position': spaces.Box(low=-100, high=100, shape=(3,)),
        'velocity': spaces.Box(low=-1, high=1, shape=(3,)),
        'front_cam': spaces.Tuple((
            spaces.Box(low=0, high=1, shape=(10, 10, 3)),
            spaces.Box(low=0, high=1, shape=(10, 10, 3))
        )),
        'rear_cam': spaces.Box(low=0, high=1, shape=(10, 10, 3)),
    }),
    'ext_controller': spaces.MultiDiscrete((5, 2, 2)),
    'inner_state':spaces.Dict({
        'charge': spaces.Discrete(100),
        'system_checks': spaces.MultiBinary(10),
        'job_status': spaces.Dict({
            'task': spaces.Discrete(5),
            'progress': spaces.Box(low=0, high=100, shape=()),
        })
    })
})

Would this amount to simply having a standard python dictionary of specs?

@IanQS
Copy link
Author

IanQS commented Jun 14, 2022

@alimuldal

Sorry for pinging you directly but I wanted to follow up on this

@alimuldal
Copy link
Collaborator

dm_env is extremely permissive about what actions are allowed to be, per the docstring:

An Array spec, or a nested dict, list or tuple of Array specs.

The main requirement is that the "leaf nodes" in the structure are subclasses of specs.Array (typically BoundedArrays), e.g.

def action_spec(self):
  return {
    'single_array': specs.BoundedArray(...),
    'nested_sequence_of_arrays': [specs.BoundedArray(...), specs.BoundedArray(...), ...],
    'nested_dict': {
        'inner_array': specs.BoundedArray(...),
        ...
    }
  }

The action passed to step must have the same structure as the thing returned by action_spec, and the arrays it contains must conform to the corresponding specs.Array objects.

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

2 participants