-
Notifications
You must be signed in to change notification settings - Fork 56
/
Copy pathtest_examples.py
152 lines (129 loc) · 7.2 KB
/
test_examples.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
'''
Unit test for all of the example scripts provided in the examples folder.
'''
from __future__ import absolute_import, division, print_function
import os
import unittest
import mloop.testing as mlt
import mloop.launchers as mll
import mloop.utilities as mlu
import logging
import numpy as np
import multiprocessing as mp
class TestExamples(unittest.TestCase):
@classmethod
def setUpClass(cls):
os.chdir(mlu.mloop_path + '/../tests')
cls.override_dict = {'file_log_level':logging.WARNING,'console_log_level':logging.DEBUG,'visualizations':False}
@classmethod
def tearDownClass(cls):
pass
def test_controller_config(self):
controller = mll.launch_from_file(mlu.mloop_path+'/../examples/controller_config.txt',
interface_type = 'test',
no_delay = False,
**self.override_dict)
self.asserts_for_cost_and_params(controller)
def test_extras_config(self):
controller = mll.launch_from_file(mlu.mloop_path+'/../examples/extras_config.txt',
num_params=1,
min_boundary = [-1.0],
max_boundary = [1.0],
target_cost = 0.1,
interface_type = 'test',
no_delay = False,
**self.override_dict)
self.asserts_for_cost_and_params(controller)
def test_logging_config(self):
controller = mll.launch_from_file(mlu.mloop_path+'/../examples/logging_config.txt',
num_params=1,
min_boundary = [-1.0],
max_boundary = [1.0],
target_cost = 0.1,
interface_type = 'test',
no_delay = False,
**self.override_dict)
self.asserts_for_cost_and_params(controller)
def test_random_simple_config(self):
_ = mll.launch_from_file(mlu.mloop_path+'/../examples/random_simple_config.txt',
interface_type = 'test',
**self.override_dict)
def test_random_complete_config(self):
_ = mll.launch_from_file(mlu.mloop_path+'/../examples/random_complete_config.txt',
interface_type = 'test',
**self.override_dict)
def test_nelder_mead_simple_config(self):
controller = mll.launch_from_file(mlu.mloop_path+'/../examples/nelder_mead_simple_config.txt',
interface_type = 'test',
**self.override_dict)
self.asserts_for_cost_and_params(controller)
def test_nelder_mead_complete_config(self):
controller = mll.launch_from_file(mlu.mloop_path+'/../examples/nelder_mead_complete_config.txt',
interface_type = 'test',
**self.override_dict)
self.asserts_for_cost_and_params(controller)
def test_differential_evolution_simple_config(self):
controller = mll.launch_from_file(mlu.mloop_path+'/../examples/differential_evolution_simple_config.txt',
interface_type = 'test',
**self.override_dict)
self.asserts_for_cost_and_params(controller)
def test_differential_evolution_complete_config(self):
controller = mll.launch_from_file(mlu.mloop_path+'/../examples/differential_evolution_complete_config.txt',
interface_type = 'test',
**self.override_dict)
self.asserts_for_cost_and_params(controller)
def test_gaussian_process_simple_config(self):
controller = mll.launch_from_file(mlu.mloop_path+'/../examples/gaussian_process_simple_config.txt',
interface_type = 'test',
no_delay = False,
**self.override_dict)
self.asserts_for_cost_and_params(controller)
def test_gaussian_process_complete_config(self):
controller = mll.launch_from_file(mlu.mloop_path+'/../examples/gaussian_process_complete_config.txt',
interface_type = 'test',
no_delay = False,
**self.override_dict)
self.asserts_for_cost_and_params(controller)
def test_neural_net_simple_config(self):
controller = mll.launch_from_file(mlu.mloop_path+'/../examples/neural_net_simple_config.txt',
interface_type = 'test',
no_delay = False,
**self.override_dict)
self.asserts_for_cost_and_params(controller)
def test_neural_net_complete_config(self):
controller = mll.launch_from_file(mlu.mloop_path+'/../examples/neural_net_complete_config.txt',
interface_type = 'test',
no_delay = False,
**self.override_dict)
self.asserts_for_cost_and_params(controller)
def test_tutorial_config(self):
fake_experiment = mlt.FakeExperiment()
fake_experiment.start()
controller = mll.launch_from_file(mlu.mloop_path+'/../examples/tutorial_config.txt',
**self.override_dict)
self.asserts_for_cost_and_params(controller)
fake_experiment.end_event.set()
fake_experiment.join()
def test_file_interface_config(self):
fake_experiment = mlt.FakeExperiment()
fake_experiment.start()
controller = mll.launch_from_file(mlu.mloop_path+'/../examples/file_interface_config.txt',
num_params=1,
target_cost = 0.1,
**self.override_dict)
self.asserts_for_cost_and_params(controller)
fake_experiment.end_event.set()
fake_experiment.join()
def test_shell_interface_config(self):
controller = mll.launch_from_file(mlu.mloop_path+'/../examples/shell_interface_config.txt',
num_params=1,
target_cost = 0.1,
no_delay = False,
**self.override_dict)
self.asserts_for_cost_and_params(controller)
def asserts_for_cost_and_params(self,controller):
self.assertTrue(controller.best_cost<=controller.target_cost)
self.assertTrue(np.sum(np.square(controller.best_params))<=controller.target_cost)
if __name__ == "__main__":
mp.freeze_support()
unittest.main()