Skip to content

Commit

Permalink
Fix: set render_mode in tianshou tutorials (#853) (#854)
Browse files Browse the repository at this point in the history
  • Loading branch information
RaffaeleGalliera authored Nov 8, 2022
1 parent cb39888 commit 37a5c1a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions tutorials/Tianshou/1_basic_api_usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@

if __name__ == "__main__":
# Step 1: Load the PettingZoo environment
env = rps_v2.env()
env = rps_v2.env(render_mode="human")

# Step 2: Wrap the environment for Tianshou interfacing
env = PettingZooEnv(rps_v2.env())
env = PettingZooEnv(env)

# Step 3: Define policies for each agent
policies = MultiAgentPolicyManager([RandomPolicy(), RandomPolicy()], env)
Expand Down
8 changes: 4 additions & 4 deletions tutorials/Tianshou/3_cli_and_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ def get_agents(
return policy, optim, env.agents


def get_env():
return PettingZooEnv(tictactoe_v3.env())
def get_env(render_mode=None):
return PettingZooEnv(tictactoe_v3.env(render_mode=render_mode))


def train_agent(
Expand Down Expand Up @@ -241,7 +241,7 @@ def watch(
agent_learn: Optional[BasePolicy] = None,
agent_opponent: Optional[BasePolicy] = None,
) -> None:
env = get_env()
env = DummyVectorEnv([lambda: get_env(render_mode="human")])
policy, optim, agents = get_agents(
args, agent_learn=agent_learn, agent_opponent=agent_opponent
)
Expand All @@ -257,4 +257,4 @@ def watch(
# train the agent and watch its performance in a match!
args = get_args()
result, agent = train_agent(args)
# watch(args, agent)
watch(args, agent)

0 comments on commit 37a5c1a

Please sign in to comment.