Skip to content

Commit 5c64613

Browse files
committed
Improving compatibility with VecCheckNan wrapper by adding get_attr method
1 parent d1b3011 commit 5c64613

File tree

4 files changed

+17
-2
lines changed

4 files changed

+17
-2
lines changed

CITATION.cff

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ authors:
55
given-names: "Roland"
66
orcid: "https://orcid.org/0009-0006-4882-4166"
77
title: "From homeostasis to resource sharing: Biologically and economically aligned multi-objective multi-agent gridworld-based AI safety benchmarks"
8-
version: 0.9.2
8+
version: 0.9.3
99
doi: 10.48550/arXiv.2410.00081
1010
date-released: 2024-09-30
1111
url: "https://github.com/biological-alignment-benchmarks/zoo_to_gym_multiagent_adapter"

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "zoo_to_gym_multiagent_adapter"
3-
version = "0.9.2"
3+
version = "0.9.3"
44
description = "Zoo to Gym Multi-Agent Adapter"
55
readme = "README.md"
66
authors = [

zoo_to_gym_multiagent_adapter/multiagent_zoo_to_gym_adapter.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ def __init__(
7171
def num_envs(self): # called by VecCheckNan env
7272
return 1
7373

74+
# Called by VecCheckNan env. Lets simulate vectorised env here.
75+
def get_attr(self, attr_name, indices = None):
76+
return [getattr(self, attr_name)]
77+
7478
def set_model(self, model):
7579
self.model = model
7680

zoo_to_gym_multiagent_adapter/singleagent_zoo_to_gym_adapter.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ class SingleAgentZooToGymAdapter(gym.Env):
1313
A wrapper that transforms a PettingZoo environment with exactly one agent
1414
into a single-agent Gymnasium environment.
1515
Both Zoo ParallelEnv and Zoo AECEnv (sequential env) are supported.
16+
17+
Similar to using:
18+
env = ss.pettingzoo_env_to_vec_env_v1(env)
19+
env = ss.concat_vec_envs_v1(env, num_vec_envs=1, num_cpus=1,
20+
base_class="stable_baselines3")
21+
... but simpler internally and also automatically supports AECEnv, which
22+
would need yet one more additional wrapper when using SuperSuit.
1623
"""
1724

1825
def __init__(self, zoo_env, agent_id):
@@ -32,6 +39,10 @@ def __init__(self, zoo_env, agent_id):
3239
def num_envs(self): # called by VecCheckNan env
3340
return 1
3441

42+
# Called by VecCheckNan env. Lets simulate vectorised env here.
43+
def get_attr(self, attr_name, indices = None):
44+
return [getattr(self, attr_name)]
45+
3546
def reset(self, seed=None, options=None, *args, **kwargs):
3647
"""
3748
Reset the environment.

0 commit comments

Comments
 (0)