Skip to content

Commit

Permalink
Fixed the mapolicy train issue (#968)
Browse files Browse the repository at this point in the history
The trained MARL policies were not performing as expected because the
parent class (MultiAgentPolicyManager) needed a train function.

Fixes #967
  • Loading branch information
FahmidMorshed authored Oct 17, 2023
1 parent 66b7fc5 commit bf78410
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion tianshou/policy/multiagent/mapolicy.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Literal
from typing import Any, Literal, Self

import numpy as np

Expand Down Expand Up @@ -230,3 +230,11 @@ def learn(
for k, v in out.items():
results[agent_id + "/" + k] = v
return results

# Need a train method that set all sub-policies to train mode.
# No need for a similar eval function, as eval internally uses the train function.
def train(self, mode: bool = True) -> Self:
"""Set each internal policy in training mode."""
for policy in self.policies.values():
policy.train(mode)
return self

0 comments on commit bf78410

Please sign in to comment.