code: def main(env, args):
      policy = Policy()
      optimizer = optim.Adam(policy.parameters(), lr=1e-2)
      timesteps = range(10000)
  
      def run_single_timestep(engine, timestep):
          observation = engine.state.observation
          action = select_action(policy, observation)
          engine.state.observation, reward, done, _, _ = env.step(
              action
          )
          if args.render:
              env.render()
          policy.rewards.append(reward)
          engine.state.ep_reward += reward
          if done:
              engine.terminate_epoch()
              engine.state.timestep = timestep
  
      trainer = Engine(run_single_timestep)
      trainer.state.running_reward = 10
  
      @trainer.on(EPISODE_STARTED)
      def reset_environment_state():
          torch.manual_seed(args.seed + trainer.state.epoch)
          trainer.state.observation, _ = env.reset(
              seed=args.seed + trainer.state.epoch
          )
          trainer.state.ep_reward = 0
  
      @trainer.on(EPISODE_COMPLETED)
      def update_model():
          trainer.state.running_reward = (
              0.05 * trainer.state.ep_reward
              + (1 - 0.05) * trainer.state.running_reward
          )
          finish_episode(policy, optimizer, args.gamma)
  
      @trainer.on(EPISODE_COMPLETED(every=args.log_interval))
      def log_episode():
          i_episode = trainer.state.epoch
          print(
              f"Episode {i_episode}\tLast reward: {trainer.state.ep_reward:.2f}"
              f"\tAverage length: {trainer.state.running_reward:.2f}"
          )
  
      @trainer.on(EPISODE_COMPLETED)
      def should_finish_training():
          running_reward = trainer.state.running_reward
          if running_reward > env.spec.reward_threshold:
              print(
                  f"Solved! Running reward is now {running_reward} and "
                  f"the last episode runs to {trainer.state.timestep} time steps!"
              )
              trainer.should_terminate = True
  
      trainer.run(timesteps, max_epochs=args.max_episodes)
  
file_path: ignite/examples/reinforcement_learning/reinforce.py
imports: import argparse
  from collections import deque
  import numpy
  import torch
  import torch.nn
  import torch.nn.functional
  import torch.optim
  from torch.distributions import Categorical
  from ignite.engine import Engine, Events
label_desc: Use image node_id 3 for calling a global function with example usage: main(env, args) without return types