Skip to content

Commit

Permalink
[RLlib] Convert PolicySpec to a readable format when converting to_di…
Browse files Browse the repository at this point in the history
…ct(). (ray-project#31146)

Signed-off-by: tmynn <[email protected]>
  • Loading branch information
kouroshHakha authored and tamohannes committed Jan 25, 2023
1 parent d2f6a07 commit 35bf361
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion rllib/algorithms/algorithm_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,22 @@ def to_dict(self) -> AlgorithmConfigDict:
# Setup legacy multi-agent sub-dict:
config["multiagent"] = {}
for k in self.multiagent.keys():
config["multiagent"][k] = config.pop(k)
# convert policies dict to something human-readable
if k == "policies" and isinstance(self.multiagent[k], dict):
policies_dict = {}
for policy_id, policy_spec in self.multiagent[k].items():
if isinstance(policy_spec, PolicySpec):
policies_dict[policy_id] = (
policy_spec.policy_class,
policy_spec.observation_space,
policy_spec.action_space,
policy_spec.config,
)
else:
policies_dict[policy_id] = policy_spec
config["multiagent"][k] = policies_dict
else:
config["multiagent"][k] = config.pop(k)

# Switch out deprecated vs new config keys.
config["callbacks"] = config.pop("callbacks_class", DefaultCallbacks)
Expand Down

0 comments on commit 35bf361

Please sign in to comment.