@@ -427,6 +427,8 @@ def __init__(
427427 else :
428428 self ._getconn = OMCSessionZMQ (omhome = omhome )
429429
430+ # get OpenModelica version
431+ self ._version = self .sendExpression ("getVersion()" , parsed = True )
430432 # set commandLineOptions using default values or the user defined list
431433 if commandLineOptions is None :
432434 # set default command line options to improve the performance of linearization and to avoid recompilation if
@@ -996,6 +998,13 @@ def getOptimizationOptions(self, names: Optional[str | list[str]] = None) -> dic
996998
997999 raise ModelicaSystemError ("Unhandled input for getOptimizationOptions()" )
9981000
1001+ def parse_om_version (self , version : str ) -> tuple [int , int , int ]:
1002+ match = re .search (r"v?(\d+)\.(\d+)\.(\d+)" , version )
1003+ if not match :
1004+ raise ValueError (f"Version not found in: { version } " )
1005+ major , minor , patch = map (int , match .groups ())
1006+ return major , minor , patch
1007+
9991008 def simulate_cmd (
10001009 self ,
10011010 result_file : pathlib .Path ,
@@ -1044,11 +1053,23 @@ def simulate_cmd(
10441053 if self ._override_variables or self ._simulate_options_override :
10451054 override_file = result_file .parent / f"{ result_file .stem } _override.txt"
10461055
1047- override_content = (
1056+ # simulation options are not read from override file from version >= 1.26.0,
1057+ # pass them to simulation executable directly as individual arguments
1058+ # see https://github.com/OpenModelica/OpenModelica/pull/14813
1059+ major , minor , patch = self .parse_om_version (self ._version )
1060+ if (major , minor , patch ) >= (1 , 26 , 0 ):
1061+ for key , opt_value in self ._simulate_options_override .items ():
1062+ om_cmd .arg_set (key = key , val = str (opt_value ))
1063+ override_content = (
1064+ "\n " .join ([f"{ key } ={ value } " for key , value in self ._override_variables .items ()])
1065+ + "\n "
1066+ )
1067+ else :
1068+ override_content = (
10481069 "\n " .join ([f"{ key } ={ value } " for key , value in self ._override_variables .items ()])
10491070 + "\n " .join ([f"{ key } ={ value } " for key , value in self ._simulate_options_override .items ()])
10501071 + "\n "
1051- )
1072+ )
10521073
10531074 override_file .write_text (override_content )
10541075 om_cmd .arg_set (key = "overrideFile" , val = override_file .as_posix ())
@@ -1642,15 +1663,32 @@ def linearize(
16421663 timeout = timeout ,
16431664 )
16441665
1645- overrideLinearFile = self .getWorkDirectory () / f'{ self ._model_name } _override_linear.txt'
1666+ # See comment in simulate_cmd regarding override file and OM version
1667+ major , minor , patch = self .parse_om_version (self ._version )
1668+ if (major , minor , patch ) >= (1 , 26 , 0 ):
1669+ for key , opt_value in self ._linearization_options .items ():
1670+ om_cmd .arg_set (key = key , val = str (opt_value ))
1671+ override_content = (
1672+ "\n " .join ([f"{ key } ={ value } " for key , value in self ._override_variables .items ()])
1673+ + "\n "
1674+ )
1675+ else :
1676+ override_content = (
1677+ "\n " .join ([f"{ key } ={ value } " for key , value in self ._override_variables .items ()])
1678+ + "\n " .join ([f"{ key } ={ value } " for key , value in self ._linearization_options .items ()])
1679+ + "\n "
1680+ )
1681+
1682+ override_file = self .getWorkDirectory () / f'{ self ._model_name } _override_linear.txt'
1683+ override_file .write_text (override_content )
16461684
1647- with open (file = overrideLinearFile , mode = "w" , encoding = "utf-8" ) as fh :
1685+ with open (file = override_file , mode = "w" , encoding = "utf-8" ) as fh :
16481686 for key1 , value1 in self ._override_variables .items ():
16491687 fh .write (f"{ key1 } ={ value1 } \n " )
16501688 for key2 , value2 in self ._linearization_options .items ():
16511689 fh .write (f"{ key2 } ={ value2 } \n " )
16521690
1653- om_cmd .arg_set (key = "overrideFile" , val = overrideLinearFile .as_posix ())
1691+ om_cmd .arg_set (key = "overrideFile" , val = override_file .as_posix ())
16541692
16551693 if self ._inputs :
16561694 for key in self ._inputs :
0 commit comments