code: def test_ppo_dataset_recurrent_and_non_recurrent_equivalence(
      use_obs_normalizer, gamma, lambd, max_recurrent_sequence_len
  ):
      """Test equivalence between recurrent and non-recurrent datasets.
  
      When the same feed-forward model is used, the values of
      log_prob, v_pred, next_v_pred obtained by both recurrent and
      non-recurrent dataset creation functions should be the same.
      """
      episodes = make_random_episodes()
      if use_obs_normalizer:
          obs_normalizer = pfrl.nn.EmpiricalNormalization(
              2, clip_threshold=5
          )
          obs_normalizer.experience(torch.rand(10, 2))
      else:
          obs_normalizer = None
  
      def phi(obs):
          return (obs * 0.5).astype(np.float32)
  
      device = torch.device("cpu")
  
      obs_size = 2
      n_actions = 3
  
      non_recurrent_model = pfrl.nn.Branched(
          nn.Sequential(
              nn.Linear(obs_size, n_actions),
              SoftmaxCategoricalHead(),
          ),
          nn.Linear(obs_size, 1),
      )
      recurrent_model = RecurrentSequential(
          non_recurrent_model,
      )
  
      dataset = pfrl.agents.ppo._make_dataset(
          episodes=copy.deepcopy(episodes),
          model=non_recurrent_model,
          phi=phi,
          batch_states=batch_states,
          obs_normalizer=obs_normalizer,
          gamma=gamma,
          lambd=lambd,
          device=device,
      )
  
      dataset_recurrent = pfrl.agents.ppo._make_dataset_recurrent(
          episodes=copy.deepcopy(episodes),
          model=recurrent_model,
          phi=phi,
          batch_states=batch_states,
          obs_normalizer=obs_normalizer,
          gamma=gamma,
          lambd=lambd,
          max_recurrent_sequence_len=max_recurrent_sequence_len,
          device=device,
      )
  
      assert "log_prob" not in episodes[0][0]
      assert "log_prob" in dataset[0]
      assert "log_prob" in dataset_recurrent[0][0]
      # They are not just shallow copies
      assert (
          dataset[0]["log_prob"]
          is not dataset_recurrent[0][0]["log_prob"]
      )
  
      states = [tr["state"] for tr in dataset]
      recurrent_states = [
          tr["state"]
          for tr in itertools.chain.from_iterable(dataset_recurrent)
      ]
      torch_assert_allclose(states, recurrent_states)
  
      actions = [tr["action"] for tr in dataset]
      recurrent_actions = [
          tr["action"]
          for tr in itertools.chain.from_iterable(dataset_recurrent)
      ]
      torch_assert_allclose(actions, recurrent_actions)
  
      rewards = [tr["reward"] for tr in dataset]
      recurrent_rewards = [
          tr["reward"]
          for tr in itertools.chain.from_iterable(dataset_recurrent)
      ]
      torch_assert_allclose(rewards, recurrent_rewards)
  
      nonterminals = [tr["nonterminal"] for tr in dataset]
      recurrent_nonterminals = [
          tr["nonterminal"]
          for tr in itertools.chain.from_iterable(dataset_recurrent)
      ]
      torch_assert_allclose(nonterminals, recurrent_nonterminals)
  
      log_probs = [tr["log_prob"] for tr in dataset]
      recurrent_log_probs = [
          tr["log_prob"]
          for tr in itertools.chain.from_iterable(dataset_recurrent)
      ]
      torch_assert_allclose(log_probs, recurrent_log_probs)
  
      vs_pred = [tr["v_pred"] for tr in dataset]
      recurrent_vs_pred = [
          tr["v_pred"]
          for tr in itertools.chain.from_iterable(dataset_recurrent)
      ]
      torch_assert_allclose(vs_pred, recurrent_vs_pred)
  
      next_vs_pred = [tr["next_v_pred"] for tr in dataset]
      recurrent_next_vs_pred = [
          tr["next_v_pred"]
          for tr in itertools.chain.from_iterable(dataset_recurrent)
      ]
      torch_assert_allclose(next_vs_pred, recurrent_next_vs_pred)
  
      advs = [tr["adv"] for tr in dataset]
      recurrent_advs = [
          tr["adv"]
          for tr in itertools.chain.from_iterable(dataset_recurrent)
      ]
      torch_assert_allclose(advs, recurrent_advs)
  
      vs_teacher = [tr["v_teacher"] for tr in dataset]
      recurrent_vs_teacher = [
          tr["v_teacher"]
          for tr in itertools.chain.from_iterable(dataset_recurrent)
      ]
      torch_assert_allclose(vs_teacher, recurrent_vs_teacher)
  
imports: import copy
  import itertools
  import os
  import tempfile
  import unittest
  import numpy
  import pytest
  import torch
  from torch import nn
  import pfrl
  from pfrl.agents import ppo
  from pfrl.agents.ppo import PPO
  from pfrl.envs.abc import ABC
  from pfrl.experiments import train_agent_batch_with_evaluation, train_agent_with_evaluation
  from pfrl.experiments.evaluator import batch_run_evaluation_episodes, run_evaluation_episodes
  from pfrl.nn import RecurrentBranched, RecurrentSequential
  from pfrl.policies import GaussianHeadWithStateIndependentCovariance, SoftmaxCategoricalHead
  from pfrl.testing import torch_assert_allclose
  from pfrl.utils.batch_states import batch_states
label_desc: Use image node_id 2 for calling a global function with example usage: test_ppo_dataset_recurrent_and_non_recurrent_equivalence(use_obs_normalizer, gamma, lambd, max_recurrent_sequence_len) and returns: unknown