code: def test_lstm_train():
      """Test that LSTM models are able to achieve >=150 (out of 500) reward on CartPoleNoVelEnv.
  
      This environment requires memory to perform well in."""
  
      def make_env(i):
          env = CartPoleNoVelEnv()
          env = TimeLimit(env, max_episode_steps=500)
          env = bench.Monitor(env, None, allow_early_resets=True)
          env.seed(i)
          return env
  
      env = SubprocVecEnv(
          [lambda: make_env(i) for i in range(NUM_ENVS)]
      )
      env = VecNormalize(env)
      model = PPO2(
          MlpLstmPolicy,
          env,
          n_steps=128,
          nminibatches=NUM_ENVS,
          lam=0.95,
          gamma=0.99,
          noptepochs=10,
          ent_coef=0.0,
          learning_rate=3e-4,
          cliprange=0.2,
          verbose=1,
      )
  
      eprewmeans = []
  
      def reward_callback(local, _):
          nonlocal eprewmeans
          eprewmeans.append(
              safe_mean(
                  [ep_info["r"] for ep_info in local["ep_info_buf"]]
              )
          )
  
      model.learn(total_timesteps=100000, callback=reward_callback)
  
      # Maximum episode reward is 500.
      # In CartPole-v1, a non-recurrent policy can easily get >= 450.
      # In CartPoleNoVelEnv, a non-recurrent policy doesn't get more than ~50.
      # LSTM policies can reach above 400, but it varies a lot between runs; consistently get >=150.
      # See PR #244 for more detailed benchmarks.
  
      average_reward = (
          sum(eprewmeans[-NUM_EPISODES_FOR_SCORE:])
          / NUM_EPISODES_FOR_SCORE
      )
      assert (
          average_reward >= 150
      ), "Mean reward below 150; per-episode rewards {}".format(
          average_reward
      )
  
imports: import os
  from gym.envs.classic_control import CartPoleEnv
  from gym.wrappers.time_limit import TimeLimit
  from gym import spaces
  import numpy
  import pytest
  from stable_baselines import A2C, ACER, ACKTR, PPO2, bench
  from stable_baselines.common.policies import MlpLstmPolicy, LstmPolicy
  from stable_baselines.common.vec_env import SubprocVecEnv
  from stable_baselines.common.vec_env.vec_normalize import VecNormalize
  from stable_baselines.common.math_util import safe_mean
  from stable_baselines.common.evaluation import evaluate_policy
label_desc: Use image node_id 2 for calling a global function with example usage: test_lstm_train() and returns: env