8000 [RLlib] Better error handling when return shape from step() mismatch in utils._flatten_multidiscrete · Issue #35113 · ray-project/ray · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
[RLlib] Better error handling when return shape from step() mismatch in utils._flatten_multidiscrete #35113
Open
@y-he2

Description

@y-he2

Description

Hi and thanks for the hardworks so far, and an amazing distributed RL library. Hope I came to the right place for RLlib improvement requests.

Im just gonna drop a quick one here as I encounter them on the road, and more details could be provided as per request.
Currently the error message could be hard to use for tracing back the issue, when the returned dimension mismatches the defined observation_space element dimensions.

In this example:

  • Cause of error: I defined a MultiDiscrete( np.one( 22 ) ) element in my observation space, then I accidentally returned a np.one( 41 ) vector in my gym.step() function.
  • Current error handling:
...\gymnasium\spaces\utils.py", line 158, in _flatten_multidiscrete
    onehot[offsets[:-1] + x.flatten()] = 1
ValueError: operands could not be broadcast together with shapes (22,) (41,)

Assuming no previous knowledge this could leave the user in some confusion as to where to start to debug.

Debug code to trace the error I used in utils.py line 156:

try:
    onehot[offsets[:-1] + x.flatten()] = 1
except ValueError as err:
    print( "space:", space )
    print( "x:", x )
    print( "onehot:", onehot )
    print( "offsets[:-1]:", offsets[:-1] )
    print( "x.flatten():", x.flatten() )
    print( "offsets[:-1].shape:", offsets[:-1].shape )
    print( "x.flatten().shape:", x.flatten().shape )
    print( "space.nvec", space.nvec )
    print( "space.nvec.size", space.nvec.size )
    raise err

Useful info to display:

  • Which element in which space
  • Defined space shape
  • Return vector shape from step()

Best regards,
Ian

Use case

As the title and this could help the user to better understand/trace their error when observation element vector size mismatch in step() return and self.observation_space definition.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issue, but not time-criticalenhancementRequest for new feature and/or capabilitypending-cleanupThis issue is pending cleanup. It will be removed in 2 weeks after being assigned.rllibRLlib related issuesrllib-envrllib env related issues

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0