code: def main():
      env = gym.make(args.env)
      env = ActionMappingWrapper(env)
  
      obs_dim = env.observation_space.shape[0]
      act_dim = env.action_space.shape[0]
      obs_dim += 1  # add 1 to obs dim for time step feature
  
      scaler = Scaler(obs_dim)
  
      model = MujocoModel(obs_dim, act_dim)
      alg = parl.algorithms.PPO(
          model,
          act_dim=act_dim,
          policy_lr=model.policy_lr,
          value_lr=model.value_lr,
      )
      agent = MujocoAgent(
          alg, obs_dim, act_dim, args.kl_targ, loss_type=args.loss_type
      )
  
      # run a few episodes to initialize scaler
      collect_trajectories(env, agent, scaler, episodes=5)
  
      test_flag = 0
      total_steps = 0
      while total_steps < args.train_total_steps:
          trajectories = collect_trajectories(
              env, agent, scaler, episodes=args.episodes_per_batch
          )
          total_steps += sum([t["obs"].shape[0] for t in trajectories])
          total_train_rewards = sum(
              [np.sum(t["rewards"]) for t in trajectories]
          )
  
          (
              train_obs,
              train_actions,
              train_advantages,
              train_discount_sum_rewards,
          ) = build_train_data(trajectories, agent)
  
          policy_loss, kl = agent.policy_learn(
              train_obs, train_actions, train_advantages
          )
          value_loss = agent.value_learn(
              train_obs, train_discount_sum_rewards
          )
  
          logger.info(
              "Steps {}, Train reward: {}, Policy loss: {}, KL: {}, Value loss: {}".format(
                  total_steps,
                  total_train_rewards / args.episodes_per_batch,
                  policy_loss,
                  kl,
                  value_loss,
              )
          )
          if total_steps // args.test_every_steps >= test_flag:
              while total_steps // args.test_every_steps >= test_flag:
                  test_flag += 1
              eval_reward = run_evaluate_episode(env, agent, scaler)
              logger.info(
                  "Steps {}, Evaluate reward: {}".format(
                      total_steps, eval_reward
                  )
              )
  
file_path: PARL/benchmark/fluid/PPO/train.py
imports: from parl.utils import check_version_for_fluid
  import argparse
  import gym
  import numpy
  import parl
  from mujoco_agent import MujocoAgent
  from mujoco_model import MujocoModel
  from parl.utils import logger
  from parl.utils.rl_utils import calc_gae, calc_discount_sum_rewards
  from parl.env.continuous_wrappers import ActionMappingWrapper
  from scaler import Scaler
label_desc: Use image node_id 5 for calling a global function with example usage: main() without return types