Пример #1
0
 def test_batched_step(self):
     """
     Make sure that the outputs of batched steps are
     the correct shape.
     """
     with self.graph.as_default():
         env = TupleCartPole()
         try:
             obs_space = env.observation_space
         finally:
             env.close()
         batch_size = 7
         in_obses = [obs_space.sample() for _ in range(batch_size)]
         in_states = self.model.start_state(batch_size)
         outs = self.model.step(in_obses, in_states)
         self.test_case.assertEqual(len(outs['actions']), batch_size)
         self.test_case.assertEqual(_state_shape_uid(outs['states']),
                                    _state_shape_uid(in_states))
         if 'action_params' in outs:
             param_shape = self.model.action_dist.param_shape
             self.test_case.assertEqual(
                 np.array(outs['action_params']).shape,
                 (batch_size, ) + param_shape)
         if 'values' in outs:
             self.test_case.assertEqual(
                 np.array(outs['values']).shape, (batch_size, ))
Пример #2
0
def run_ac_test(maker):
    """
    Run a test given a model constructor.
    """
    env = TupleCartPole()
    try:
        spaces = gym_spaces(env)
    finally:
        env.close()
    ModelTester(lambda sess: maker(sess, *spaces)).test_all()
Пример #3
0
 def __init__(self, *args, **kwargs):
     super(ACTest, self).__init__(*args, **kwargs)
     self.session = tf.Session()
     env = TupleCartPole()
     try:
         action_space = env.action_space
         observation_space = env.observation_space
     finally:
         env.close()
     self.action_dist = gym_space_distribution(action_space)
     self.obs_vectorizer = gym_space_vectorizer(observation_space)
Пример #4
0
def run_ac_test(maker):
    """
    Run a test given a model constructor.
    """
    env = TupleCartPole()
    try:
        action_space = env.action_space
        observation_space = env.observation_space
    finally:
        env.close()
    action_dist = gym_space_distribution(action_space)
    obs_vectorizer = gym_space_vectorizer(observation_space)
    ModelTester(
        lambda sess: maker(sess, action_dist, obs_vectorizer)).test_all()
Пример #5
0
 def _test_batches_consistency(self, batch_size, trunc_start):
     """
     Make sure that batches() produces the same outputs
     that we got with step().
     """
     env = TupleCartPole()
     try:
         roller = BasicRoller(env, self.model, min_episodes=7)
         rollouts = roller.rollouts()
         if trunc_start:
             rollouts = self._truncate_first(rollouts)
         num_batches = 10
         for batch in self.model.batches(rollouts, batch_size=batch_size):
             num_batches -= 1
             if num_batches == 0:
                 break
             self._test_batch(rollouts, batch)
     finally:
         env.close()