Commit bce2582f authored by Yannick Roehlly's avatar Yannick Roehlly
Browse files

Change the way configuration parameters are evaluated

parent 6f2e164a
...@@ -48,8 +48,9 @@ def evaluate_description(description): ...@@ -48,8 +48,9 @@ def evaluate_description(description):
- If the description is a string beginning with 'eval ', then its content - If the description is a string beginning with 'eval ', then its content
(without 'eval ') is evaluated as Python code and its result returned. (without 'eval ') is evaluated as Python code and its result returned.
An array is expected. An array is expected.
- If the description is a list beginning by 'range', the start, step and - If the description is a string beginning by 'range', the start, step and
stop values are then expected and the range is evaluated. stop values are then expected and the range is evaluated (stop included
if reached.
- Then the function tries to evaluate the description as a Numpy array of - Then the function tries to evaluate the description as a Numpy array of
float and returns the mere list if this fails. float and returns the mere list if this fails.
...@@ -64,25 +65,28 @@ def evaluate_description(description): ...@@ -64,25 +65,28 @@ def evaluate_description(description):
The evaluated list of values. The evaluated list of values.
""" """
results = description
if not type(description) == list: if type(description) == str:
description = [description] if description.startswith('eval '):
results = eval(description[4:])
if description[0].startswith('eval '): # If the evaluation lead to a single value, we put it in a list.
results = eval(description[0][4:]) if not isinstance(results, collections.Iterable):
# If the evaluation lead to a single value, we put it in a list. results = [results]
if not isinstance(results, collections.Iterable): elif description.startswith('range '):
start, stop, step = [float(item) for item
in description[5:].split()]
results = np.arange(start, stop+step, step)
else:
# We need to return a list to combine the list of possible values
# for each parameter.
results = [results] results = [results]
elif description[0] == 'range':
start = float(description[1]) # We prefer to evaluate the parameter as a numpy array of floats if
step = float(description[2]) # possible.
stop = float(description[3]) try:
results = np.arange(start, stop, step, float) results = np.array(results, float)
else: except ValueError:
try: pass
results = np.array(description, float)
except ValueError:
results = description
return results return results
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment