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

Working with my own customized env #206

Open
HawkQ opened this issue Dec 12, 2023 · 3 comments
Open

Working with my own customized env #206

HawkQ opened this issue Dec 12, 2023 · 3 comments
Assignees
Labels
help wanted Extra attention is needed

Comments

@HawkQ
Copy link

HawkQ commented Dec 12, 2023

Hi, I'm trying to use this library to solve some modified multi-UAV problems, but I'm not professional in coding 🤣
Will there be any instructions about how to use pure modified environments in the future? I've read the add_new_env.py but still not clear with it😥

开发者您好,我试图用这个库去解决一些多无人机的MARL问题,但因为我并非本专业,add_new_env.py文件对我自定义环境起到的帮助极其有限,请问未来是否有更详细或进一步的说明性文档?谢谢!

@Aequatio-Space
Copy link

You can use an example from marllib/envs/base_env to check how a custom environment is wrapped for RLlib. I write my own environment according to such example.

class RLlibMPE(MultiAgentEnv):
def __init__(self, env_config):
map = env_config["map_name"]
env_config.pop("map_name", None)
env = REGISTRY[map](**env_config)
# keep obs and action dim same across agents
# pad_action_space_v0 will auto mask the padding actions
env = ss.pad_observations_v0(env)
env = ss.pad_action_space_v0(env)
self.env = ParallelPettingZooEnv(env)
self.action_space = self.env.action_space
self.observation_space = GymDict({"obs": Box(
low=-100.0,
high=100.0,
shape=(self.env.observation_space.shape[0],),
dtype=self.env.observation_space.dtype)})
self.agents = self.env.agents
self.num_agents = len(self.agents)
env_config["map_name"] = map
self.env_config = env_config
def reset(self):
original_obs = self.env.reset()
obs = {}
for i in self.agents:
obs[i] = {"obs": original_obs[i]}
return obs
def step(self, action_dict):
o, r, d, info = self.env.step(action_dict)
rewards = {}
obs = {}
for key in action_dict.keys():
rewards[key] = r[key]
obs[key] = {
"obs": o[key]
}
dones = {"__all__": d["__all__"]}
return obs, rewards, dones, info
def close(self):
self.env.close()
def render(self, mode=None):
self.env.render()
time.sleep(0.05)
return True
def get_env_info(self):
env_info = {
"space_obs": self.observation_space,
"space_act": self.action_space,
"num_agents": self.num_agents,
"episode_limit": 25,
"policy_mapping_info": policy_mapping_dict
}
return env_info

@ChenJiangxi
Copy link

I'm having the same problem, and I think the key to customizing your environment is in this statement:
self.env = ParallelPettingZooEnv(env)
But I don't really know how to access my own simulation environment

@Theohhhu
Copy link
Collaborator

Thank you to @Aequatio-Space for offering guidance. MARLlib utilizes a standard agent-environment interface based on RLlib. A practical approach to integrating your own environment is to begin by identifying a similar environment (e.g., with the same data structure or interaction style) and then follow the integration approach used for that environment.

@Theohhhu Theohhhu self-assigned this Jan 17, 2024
@Theohhhu Theohhhu added the help wanted Extra attention is needed label Jan 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

4 participants