Ubuntu20下OpenModelica Buildings模块Python路径配置及加载失败问题
Ubuntu 20系统中OpenModelica调用Python模块模拟失败(退出码255)
在Ubuntu 20系统运行OpenModelica模型时遇到问题:已按官方文档配置PYTHONPATH并安装libpython3.8-dev,但模拟仍失败,退出码为255,提示无法加载指定Python模块,错误信息为"(null)",无法确定是Python代码语法错误还是PYTHONPATH配置问题。以下是相关信息:
错误日志
Simulation process failed. Exited with code 255. > Simulation process failed. Exited with code 255. /tmp/OpenModelica_sigi-laptop/OMEdit/peakShavingPythonModule/peakShavingPythonModule -port=36007 -logFormat=xmltcp -override=startTime=0,stopTime=10,stepSize=1,tolerance=1e-6,solver=dassl,outputFormat=mat,variableFilter=.* -r=/tmp/OpenModelica_sigi-laptop/OMEdit/peakShavingPythonModule/peakShavingPythonModule_res.mat -w -lv=LOG_STATS -inputPath=/tmp/OpenModelica_sigi-laptop/OMEdit/peakShavingPythonModule -outputPath=/tmp/OpenModelica_sigi-laptop/OMEdit/peakShavingPythonModule The initialization finished successfully without homotopy method. Failed to load "/home/sigi-laptop/.openmodelica/libraries/Buildings 9.1.0/Resources/Python-Sources/peak_shaving_no_soc.py". This may occur if you did not set the PYTHONPATH environment variable or if the Python module contains a syntax error. The error message is "(null)"
Modelica代码
model peakShavingPythonModule Buildings.Utilities.IO.Python_3_8.Real_Real peak_shaving_test(functionName = "peak_shaving", moduleName = "/home/sigi-laptop/.openmodelica/libraries/Buildings 9.1.0/Resources/Python-Sources/peak_shaving_no_soc.py", nDblRea = 1, nDblWri = 1, samplePeriod = 1) annotation( Placement(visible = true, transformation(origin = {-14, 30}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); Modelica.Blocks.Sources.CombiTimeTable combiTimeTable(table = [0, 0; 1, 100; 2, -100; 3, 150; 4, -150; 5, 75; 6, 30; 7, 10; 8, -5; 9, -32; 10, 42]) annotation( Placement(visible = true, transformation(origin = {-64, 30}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); equation connect(combiTimeTable.y, peak_shaving_test.uR) annotation( Line(points = {{-52, 30}, {-26, 30}}, color = {0, 0, 127}, thickness = 0.5)); annotation( uses(Buildings(version = "9.1.0"), Modelica(version = "4.0.0")), experiment(StartTime = 0, StopTime = 10, Tolerance = 1e-6, Interval = 1), __OpenModelica_commandLineOptions = "--matchingAlgorithm=PFPlusExt --indexReductionMethod=dynamicStateSelection -d=initialization,NLSanalyticJacobian", __OpenModelica_simulationFlags(lv = "LOG_STATS", s = "dassl", variableFilter = ".*")); end peakShavingPythonModule;
Python代码
保存路径:/home/sigi-laptop/.openmodelica/libraries/Buildings 9.1.0/Resources/Python-Sources
def peak_shaving(net_load): if (net_load <= -15) and (net_load >= -100): ivt_ctrl = abs(net_load + 15) elif (net_load <= -100): ivt_ctrl = 100 elif (net_load >= 0) and (net_load < 100): ivt_ctrl = -1*(net_load); elif (net_load < 100): ivt_ctrl = -100 else: ivt_ctrl = 0 return int(ivt_ctrl)
内容的提问来源于stack exchange,提问作者Luis Enriquez-Contreras
相关产品推荐
相关产品推荐

