|
7 | 7 | This file is part of OpenModelica. |
8 | 8 |
|
9 | 9 | Copyright (c) 1998-CurrentYear, Open Source Modelica Consortium (OSMC), |
10 | | - c/o Linköpings universitet, Department of Computer and Information Science, |
11 | | - SE-58183 Linköping, Sweden. |
| 10 | + c/o Link�pings universitet, Department of Computer and Information Science, |
| 11 | + SE-58183 Link�ping, Sweden. |
12 | 12 |
|
13 | 13 | All rights reserved. |
14 | 14 |
|
@@ -427,6 +427,8 @@ def __init__( |
427 | 427 | else: |
428 | 428 | self._getconn = OMCSessionZMQ(omhome=omhome) |
429 | 429 |
|
| 430 | + # get OpenModelica version |
| 431 | + self._version = self.sendExpression("getVersion()", parsed=True) |
430 | 432 | # set commandLineOptions using default values or the user defined list |
431 | 433 | if commandLineOptions is None: |
432 | 434 | # 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 |
996 | 998 |
|
997 | 999 | raise ModelicaSystemError("Unhandled input for getOptimizationOptions()") |
998 | 1000 |
|
| 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 | + |
999 | 1008 | def simulate_cmd( |
1000 | 1009 | self, |
1001 | 1010 | result_file: pathlib.Path, |
@@ -1044,11 +1053,23 @@ def simulate_cmd( |
1044 | 1053 | if self._override_variables or self._simulate_options_override: |
1045 | 1054 | override_file = result_file.parent / f"{result_file.stem}_override.txt" |
1046 | 1055 |
|
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 = ( |
1048 | 1069 | "\n".join([f"{key}={value}" for key, value in self._override_variables.items()]) |
1049 | 1070 | + "\n".join([f"{key}={value}" for key, value in self._simulate_options_override.items()]) |
1050 | 1071 | + "\n" |
1051 | | - ) |
| 1072 | + ) |
1052 | 1073 |
|
1053 | 1074 | override_file.write_text(override_content) |
1054 | 1075 | om_cmd.arg_set(key="overrideFile", val=override_file.as_posix()) |
@@ -1642,15 +1663,32 @@ def linearize( |
1642 | 1663 | timeout=timeout, |
1643 | 1664 | ) |
1644 | 1665 |
|
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) |
1646 | 1684 |
|
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: |
1648 | 1686 | for key1, value1 in self._override_variables.items(): |
1649 | 1687 | fh.write(f"{key1}={value1}\n") |
1650 | 1688 | for key2, value2 in self._linearization_options.items(): |
1651 | 1689 | fh.write(f"{key2}={value2}\n") |
1652 | 1690 |
|
1653 | | - om_cmd.arg_set(key="overrideFile", val=overrideLinearFile.as_posix()) |
| 1691 | + om_cmd.arg_set(key="overrideFile", val=override_file.as_posix()) |
1654 | 1692 |
|
1655 | 1693 | if self._inputs: |
1656 | 1694 | for key in self._inputs: |
|
0 commit comments