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

Questions about MAMujoco #23

Open
kaiyama12345679 opened this issue Dec 26, 2023 · 4 comments
Open

Questions about MAMujoco #23

kaiyama12345679 opened this issue Dec 26, 2023 · 4 comments

Comments

@kaiyama12345679
Copy link

Hi, I'm very instersted in your work, and I want to test your MAT for MAMujoco.
So, Do you have any experimental results or config of the MAMujoco Envirionment other than "HalfCheetah"?

@morning9393
Copy link
Collaborator

hiya, thank you for your interesting, but we don't have results on other ma-mujoco map w.r.t MAT, since we use ma-mujoco mainly to simulate robot failure scenarios (for Table 3)....thus only choose the simplest case~

@kaiyama12345679
Copy link
Author

kaiyama12345679 commented Dec 28, 2023

@morning9393 , thanks for your reply.

Can I ask one more question? I want to know whether get_obs_agent() in your MAMujoco is globally observable or partially observable, because there is differences between the obsk.py of original MAMujoco and that of yours.

@morning9393
Copy link
Collaborator

morning9393 commented Dec 28, 2023

@kaiyama12345679 hiya, Questions are always welcome~~ :))

in the file "train_mujoco.sh", you may find that we set agent_obsk=0, which means each agent obs returned by get_obs_agent() contained only the information corresponding to its own node, without neighbors, which is different from the original MA-Mujoco settings (usually agent_obsk=1 or agent_obsk=2, means it will contain information from the current node and all the nearest neighbor nodes with distances 1 or 2).

you can also change the agent_obsk if you would like to include more information into the agent obs~

hoping it might help you~

@kaiyama12345679
Copy link
Author

@morning9393,
I'm sorry I didn't make the question clear enough.
I would like to know why there is a difference between "build_obs()" in obsk.py and that of original MAMujoco, which seems to be the same as the commented out part in yours.

