diff --git a/src/orchestration_config.json b/src/orchestration_config.json index 77174c8067d7fe4990461c0f3150f0706fea83c0..8b9dacaa4fcb44afa29aadbc74b42f84ee26ba59 100644 --- a/src/orchestration_config.json +++ b/src/orchestration_config.json @@ -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 diff --git a/src/orchestration_wrapper.py b/src/orchestration_wrapper.py index 5531f2bc1e01ac489abb222d229b6b824242f180..aa556c28bea3594f6879cf9169b7ee3b6f1c2c78 100644 --- a/src/orchestration_wrapper.py +++ b/src/orchestration_wrapper.py @@ -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()