Closed pkrack closed 2 months ago
@pkrack Thanks for the detailed issue Could you make a PR with your suggested fix along with related tests that confirms the fix
Ironically, I caused this bug by fixing a test that was actually wrong but never realised, https://github.com/Farama-Foundation/Gymnasium/pull/941
By reverting the shared_memory
code to what you suggested (this was the original code) and fixing the test related to all of this.
Thanks for the quick answer and fix.
The
AsyncVectorEnv
class does not batch the observations when the underlying environment has an observation space of typeDict
. Instead the reset and step functions return a tuple of individual observations.I think this is a bug because:
SyncVectorEnv
.VectorizeTransformObservation
throw an exception (cf. code example)The reason for this behaviour is that, when using
use_shared_mem=True
(the default), the observations are read only once at the beginning using theread_from_shared_memory
functions and the dict version of that function returns tuples instead of returning the batched observations. The_read_base_from_shared_memory
for example, reshapes the observation to fit the batched observation space.In the
AsyncVectorEnv
lines 306 and 397 there is then a case distinction:if not shared_memory
... and the observations are not batched when usingshared_memory
.A possible fix for the error in the code sample (on tag v1.0.0.a2) is:
Is there a reason for returning a tuple instead of returning the batched observation (
subspace_samples
is already correctly batched in the code example below)?EDIT Similar issue with the
Tuple
action space:subspace_samples
is batched, thentuple(zip(*subspace_samples))
is returned, which "unbatches" the observations in theTuple
obs are for exampleBox
and returns non-sense if the observations in the tuple are for exampleDict
observations (*subspace_samples
then unpacks to the key names of the individual dicts, zipping them together gives you pairs of key names).Similar fix:
Code example
System info
pip install -e .
Additional context
No response
Checklist