docstr: Ensure that observations and rewards change in consecutive calls.
docstr_tok: ["Ensure","that","observations","and","rewards","change","in","consecutive","calls","."]
code: def testObservationAndRewardsVary(self):
      """Ensure that observations and rewards change in consecutive calls."""
      dynamics = DummyDynamics()
      env = nsse.NonStationaryStochasticEnvironment(dynamics)
  
      self.evaluate(tf.compat.v1.global_variables_initializer())
      env_time = env._env_time
      observation_samples = []
      reward_samples = []
  
      if tf.executing_eagerly():
          for t in range(0, 10):
              ts = env.reset()
              observation = ts.observation
              reward = env.step(tf.zeros([2])).reward
  
              [
                  observation_sample,
                  reward_sample,
                  env_time_sample,
              ] = self.evaluate([observation, reward, env_time])
              observation_samples.append(observation_sample)
              reward_samples.append(reward_sample)
              self.assertEqual(
                  env_time_sample, (t + 1) * dynamics.batch_size
              )
  
      else:
          ts = env.reset()
          observation = ts.observation
          reward = env.step(tf.zeros([2])).reward
  
          for t in range(0, 10):
              # The order of evaluations below matters. We first compute observation
              # batch, then the reward, and finally the env_time tensor. Joining the
              # evaluations in a single call does not guarantee the right order.
  
              observation_sample = self.evaluate(observation)
              reward_sample = self.evaluate(reward)
              env_time_sample = self.evaluate(env_time)
              observation_samples.append(observation_sample)
              reward_samples.append(reward_sample)
              self.assertEqual(
                  env_time_sample, (t + 1) * dynamics.batch_size
              )
  
      for t in range(0, 10):
          t_b = t * dynamics.batch_size
          self.assertAllClose(
              observation_samples[t],
              [
                  [1.0 + t_b, 2.0 + t_b, 3.0 + t_b],
                  [0.0 + t_b, 4.0 + t_b, 5.0 + t_b],
              ],
          )
          self.assertAllClose(reward_samples[t], [1, 0])
  
file_path: agents/tf_agents/bandits/environments/non_stationary_stochastic_environment_test.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import tensorflow
  import tensorflow_probability
  from tf_agents.bandits.environments import non_stationary_stochastic_environment
  from tf_agents.specs import tensor_spec
label_desc: Use image node_id 1 for calling the NonStationaryStochasticEnvironmentTest obj's underlying member method code with example usage: obj.testObservationAndRewardsVary() without return types