diff --git a/examples/scripts/sellar_problem.py b/examples/scripts/sellar_problem.py index ab50a30690607b87fe88d843241a80d20aff7244..21d6b052c926308fc95b55c6116d09328c6b7321 100644 --- a/examples/scripts/sellar_problem.py +++ b/examples/scripts/sellar_problem.py @@ -50,7 +50,7 @@ rcg.add_node('D3', category='function') rcg.add_node('F1', category='function', function_type='regular', sleep_time=0.) rcg.add_node('F2', category='function') rcg.add_node('G1', category='function', function_type='regular', sleep_time=0.) -rcg.add_node('G2', category='function', function_type='regular', sleep_time=0.) +rcg.add_node('G2', category='function', function_type='regular') # All variable nodes are defined rcg.add_node('/dataSchema/settings/a', category='variable', label='a') rcg.add_node('/dataSchema/settings/c', category='variable', label='c') diff --git a/kadmos/graph/mixin_equation.py b/kadmos/graph/mixin_equation.py index 59119fdf3c5482ab4b1147888b8404decf31d648..4a6e7a8c644612f3a4070bd7e73ad54c01abd9b4 100644 --- a/kadmos/graph/mixin_equation.py +++ b/kadmos/graph/mixin_equation.py @@ -3,8 +3,7 @@ import math import logging from ..utilities.xmls import Element -from ..utilities.general import get_uid - +from ..utilities.general import get_uid, make_float_or_keep_none # Settings for the logger logger = logging.getLogger(__name__) @@ -231,8 +230,8 @@ class EquationMixin(object): # Create mathematicalFunctions/mathematicalFunction cmdows_math_func = cmdows_math_funcs.add('mathematicalFunction', uID=graph_math_func) cmdows_math_func.add('label', self.node[graph_math_func].get('label', graph_math_func)) - cmdows_math_func.add('functionType', self.node[graph_math_func].get('function_type', graph_math_func)) - cmdows_math_func.add('sleepTime', self.node[graph_math_func].get('sleep_time', graph_math_func)) + cmdows_math_func.add('functionType', self.node[graph_math_func].get('function_type')) + cmdows_math_func.add('sleepTime', make_float_or_keep_none(self.node[graph_math_func].get('sleep_time'))) # Create mathematicalFunctions/mathematicalFunction/inputs with children cmdows_inputs = cmdows_math_func.add('inputs') @@ -279,7 +278,7 @@ class EquationMixin(object): shape='s', label=function.findtext('label'), function_type=function.findtext('functionType'), - sleep_time=float(function.findtext('sleepTime'))) + sleep_time=make_float_or_keep_none(function.findtext('sleepTime'))) for inp in function.findall('inputs/input'): self.add_edge(inp.findtext('parameterUID').replace("'", '"'), function.get('uID'), equation_label=inp.findtext('equationLabel'), diff --git a/kadmos/utilities/general.py b/kadmos/utilities/general.py index d8daa97e094f9cf389a7ca943673cac07a4124ff..98d1a505e749297b9ac1a51df0e00c5a76a4f15e 100644 --- a/kadmos/utilities/general.py +++ b/kadmos/utilities/general.py @@ -858,3 +858,12 @@ def unzip_file(file_to_unzip, destination_folder=None): zip_ref.extractall(destination_folder) zip_ref.close() return extracted_file + + +def make_float_or_keep_none(value): + if isinstance(value, (float, int, str)): + return float(value) + elif value is None: + return None + else: + raise AssertionError('Could not process value {} which is of type {}.'.format(value, type(value))) \ No newline at end of file