Skip to content

[RLlib] introduce utils to serialize gym spaces and view requirements#25007

Merged
sven1977 merged 3 commits intoray-project:masterfrom
gjoliver:serialize-space
May 24, 2022
Merged

[RLlib] introduce utils to serialize gym spaces and view requirements#25007
sven1977 merged 3 commits intoray-project:masterfrom
gjoliver:serialize-space

Conversation

@gjoliver
Copy link
Member

@gjoliver gjoliver commented May 20, 2022

into JSON-serializable dicts.

This is for safe checkpointing of RLlib policy's obs and action spaces, and view requirements (which currently contains a space attribute).

Why are these changes needed?

This is so we can checkpoint everything a policy needs to run independently.

Related issue number

Checks

  • I've run scripts/format.sh to lint the changes in this PR.
  • I've included any doc changes needed for https://docs.ray.io/en/master/.
  • I've made sure the tests are passing. Note that there might be a few flaky tests, see the recent failures at https://flakey-tests.ray.io/
  • Testing Strategy
    • [*] Unit tests
    • Release tests
    • This PR is not tested :(

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

type is a reserved keyword, better not to use it

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use type_ or dtype.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch!
I am changing the serialization key to "space". and the variable name to "space_type".

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe cleaner to have a dict

type_mapper = {"box": _box, ...}

and then simply

func = type_mapper.get(d["type"])
return func(d)

checking for invalid type can happen before. wdyt?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

love the idea. done.

Copy link
Contributor

@maxpumperla maxpumperla May 20, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works with margin=None, which you wisely put as default, so I think you can simplify this to just

for a in zip(a1, a2):
    eq(a[0], a[1], margin)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤯 had no idea. thanks.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we call this array instead of d? ok in tests, but let's not be too cryptic here!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, we should never use single-char variable names.

Copy link
Member Author

@gjoliver gjoliver May 20, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

habit from working with other languages.
I agree function signature shouldn't use these super short-hands.
what are your opinions of only using these short names in a function for local variables?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

think this is fine. especially for complex and math-heavy functionality, imo it can even be an advantage to have concise notation. depends on context, of course.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe a little docstring here as well?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

string_array?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done. settled on b64_string

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sp --> space

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Contributor

@maxpumperla maxpumperla left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

left a couple of non-blocking comments

@sven1977
Copy link
Contributor

Looks great! Thanks for trying to solve this problem. I'm guessing this is mostly for the serializability of our Policies, which all have-a view-requirements dict (with spaces inside) as well as observation- and action gym spaces. Can you write one sentence about the main purpose of this PR in the comment?

@gjoliver
Copy link
Member Author

Looks great! Thanks for trying to solve this problem. I'm guessing this is mostly for the serializability of our Policies, which all have-a view-requirements dict (with spaces inside) as well as observation- and action gym spaces. Can you write one sentence about the main purpose of this PR in the comment?

sure

Copy link
Member Author

@gjoliver gjoliver left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done. all comments addressed. thanks for the awesome review.

Copy link
Contributor

@maxpumperla maxpumperla left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for addressing everything! 👍

@sven1977 sven1977 merged commit 93ff0be into ray-project:master May 24, 2022
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

Successfully merging this pull request may close these issues.

3 participants