# def build_obs(env, k_dict, k_categories, global_dict, global_categories, vec_len=None):
# """Given a k_dict from get_joints_at_kdist, extract observation vector.
#
# :param k_dict: k_dict
# :param qpos: qpos numpy array
# :param qvel: qvel numpy array
# :param vec_len: if None no padding, else zero-pad to vec_len
# :return:
# observation vector
# """
#
# # TODO: This needs to be fixed, it was designed for half-cheetah only!
# #if add_global_pos:
# # obs_qpos_lst.append(global_qpos)
# # obs_qvel_lst.append(global_qvel)
# body_set_dict = {}
# obs_lst = []
# # Add parts attributes
# for k in sorted(list(k_dict.keys())):
# cats = k_categories[k]
# for _t in k_dict[k]:
# for c in cats:
# if c in _t.extra_obs:
# items = _t.extra_obs[c](env).tolist()
# obs_lst.extend(items if isinstance(items, list) else [items])
# else:
# if c in ["qvel","qpos"]: # this is a "joint position/velocity" item
# items = getattr(env.sim.data, c)[getattr(_t, "{}_ids".format(c))]
# obs_lst.extend(items if isinstance(items, list) else [items])
# elif c in ["qfrc_actuator"]: # this is a "vel position" item
# items = getattr(env.sim.data, c)[getattr(_t, "{}_ids".format("qvel"))]
# obs_lst.extend(items if isinstance(items, list) else [items])
# elif c in ["cvel", "cinert", "cfrc_ext"]: # this is a "body position" item
# if _t.bodies is not None:
# for b in _t.bodies:
# if c not in body_set_dict:
# body_set_dict[c] = set()
# if b not in body_set_dict[c]:
# items = getattr(env.sim.data, c)[b].tolist()
# items = getattr(_t, "body_fn", lambda _id,x:x)(b, items)
# # obs_lst.extend(items if isinstance(items, list) else [items])
# body_set_dict[c].add(b)
#
# # Add global attributes
# body_set_dict = {}
# for c in global_categories:
# if c in ["qvel", "qpos"]: # this is a "joint position" item
# for j in global_dict.get("joints", []):
# items = getattr(env.sim.data, c)[getattr(j, "{}_ids".format(c))]
# obs_lst.extend(items if isinstance(items, list) else [items])
# else:
# for b in global_dict.get("bodies", []):
# if c not in body_set_dict:
# body_set_dict[c] = set()
# if b not in body_set_dict[c]:
# obs_lst.extend(getattr(env.sim.data, c)[b].tolist())
# body_set_dict[c].add(b)
#
# if vec_len is not None:
# pad = np.array((vec_len - len(obs_lst))*[0])
# if len(pad):
# return np.concatenate([np.array(obs_lst), pad])
# return np.array(obs_lst)
def build_obs(env, k_dict, k_categories, global_dict, global_categories, vec_len=None):
"""Given a k_dict from get_joints_at_kdist, extract observation vector.
:param k_dict: k_dict
:param qpos: qpos numpy array
:param qvel: qvel numpy array
:param vec_len: if None no padding, else zero-pad to vec_len
:return:
observation vector
"""
# TODO: This needs to be fixed, it was designed for half-cheetah only!
#if add_global_pos:
# obs_qpos_lst.append(global_qpos)
# obs_qvel_lst.append(global_qvel)
body_set_dict = {}
obs_lst = []
# Add parts attributes
# print("start=========================================================")
# print("k_categories: ", k_categories)
# print("k_dict: ", k_dict)
for k in sorted(list(k_dict.keys())):
cats = k_categories[k]
# print("cats: ", cats)
for _t in k_dict[k]:
# print("_t: ", _t)
for c in cats:
# print("c: ", c)
if c in _t.extra_obs:
items = _t.extra_obs[c](env).tolist()
# print("extra_obs %s items: %s" % (c, items))
obs_lst.extend(items if isinstance(items, list) else [items])
elif c in ["qvel","qpos"]: # this is a "joint position/velocity" item
items = getattr(env.sim.data, c)[getattr(_t, "{}_ids".format(c))]
# print("%s items: %s" % (c, items))
obs_lst.extend(items if isinstance(items, list) else [items])
elif c in ["qfrc_actuator"]: # this is a "vel position" item
items = getattr(env.sim.data, c)[getattr(_t, "{}_ids".format("qvel"))]
# print("qfrc_actuator items: ", items)
obs_lst.extend(items if isinstance(items, list) else [items])
elif c in ["cvel", "cinert", "cfrc_ext"]: # this is a "body position" item
if _t.bodies is not None:
for b in _t.bodies:
# print("b: ", b)
if c not in body_set_dict:
body_set_dict[c] = set()
if b not in body_set_dict[c]:
items = getattr(env.sim.data, c)[b].tolist()
items = getattr(_t, "body_fn", lambda _id,x:x)(b, items)
# print("%s items: %s" % (c, items))
# obs_lst.extend(items if isinstance(items, list) else [items])
body_set_dict[c].add(b)
# Add global attributes
body_set_dict = {}
# print("global_categories: ", global_categories)
# print("global_dict: ", global_dict)
for c in global_categories:
# print("global c: ", c)
for j in global_dict.get("joints", []):
if c in j.extra_obs:
items = j.extra_obs[c](env).tolist()
# print("global extra_obs %s items: %s" % (c, items))
if c not in ["cfrc_ext"]:
obs_lst.extend(items if isinstance(items, list) else [items])
elif c in ["qvel", "qpos"]: # this is a "joint position" item
items = getattr(env.sim.data, c)[getattr(j, "{}_ids".format(c))]
# print("global %s items: %s" % (c, items))
obs_lst.extend(items if isinstance(items, list) else [items])
elif c in ["qfrc_actuator"]: # this is a "vel position" item
items = getattr(env.sim.data, c)[getattr(j, "{}_ids".format("qvel"))]
# print("global qfrc_actuator items: ", items)
obs_lst.extend(items if isinstance(items, list) else [items])
elif c in ["cvel", "cinert", "cfrc_ext"]: # this is a "body position" item
if j.bodies is not None:
for b in j.bodies:
# print("global b: ", b)
if c not in body_set_dict:
body_set_dict[c] = set()
if b not in body_set_dict[c]:
items = getattr(env.sim.data, c)[b].tolist()
items = getattr(j, "body_fn", lambda _id,x:x)(b, items)
# print("global %s items: %s" % (c, items))
# obs_lst.extend(items if isinstance(items, list) else [items])
body_set_dict[c].add(b)
for b in global_dict.get("bodies", []):
if c not in body_set_dict:
body_set_dict[c] = set()
if b not in body_set_dict[c]:
# print("global body items: ", getattr(env.sim.data, c)[b].tolist())
obs_lst.extend(getattr(env.sim.data, c)[b].tolist())
body_set_dict[c].add(b)
if vec_len is not None:
pad = np.array((vec_len - len(obs_lst))*[0])
if len(pad):
# print("len_pad: ", len(pad))
# print("obs_lst: ", obs_lst)
# print("end=========================================================")
return np.concatenate([np.array(obs_lst), pad])
# print("obs_lst: ", obs_lst)
# print("end=========================================================")
return np.array(obs_lst)

@kaiyama12345679 kaiyama12345679 changed the title MAMujoco result other than HalfCheetah Questions about MAMujoco Jan 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants