google-research

Форк
0
/
objects_test.py 
56 строк · 1.9 Кб
1
# coding=utf-8
2
# Copyright 2024 The Google Research Authors.
3
#
4
# Licensed under the Apache License, Version 2.0 (the "License");
5
# you may not use this file except in compliance with the License.
6
# You may obtain a copy of the License at
7
#
8
#     http://www.apache.org/licenses/LICENSE-2.0
9
#
10
# Unless required by applicable law or agreed to in writing, software
11
# distributed under the License is distributed on an "AS IS" BASIS,
12
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
# See the License for the specific language governing permissions and
14
# limitations under the License.
15

16
"""Tests for ES-ENAS objects."""
17

18
from absl.testing import absltest
19
from absl.testing import parameterized
20
import pyglove as pg
21
from es_enas import config as config_util
22
from es_enas import objects
23

24

25
class ObjectsTest(parameterized.TestCase):
26

27
  def setUp(self):
28
    self.base_config = config_util.get_config()
29
    super().setUp()
30

31
  @parameterized.named_parameters(
32
      ('Random', 'random'), ('PolicyGradient', 'policy_gradient'),
33
      ('RegularizedEvolution', 'regularized_evolution'))
34
  def test_GeneralTopologyBlackboxObject(self, controller_str):
35
    self.base_config.controller_type_str = controller_str
36
    self.base_config.horizon = 2
37
    self.base_config.environment_name = 'Pendulum'
38

39
    self.config = config_util.generate_config(
40
        self.base_config, current_time_string='TEST')
41

42
    self.config.setup_controller_fn()
43
    self.object = objects.GeneralTopologyBlackboxObject(self.config)
44

45
    optimizer = self.config.es_blackbox_optimizer_fn(
46
        self.object.get_metaparams())
47

48
    params = self.object.get_initial()
49
    topology_str = pg.to_json(self.config.controller.propose_dna())
50
    core_hyperparams = optimizer.get_hyperparameters()
51
    hyperparams = [0] + list(core_hyperparams)
52
    self.object.execute_with_topology(params, topology_str, hyperparams)
53

54

55
if __name__ == '__main__':
56
  absltest.main()
57

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.