fix(pytorch): Adapt to new Gym API for compatibility #21
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR introduces changes specifically within the
pytorch/
directory to adapt the codebase for newer Gym/Gymnasium API versions.Problem:
The original code within
pytorch/
was incompatible with newer Gym/Gymnasium API versions. This was due to changes in the return values ofenv.reset()
andenv.step()
, and how states (sometimes tuples) are handled.Solution:
This PR updates the code within
pytorch/
to align with the new Gym API:get_action
: Now correctly handles tuple state inputs by extracting the main observation.env.reset()
: Updated tostate, _ = env.reset()
to match the new API (returns observation and info).env.step()
: Adapted to process five return values (next_state, reward, terminated, truncated, info
) and now uses a combineddone = terminated or truncated
flag.These changes ensure the
pytorch/
examples/code work correctly with environments using the updated API, such as CartPole.Testing:
pytorch/
folder with: gym0.26.2
, Python3.9.13
on macOS15.4.1 (Sequoia)
.