docstr: Tests the apply_gradients correctness.
  
  Tests that if we apply gradients of all ones, the new params are equal to the
  standard SGD/Adam update rule.
docstr_tok: ["Tests","the","apply_gradients","correctness",".","Tests","that","if","we","apply","gradients","of","all","ones",",","the","new","params","are","equal","to","the","standard","SGD\/Adam","update","rule","."]
code: def test_apply_gradients(self):
      """Tests the apply_gradients correctness.
  
      Tests that if we apply gradients of all ones, the new params are equal to the
      standard SGD/Adam update rule.
      """
      config = BaseTestingAlgorithmConfig().training(lr=0.0003)
  
      for fw in framework_iterator(config, frameworks=("torch", "tf2")):
          learner = config.build_learner(env=self.ENV)
  
          # calculated the expected new params based on gradients of all ones.
          params = learner.get_parameters(
              learner.module[DEFAULT_POLICY_ID]
          )
          n_steps = 100
          expected = [
              (
                  convert_to_numpy(param)
                  - n_steps * learner.config.lr * np.ones(param.shape)
              )
              for param in params
          ]
          for _ in range(n_steps):
              if fw == "torch":
                  gradients = {
                      learner.get_param_ref(p): torch.ones_like(p)
                      for p in params
                  }
              else:
                  gradients = {
                      learner.get_param_ref(p): tf.ones_like(p)
                      for p in params
                  }
              learner.apply_gradients(gradients)
  
          check(params, expected)
  
imports: import gymnasium
  import numpy
  import tempfile
  import unittest
  import ray
  from ray.rllib.core.learner.learner import Learner
  from ray.rllib.core.testing.testing_learner import BaseTestingAlgorithmConfig
  from ray.rllib.policy.sample_batch import DEFAULT_POLICY_ID
  from ray.rllib.utils.numpy import convert_to_numpy
  from ray.rllib.utils.framework import try_import_tf, try_import_torch
  from ray.rllib.utils.test_utils import check, framework_iterator, get_cartpole_dataset_reader
  from ray.rllib.utils.metrics import ALL_MODULES
label_desc: Use image node_id 6 for calling the TestLearner obj's underlying member method code with example usage: obj.test_apply_gradients() without return types