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

[Proposal] Deepcopy of an Environment Object #737

Closed
1 task done
sdpkjc opened this issue Oct 12, 2023 · 3 comments
Closed
1 task done

[Proposal] Deepcopy of an Environment Object #737

sdpkjc opened this issue Oct 12, 2023 · 3 comments
Labels
enhancement New feature or request

Comments

@sdpkjc
Copy link
Contributor

sdpkjc commented Oct 12, 2023

Proposal

I am proposing the addition of true deepcopy or snapshot functionality to the utils.EzPickle class in the Gymnasium library.

Motivation

While working with the Gymnasium library, I realized that most environment classes inherit from the utils.EzPickle class. However, I've noticed a potential issue with this class. When using the deepcopy function, the EzPickle class discards the current environment state and creates a new one instead. This behaviour seems problematic for use cases that require keeping the environment state after deepcopy.

Is there a specific reason why EzPickle was designed in this way? Is it due to limitations that prevent real deepcopy from being implemented? I am asking this particularly because I am willing to draft a PR with the implementation of true deepcopy or snapshot functionality. I believe this feature would greatly benefit the library.

Additionally, I noticed openai/gym#402 which could be related.

Pitch

Providing a true deepcopy or snapshot functionality would improve the usability of the Gymnasium library. This change would allow users to easily store the state of a certain environment, facilitating tasks such as training reinforcement learning algorithms, which often require the ability to interact with multiple environment instances.

Alternatives

An alternative solution could be to create a new class that implements true deepcopy or snapshot. Another possibility would be to support clone_state and restore_state functions, similar to the current Atari environment, that would cater to this functionality. However, since EzPickle is already widely used in the library, and considering that this feature might be essential for several users, I believe modifying the EzPickle class would be more beneficial.

Additional context

No response

Checklist

  • I have checked that there is no similar issue in the repo
@sdpkjc sdpkjc added the enhancement New feature or request label Oct 12, 2023
@sdpkjc
Copy link
Contributor Author

sdpkjc commented Oct 13, 2023

related to #94

@pseudo-rnd-thoughts
Copy link
Member

This is certainly an interesting idea however I'm not sure how much Gymnasium can do as an API

It might be possible to implement a clone_state or restore_state that defaults to NotImplemented
We could add the functionality to gymnasium and to the check_env function for testing environments.

However, I'm worried that this is too late in its development to do this and additionally the inconsistencies within environment implementations make this difficult.
If starting again, I design Env to have a state attribute containing all the environment information, probably as a dataclass, making implementing such a function straightforward. However I don't think a change like this is possible anymore

@dm-ackerman
Copy link

It might be possible to implement a clone_state or restore_state that defaults to NotImplemented We could add the functionality to gymnasium and to the check_env function for testing environments.

However, I'm worried that this is too late in its development to do this and additionally the inconsistencies within environment implementations make this difficult.

Is the fact that it is late in the development a reason not to do this as an optional feature? (related: #842). Maybe not all envs could/would support this feature, but is there value in standardizing how it would be done for envs that do support it?

@pseudo-rnd-thoughts pseudo-rnd-thoughts closed this as not planned Won't fix, can't repro, duplicate, stale Mar 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants