code: def main():
      env = gym.make("CartPole-v0")
      # Compatible for different versions of gym
      env = CompatWrapper(env)
      obs_dim = env.observation_space.shape[0]
      act_dim = env.action_space.n
      logger.info("obs_dim {}, act_dim {}".format(obs_dim, act_dim))
  
      # set action_shape = 0 while in discrete control environment
      rpm = ReplayMemory(MEMORY_SIZE, obs_dim, 0)
  
      # build an agent
      model = CartpoleModel(obs_dim=obs_dim, act_dim=act_dim)
      alg = DQN(model, gamma=GAMMA, lr=LEARNING_RATE)
      agent = CartpoleAgent(
          alg, act_dim=act_dim, e_greed=0.1, e_greed_decrement=1e-6
      )
  
      # warmup memory
      while len(rpm) < MEMORY_WARMUP_SIZE:
          run_train_episode(agent, env, rpm)
  
      max_episode = args.max_episode
  
      # start training
      episode = 0
      while episode < max_episode:
          # train part
          for i in range(50):
              total_reward = run_train_episode(agent, env, rpm)
              episode += 1
  
          # test part
          eval_reward = run_evaluate_episodes(agent, render=False)
          logger.info(
              "episode:{}    e_greed:{}   Test reward:{}".format(
                  episode, agent.e_greed, eval_reward
              )
          )
  
      # save the parameters to ./model.ckpt
      save_path = "./model.ckpt"
      agent.save(save_path)
  
      # save the model and parameters of policy network for inference
      save_inference_path = "./inference_model"
      input_shapes = [[None, env.observation_space.shape[0]]]
      input_dtypes = ["float32"]
      agent.save_inference_model(
          save_inference_path, input_shapes, input_dtypes
      )
  
file_path: PARL/examples/DQN/train.py
imports: import os
  import gym
  import numpy
  import parl
  import argparse
  from parl.utils import logger, ReplayMemory
  from cartpole_model import CartpoleModel
  from cartpole_agent import CartpoleAgent
  from parl.env import CompatWrapper, is_gym_version_ge
  from parl.algorithms import DQN
label_desc: Use image node_id 3 for calling a global function with example usage: main() without return types