Skip to content
Snippets Groups Projects
Commit e330711b authored by Zizhe Wang's avatar Zizhe Wang
Browse files

feat load libraries in orchestration workflow

parent af50fdae
No related branches found
No related tags found
No related merge requests found
......@@ -45,5 +45,11 @@
"PLOT_TITLE": "",
"ENABLE_PLOT": false
},
"LIBRARY_CONFIG": {
"LOAD_LIBRARIES": true,
"LIBRARIES": [
{"name": "PNlib-3.0.0", "path": "PNlib-3.0.0/PNlib/package.mo"}
]
},
"N_JOBS": -1
}
\ No newline at end of file
......@@ -4,6 +4,7 @@
import json
import os
from optimize_main import run_optimization
from OMPython import OMCSessionZMQ
class MOO4ModelicaWrapper:
def __init__(self, orchestration_config_path, config_path):
......@@ -11,6 +12,8 @@ class MOO4ModelicaWrapper:
self.config_path = config_path
self.load_configs()
self.update_config_file()
self.omc = OMCSessionZMQ()
self.load_libraries()
def load_configs(self):
with open(self.orchestration_config_path, 'r') as f:
......@@ -29,6 +32,7 @@ class MOO4ModelicaWrapper:
self.config['OBJECTIVES'] = self.orchestration_config['OBJECTIVES']
self.config['PLOT_CONFIG'] = self.orchestration_config['PLOT_CONFIG']
self.config['N_JOBS'] = self.orchestration_config['N_JOBS']
self.config['LIBRARY_CONFIG'] = self.orchestration_config['LIBRARY_CONFIG']
for key, value in self.orchestration_config['OPTIMIZATION_CONFIG'].items():
self.config['OPTIMIZATION_CONFIG'][key] = value
......@@ -45,6 +49,18 @@ class MOO4ModelicaWrapper:
with open(self.config_path, 'w') as f:
json.dump(self.config, f, indent=4)
def load_libraries(self):
if self.orchestration_config['LIBRARY_CONFIG']['LOAD_LIBRARIES']:
for lib in self.orchestration_config['LIBRARY_CONFIG']['LIBRARIES']:
library_path = os.path.join(os.getcwd(), 'models', lib['path']).replace('\\', '/')
print(f"Loading library: {lib['name']} from {library_path}")
load_library_result = self.omc.sendExpression(f'loadFile("{library_path}")')
print(f"Load library result: {load_library_result}")
if load_library_result is not True:
messages = self.omc.sendExpression("getErrorString()")
print(f"OpenModelica error messages: {messages}")
raise RuntimeError(f"Failed to load library: {lib['name']}")
def run_optimization(self):
run_optimization()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment