fix: return Gymnasium-style dict infos from MarkovVectorEnv - #270
Open
teddytennant wants to merge 1 commit into
Open
fix: return Gymnasium-style dict infos from MarkovVectorEnv#270teddytennant wants to merge 1 commit into
teddytennant wants to merge 1 commit into
Conversation
MarkovVectorEnv (and concat/multiproc helpers) returned infos as a list of per-env dicts. Gymnasium vector envs since v0.25 expect a dict of arrays with boolean _key masks, so wrappers like RecordEpisodeStatistics raise when used with pettingzoo_env_to_vec_env_v1 (e.g. CleanRL multi- agent PPO). Convert agent infos via list_infos_to_dict, merge concatenated vector infos along the env axis, and convert back to a list only at the SB3 boundary. Also set autoreset_mode=SAME_STEP metadata to match the existing same-step auto-reset behavior. Fixes Farama-Foundation#249
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
pettingzoo_env_to_vec_env_v1wraps a PettingZoo parallel env inMarkovVectorEnv, which is agymnasium.vector.VectorEnv. Onresetandstepit returnedinfosas a Pythonlistof per-agent dicts:Gymnasium vector environments (since v0.25) expect
infosto be a dict of arrays with boolean_<key>masks (seeVectorEnv._add_info). Wrappers such asgymnasium.wrappers.RecordEpisodeStatistics(and the vector variant) assertisinstance(infos, dict)and fail with:This breaks CleanRL multi-agent PPO (
ppo_pettingzoo_ma_atari.py), which wraps the SuperSuit vec env withRecordEpisodeStatistics.Root cause
MarkovVectorEnvnever adopted the post-v0.25 Gymnasium vector info layout. DownstreamConcatVecEnv/ProcConcatVecalso assumed list-of-dicts and flattened nested lists, so the whole SuperSuit vector stack was list-shaped.Fix
supersuit/vector/utils/info_dict.pywithlist_infos_to_dict(list of per-env dicts -> Gymnasium vector dict) andmerge_vector_infos(concat blocks along the env axis).MarkovVectorEnv.reset/stepnow return dict infos. Non-agent (global) PettingZoo info keys are still propagated into every agent slot. Terminal auto-reset still merges step + reset infos with reset keys winning.metadata["autoreset_mode"] = AutoresetMode.SAME_STEPto match the existing same-step auto-reset when the underlying PZ env finishes.ConcatVecEnvandProcConcatVecmerge vector info dicts instead of flattening lists.SingleVecEnvreturns dict infos for consistency.SB3VecEnvWrapperconverts dict infos back to a list of per-env dicts, which is what Stable-Baselines3 expects.Test plan
test_infos_are_dict_not_list- reset/step returndicttest_record_episode_statistics_compatible-gymnasium.wrappers.vector.RecordEpisodeStatisticsworks and emitsepisode/_episodetest_infos_dict_through_concat_vec_envs- same throughconcat_vec_envs_v1test_pettingzoo_to_vec.pysuite updated for dict infos (terminal_observation masks, etc.) - 9 passedtest_gym_vector,test_vector_dict,vec_env_test) - passed / skipped as beforepytest test/test_vector/test_pettingzoo_to_vec.py -o addopts=''Fixes #249