docstr: Test PG with learning rate schedule.
docstr_tok: ["Test","PG","with","learning","rate","schedule","."]
code: def test_simple_q_lr_schedule(self):
      """Test PG with learning rate schedule."""
      config = simple_q.SimpleQConfig()
      config.reporting(
          min_sample_timesteps_per_iteration=10,
          # Make sure that results contain info on default policy
          min_train_timesteps_per_iteration=10,
          # 0 metrics reporting delay, this makes sure timestep,
          # which lr depends on, is updated after each worker rollout.
          min_time_s_per_iteration=0,
      )
      config.rollouts(
          num_rollout_workers=1,
          rollout_fragment_length=50,
      )
      config.training(lr=0.2, lr_schedule=[[0, 0.2], [500, 0.001]])
  
      def _step_n_times(algo, n: int):
          """Step trainer n times.
  
          Returns:
              learning rate at the end of the execution.
          """
          for _ in range(n):
              results = algo.train()
          return results["info"][LEARNER_INFO][DEFAULT_POLICY_ID][
              LEARNER_STATS_KEY
          ]["cur_lr"]
  
      for _ in framework_iterator(config):
          algo = config.build(env="CartPole-v1")
  
          lr = _step_n_times(algo, 1)  # 50 timesteps
          # Close to 0.2
          self.assertGreaterEqual(lr, 0.15)
  
          lr = _step_n_times(algo, 8)  # Close to 500 timesteps
          # LR Annealed to 0.001
          self.assertLessEqual(float(lr), 0.5)
  
          lr = _step_n_times(algo, 2)  # > 500 timesteps
          # LR == 0.001
          self.assertAlmostEqual(lr, 0.001)
  
          algo.stop()
  
file_path: ray/rllib_contrib/simple_q/tests/test_simple_q.py
imports: import unittest
  import numpy
  import rllib_simple_q.simple_q.simple_q
  from rllib_simple_q.simple_q.simple_q_tf_policy import SimpleQTF2Policy
  from rllib_simple_q.simple_q.simple_q_torch_policy import SimpleQTorchPolicy
  import ray
  from ray.rllib.policy.sample_batch import SampleBatch
  from ray.rllib.utils.framework import try_import_tf
  from ray.rllib.utils.metrics.learner_info import DEFAULT_POLICY_ID, LEARNER_INFO, LEARNER_STATS_KEY
  from ray.rllib.utils.numpy import fc, huber_loss, one_hot
  from ray.rllib.utils.test_utils import check, check_compute_single_action, check_train_results, framework_iterator
label_desc: Use image node_id 5 for calling the TestSimpleQ obj's underlying member method code with example usage: obj.test_simple_q_lr_schedule() and returns: results