Skip to content

Commit 28696c2

Browse files
committed
Unit tests fixes
1 parent d445c86 commit 28696c2

22 files changed

Lines changed: 116 additions & 99 deletions

File tree

MLC/Application.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ def go(self, to_generation, from_generation=None, display_best=False):
123123
self._set_numpy_parameters()
124124
self.__display_best = display_best
125125

126+
print(Config.get_instance()["EVALUATOR"]["evaluation_function"])
127+
126128
if from_generation is None:
127129
from_generation = self._mlc_repository.count_population()
128130

MLC/Common/PreevaluationManager.py

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121

2222
import MLC.Log.log as lg
2323
import importlib
24+
import imp
25+
import os
2426
import sys
2527
from MLC.mlc_parameters.mlc_parameters import Config
2628

@@ -42,25 +44,26 @@ def get_callback():
4244
function_name = Config.get_instance().get('EVALUATOR', 'preev_function')
4345
module_name = "Preevaluation.{0}".format(function_name)
4446

45-
# try:
46-
# # WARNING: I am unloading manually the evaluation function module. I need to do this
47-
# # because Python does not support module unloading and my evaluation functions are
48-
# # all the same, so when one experiment loads his module, other project with the same
49-
# # name of module won't be able to load yours
50-
# preev_module = sys.modules["Preevaluation"]
51-
# del sys.modules['Preevaluation']
52-
# del preev_module
53-
# lg.logger_.debug("[EV_FACTORY] Module {0} was removed"
54-
# .format(sys.modules["Preevaluation"]))
55-
# except KeyError as err:
56-
# # If the module cannot be unload because it does not exists, continue
57-
# pass
47+
try:
48+
# WARNING: I am unloading manually the evaluation function module. I need to do this
49+
# because Python does not support module unloading and my evaluation functions are
50+
# all the same, so when one experiment loads his module, other project with the same
51+
# name of module won't be able to load yours
52+
preev_module = sys.modules["Preevaluation"]
53+
del sys.modules['Preevaluation']
54+
del preev_module
55+
lg.logger_.debug("[EV_FACTORY] Module {0} was removed"
56+
.format(sys.modules["Preevaluation"]))
57+
except KeyError as err:
58+
# If the module cannot be unload because it does not exists, continue
59+
pass
5860

5961
lg.logger_.debug('[PREEV_MANAGER] Importing module {0}'.format(module_name))
6062
try:
61-
module = importlib.import_module(module_name)
62-
importlib.reload(module)
63-
return module
63+
return imp.load_source("Preevaluation." + function_name,
64+
os.path.join(*[sys.path[-1],
65+
"Preevaluation",
66+
function_name + ".py"]))
6467
except ImportError:
6568
lg.logger_.debug("[PREEV_MANAGER] Preevaluation function doesn't exists. " +
6669
"Aborting program...")

MLC/Population/Evaluation/EvaluatorFactory.py

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@
1515
# but WITHOUT ANY WARRANTY; without even the implied warranty of
1616
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1717
# GNU General Public License for more details.
18-
#
18+
1919
# You should have received a copy of the GNU General Public License
2020
# along with this program. If not, see <http://www.gnu.org/licenses/>
2121

2222
import MLC.Log.log as lg
2323
import importlib
24+
import imp
25+
import os
2426
import sys
2527

2628
from MLC.mlc_parameters.mlc_parameters import Config
@@ -34,25 +36,26 @@ def get_callback():
3436
function_name = Config.get_instance().get('EVALUATOR', 'evaluation_function')
3537
module_name = 'Evaluation.{0}'.format(function_name)
3638

37-
# try:
38-
# # WARNING: I am unloading manually the evaluation function module. I need to do this
39-
# # because Python does not support module unloading and my evaluation functions are
40-
# # all the same, so when one experiment loads his module, other project with the same
41-
# # name of module won't be able to load yours
42-
# # ev_module = sys.modules["Evaluation"]
43-
# # del sys.modules['Evaluation']
44-
# # del ev_module
45-
# lg.logger_.debug("[EV_FACTORY] Module {0} was removed".format(sys.modules["Evaluation"]))
46-
# except KeyError as err:
47-
# # If the module cannot be unload because it does not exists, continue
48-
# pass
39+
try:
40+
# WARNING: I am unloading manually the evaluation function module. I need to do this
41+
# because Python does not support module unloading and my evaluation functions are
42+
# all the same, so when one experiment loads his module, other project with the same
43+
# name of module won't be able to load yours
44+
ev_module = sys.modules["Evaluation"]
45+
print(ev_module)
46+
del sys.modules['Evaluation']
47+
del ev_module
48+
lg.logger_.debug("[EV_FACTORY] Module {0} was removed".format(sys.modules["Evaluation"]))
49+
except KeyError as err:
50+
# If the module cannot be unload because it does not exists, continue
51+
pass
4952

