Skip to content

Commit

Permalink
ModelicaMixin: Fix reading of ca.DM nominals
Browse files Browse the repository at this point in the history
If the nominal from the model was a ca.DM instance, it would raise an
exception when calling np.isnan on it.

For performance reasons we want to avoid naively converting to float
twice, at least for the common case of the nominal being non-symbolic. To
that end, we use a similar resolving check for nominals as was already in
place for e.g seed() and bounds().
  • Loading branch information
Tjerk Vreeken committed Apr 4, 2019
1 parent 5e53fc5 commit 5bf0d9d
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/rtctools/optimization/modelica_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,10 +347,13 @@ def __nominals(self):
# If nominal contains parameter symbols, substitute them
if isinstance(nominal, ca.MX) and not nominal.is_constant():
[nominal] = substitute_in_external([nominal], self.__mx['parameters'], parameter_values)
if not nominal.is_constant() or np.isnan(float(nominal)):
logger.error('ModelicaMixin: Could not resolve nominal value for {}'.format(sym_name))
continue

if (not isinstance(nominal, ca.MX) and not np.isnan(nominal)) or nominal.is_constant():
nominal = float(nominal)
nominal = float(nominal)

if not np.isnan(nominal):
# Take absolute value (nominal sign is meaningless- a nominal is a magnitude)
nominal = abs(nominal)

Expand Down

0 comments on commit 5bf0d9d

Please sign in to comment.