code: def run(env, agents, config):
      win_rates = []
      episode_rewards = []
      train_steps = 0
      for epoch in range(config["n_epoch"]):
          print("train epoch {}".format(epoch))
          # decay epsilon at the begging of each epoch
          if config["epsilon"] > config["min_epsilon"]:
              config["epsilon"] -= config["anneal_epsilon"]
  
          # run n episode(s)
          ep_data_list = []
          for _ in range(config["n_episodes"]):
              ep_data, _ = run_episode(env, agents, config, test=False)
              ep_data_list.append(ep_data)
          # each item in ep_batch shape: (episode_num, trainsition_num, n_agents, item_shape)
          ep_batch = ep_data_list[0]
          ep_data_list.pop(0)
          for ep_data in ep_data_list:
              for key in ep_batch.keys():
                  ep_batch[key] = np.concatenate(
                      (ep_batch[key], ep_data[key]), axis=0
                  )
  
          # learn
          agents.learn(ep_batch, config["epsilon"])
          train_steps += 1
  
          # save model
          if (
              train_steps > 0
              and train_steps % config["save_cycle"] == 0
          ):
              model_path = (
                  config["model_dir"]
                  + "/coma_"
                  + str(train_steps)
                  + ".ckpt"
              )
              agents.save(save_path=model_path)
              print("save model: ", model_path)
  
          # test
          if epoch % config["test_cycle"] == 0:
              win_rate, ep_mean_reward = test(env, agents, config)
              # print('win_rate is ', win_rate)
              win_rates.append(win_rate)
              episode_rewards.append(ep_mean_reward)
              summary.add_scalar(
                  "win_rate", win_rates[-1], len(win_rates)
              )
              summary.add_scalar(
                  "episode_rewards",
                  episode_rewards[-1],
                  len(episode_rewards),
              )
              print("win_rate", win_rates, len(win_rates))
              print(
                  "episode_rewards",
                  episode_rewards,
                  len(episode_rewards),
              )
  
file_path: PARL/benchmark/torch/coma/train.py
imports: from smac.env import StarCraft2Env
  import numpy
  import os
  from sc2_model import ComaModel
  from sc2_agent import Agents
  from parl.algorithms import COMA
  from parl.utils import summary
label_desc: Use image node_id 2 for calling a global function with example usage: run(env, agents, config) without return types