5053
lg.logger_.debug('[EV_FACTORY] Importing module {0}'.format(module_name))
5154
try:
52-
# lg.logger_.debug("[EV_FACTORY] Sys.path: {0}".format(sys.path))
53-
module = importlib.import_module(module_name)
54-
importlib.reload(module)
55-
return module
55+
return imp.load_source("Evaluation." + function_name,
56+
os.path.join(*[sys.path[-1],
57+
"Evaluation",
58+
function_name + ".py"]))
5659
except ImportError as err:
5760
lg.logger_.debug("[EV_FACTORY] Evaluation function doesn't exists. "
5861
"Aborting program. Error Msg: {0}".format(err))

MLC/arduino/protocol.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ def actuate(self, data):
240240
# for x in self._anlg_inputs + self._digital_inputs} # One dictionary
241241
# to save all ports results
242242

243-
results = dict(digital_res.items() + analog_res.items())
243+
results = dict(list(digital_res.items()) + list(analog_res.items()))
244244

245245
while pos < length:
246246
pin = ord(data[pos])
@@ -253,13 +253,13 @@ def actuate(self, data):
253253

254254
if self._report_mode == REPORT_MODES.AVERAGE:
255255
results["A%d" % (pin - len(self._board["DIGITAL_PINS"]))] = [
256-
sum(results["A%d" % (pin - len(self._board["DIGITAL_PINS"]))]) / (self._read_count + 1)]
256+
sum(results["A%d" % (pin - len(self._board["DIGITAL_PINS"]))]) // (self._read_count + 1)]
257257
else:
258258
if pin in self._digital_inputs:
259259
for i in range(0, self._read_count + 1):
260260
results["D%d" % (pin)].append(
261-
bool(ord(data[pos + 1 + i / 8]) & (0x01 << (i % 8))))
262-
pos = pos + 1 + self._read_count / 8 + 1
261+
bool(ord(data[pos + 1 + i // 8]) & (0x01 << (i % 8))))
262+
pos = pos + 1 + self._read_count // 8 + 1
263263

264264
if self._report_mode == REPORT_MODES.AVERAGE:
265265
results["D%d" % (pin)] = [
@@ -326,7 +326,7 @@ def get_instance(protocol_config=None, conn_setup=None):
326326
if protocol_config and conn_setup:
327327
serial_conn = None
328328
try:
329-
#serial_conn = SerialConnection(**conn_setup)
329+
# serial_conn = SerialConnection(**conn_setup)
330330
connection = ArduinoUserInterface._connection_builder[0](conn_setup)
331331
except ConnectionException as err:
332332
lg.logger_.info("[PROTOCOL] Error while building connection. "

MLC/mlc_parameters/mlc_parameters.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,5 +87,6 @@ def from_dictionary(cls, config_dict, config_type=None):
8787
for section, options in config_dict.items():
8888
config.add_section(section)
8989
for opt, value in options.items():
90-
config.set(section, opt, value)
90+
# print("Option: {} - Type: {}: ".format(opt, type(opt)))
91+
config[section][opt] = str(value)
9192
return config

conf/configuration_simulink_ev.ini

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ artificialnoise = 0
6767
execute_before_evaluation =
6868
badvalue = 1e36
6969
badvalues_elim = first
70-
%badvalues_elim = none
71-
%badvalues_elim = all
70+
# badvalues_elim = none
71+
# badvalues_elim = all
7272
preevaluation = true
7373
preev_function = simulink_preev
7474
problem_variables.gamma = 0.1

tests/default_test_configuration.ini

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ artificialnoise = 0
6363
execute_before_evaluation =
6464
badvalue = 1e36
6565
badvalues_elim = first
66-
%badvalues_elim = none
67-
%badvalues_elim = all
66+
# badvalues_elim = none
67+
# badvalues_elim = all
6868
preevaluation = false
6969
preev_function = default
7070
problem_variables.gamma = 0.1

tests/integration_tests/test_basic/configuration.ini

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ artificialnoise = 0
6161
execute_before_evaluation =
6262
badvalue = 1e36
6363
badvalues_elim = first
64-
%badvalues_elim = none
65-
%badvalues_elim = all
64+
# badvalues_elim = none
65+
# badvalues_elim = all
6666
preevaluation = false
6767
preev_function = default_preevaluation_script
6868
problem_variables.gamma = 0.1

tests/integration_tests/test_multiple_controls/configuration.ini

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ artificialnoise = 0
6464
execute_before_evaluation =
6565
badvalue = 1e36
6666
badvalues_elim = first
67-
%badvalues_elim = none
68-
%badvalues_elim = all
67+
# badvalues_elim = none
68+
# badvalues_elim = all
6969
preevaluation = false
7070
preev_function = default_preevaluation_script
7171
problem_variables.gamma = 0.1

tests/integration_tests/test_persist_reusing_simulations/configuration.ini

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ artificialnoise = 0
6363
execute_before_evaluation =
6464
badvalue = 1e36
6565
badvalues_elim = first
66-
%badvalues_elim = none
67-
%badvalues_elim = all
66+
# badvalues_elim = none
67+
# badvalues_elim = all
6868
preevaluation = false
6969
preev_function = default_preevaluation_script
7070
problem_variables.gamma = 0.1

0 commit comments

Comments
 (0)