code: def test_obtain_samples():
      env = GridWorldEnv(desc="4x4")
      policy = ScriptedPolicy(
          scripted_actions=[
              2,
              2,
              1,
              0,
              3,
              1,
              1,
              1,
              2,
              2,
              1,
              1,
              1,
              2,
              2,
              1,
          ]
      )
      algo = Mock(
          env_spec=env.spec, policy=policy, max_episode_length=16
      )
  
      workers = WorkerFactory(
          seed=100,
          max_episode_length=algo.max_episode_length,
          n_workers=8,
      )
      sampler1 = MultiprocessingSampler.from_worker_factory(
          workers, policy, env
      )
      sampler2 = LocalSampler.from_worker_factory(workers, policy, env)
      eps1 = sampler1.obtain_samples(
          0, 1000, tuple(algo.policy.get_param_values())
      )
      eps2 = sampler2.obtain_samples(
          0, 1000, tuple(algo.policy.get_param_values())
      )
      # pylint: disable=superfluous-parens
      assert eps1.observations.shape[0] >= 1000
      assert eps1.actions.shape[0] >= 1000
      assert (
          sum(eps1.rewards[: eps1.lengths[0]])
          == sum(eps2.rewards[: eps2.lengths[0]])
          == 1
      )
  
      true_obs = np.array([0, 1, 2, 6, 10, 14])
      true_actions = np.array([2, 2, 1, 1, 1, 2])
      true_rewards = np.array([0, 0, 0, 0, 0, 1])
      start = 0
      for length in eps1.lengths:
          observations = eps1.observations[start : start + length]
          actions = eps1.actions[start : start + length]
          rewards = eps1.rewards[start : start + length]
          assert np.array_equal(observations, true_obs)
          assert np.array_equal(actions, true_actions)
          assert np.array_equal(rewards, true_rewards)
          start += length
      sampler1.shutdown_worker()
      sampler2.shutdown_worker()
      env.close()
  
file_path: garage/tests/garage/sampler/test_multiprocessing_sampler.py
imports: import pickle
  from unittest.mock import Mock
  import numpy
  import pytest
  from garage.envs import PointEnv
  from garage.envs.grid_world_env import GridWorldEnv
  from garage.experiment.task_sampler import SetTaskSampler
  from garage.np.policies import FixedPolicy, ScriptedPolicy
  from garage.sampler import LocalSampler, MultiprocessingSampler, WorkerFactory
label_desc: Use image node_id 1 for calling a global function with example usage: test_obtain_samples() without return types