Prevented accidental alteration of env_spec_kwargs in make_vec #1304
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.
Description
In
make_vec
,env_spec_kwargs
is first stripped of all arguments which do not belong to the underlying environment (num_envs
,vectorization_mode
, ...). Thencreate_single_env
is defined, whereenv_spec_kwargs
is used to create the environment, which is then passed to eitherSyncVectorEnv
orAsyncVectorEnv
. After those vector environments are created, the stripped arguments are added toenv_spec_kwargs
again.AsyncVectorEnv
keeps a reference tocreate_single_env
in a publicly accessible fieldAsyncVectorEnv.env_fns
. The problem is now that because the stripped arguments were added toenv_spec_kwargs
again,create_single_env
does not work anymore, as it will now try to pass arguments such asnum_envs
to the environment constructor.In my workflow, I need to access a single environment of
AsyncVectorEnv
, e.g.:produces
The fix is to copy the env_spec_kwargs dictionary before adding the stripped arguments again.
Type of change