Skip to content

Commit 891528c

Browse files
authored
load linearized model directly from file (OpenModelica#213)
1 parent 69a502e commit 891528c

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

OMPython/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ class which means it will use OMCSessionZMQ by default. If you want to use
5555
from collections import OrderedDict
5656
import numpy as np
5757
import pyparsing
58+
import importlib
5859

5960

6061
if sys.platform == 'darwin':
@@ -1766,11 +1767,10 @@ def linearize(self, lintime = None, simflags= None): # 22
17661767
# this function is called from the generated python code linearized_model.py at runtime,
17671768
# to improve the performance by directly reading the matrices A, B, C and D from the julia code and avoid building the linearized modelica model
17681769
try:
1769-
## add the generated linearfile directory to system path, as running from script does not find the module
1770+
## do not add the linearfile directory to path, as multiple execution of linearization will always use the first added path, instead execute the file
17701771
## https://github.com/OpenModelica/OMPython/issues/196
1771-
sys.path.append(os.path.dirname(linearFile))
1772-
from linearized_model import linearized_model
1773-
result = linearized_model()
1772+
module = importlib.machinery.SourceFileLoader("linearized_model", linearFile).load_module()
1773+
result = module.linearized_model()
17741774
(n, m, p, x0, u0, A, B, C, D, stateVars, inputVars, outputVars) = result
17751775
self.linearinputs = inputVars
17761776
self.linearoutputs = outputVars

0 commit comments

Comments
 (0)