Skip to content

Commit

Permalink
Function compile error now raised when the return type of ObjectiveCo…
Browse files Browse the repository at this point in the history
…nstraint's exec is not a float
  • Loading branch information
mlauer154 committed Aug 30, 2023
1 parent ef51e99 commit 4437c9e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"label": "Objective Functions:",
"widget_type": "QLineEdit",
"setText": "$Cd",
"setToolTip": "Enter the objective functions to be minimized, separated by commas.\nVariables can be started with the dollar sign ($)."
"setToolTip": "Enter the objective functions to be minimized, separated by commas.\nVariables can be started with the dollar sign ($).\nNote: if multi-point optimization is active, each variable\nmust be indexed to ensure the return type is a float rather\nthat a list. For example, $Cd[0] must be used rather than\n$Cd if multi-point optimization is active. Here, $Cd[0]\ncorresponds to the drag coefficient of the airfoil (system) evaluated\nusing the first multi-point stencil point values."
},
"G": {
"label": "Constraints:",
Expand Down
5 changes: 4 additions & 1 deletion pymead/optimization/objectives_and_constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ def update_function(self):
if execute:
try:
exec(self.func, self.function_dict)
return_val = self.function_dict["f"]()
if not isinstance(return_val, float):
raise FunctionCompileError(f"Error in function compilation output type. Required type is float,"
f"found type {type(return_val)}")
except (SyntaxError, NameError, TypeError):
raise FunctionCompileError('Error in function compilation')

Expand Down Expand Up @@ -114,7 +118,6 @@ def parse_update_function_str(self):
a ``Param`` name. For example, the string ``"A0.Base.R_le"`` corresponds to the leading edge radius of the base
parameter set of airfoil ``"A0"``.
"""
# TODO: throw an error if an objective function is setup without indexing despite multipoint being active
self.tag_matrix = []
self.func = 'def f(): return '
math_functions_to_include = []
Expand Down

0 comments on commit 4437c9e

Please sign in to comment.