Skip to content

Commit e5c41e1

Browse files
committed
Fixed numpy warnings problems in evaluation and preev scripts
* Now the problem doesn't crash if a numpy warning is thrown in the evaluation scripts
1 parent 334c0e7 commit e5c41e1

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

MLC/Application.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,6 @@ def _set_numpy_parameters(self):
7979
np.set_printoptions(threshold=np.inf)
8080
# Don't show scientific notation
8181
np.set_printoptions(suppress=True)
82-
# Transform printed warnings to real warnings
83-
np.seterr(all='raise')
8482

8583
def go(self, to_generation, from_generation=None, display_best=False):
8684
"""
@@ -155,9 +153,6 @@ def go(self, to_generation, from_generation=None, display_best=False):
155153
# emit app finish event
156154
self.__callbacks_manager.on_event(MLC_CALLBACKS.ON_FINISH)
157155

158-
# Return the numpy warning configuration to its original value
159-
np.seterr(all='warn')
160-
161156
def get_simulation(self):
162157
return self._simulation
163158

MLC/Common/LispTreeExpr/LispTreeExpr.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ def __init__(self, expression):
2525
"[EXPR_EXCEPTION] Root node was not found. Expression: {0}"
2626
.format(expression))
2727

28+
2829
class TrailingTrashExprException(ExprException):
2930

3031
def __init__(self, expression):
@@ -122,9 +123,9 @@ def check_operands(expr):
122123

123124
if expr[pos] == '(':
124125
# The argument is another operator. Process it recursively
125-
argument_len = check_operands(expr[pos:])
126-
pos += argument_len
127-
if expr[pos] == ' ':
126+
argument_len = check_operands(expr[pos:])
127+
pos += argument_len
128+
if expr[pos] == ' ':
128129
pos += 1
129130
else:
130131
# The argument is a number or a sensor
@@ -181,6 +182,8 @@ def visit_leaf_node(self, node):
181182
# First, replace the sensors
182183
visitor = Replace_Sensors_Visitor(sensor_replacement_list)
183184
self._root.accept(visitor)
185+
186+
# Transform printed warnings to real warnings
184187
return self._root.compute()
185188

186189
def get_root_node(self):

MLC/Common/LispTreeExpr/OperationNodes.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -340,10 +340,15 @@ def simplify(self):
340340
return self
341341

342342
def compute(self):
343+
np.seterr(all='raise')
343344
if len(self._nodes) == 1:
344-
return self._nodes[0].compute()
345+
result = self._nodes[0].compute()
346+
np.seterr(all='warn')
347+
return result
345348

346-
return [node.compute() for node in self._nodes]
349+
result = [node.compute() for node in self._nodes]
350+
np.seterr(all='warn')
351+
return result
347352

348353
def formal(self):
349354
if len(self._nodes) == 1:

0 commit comments

Comments
 (0)