Score:0

How to get pythonpath to work for the python module in openmodelica Buildings running Ubuntu 20

bz flag

I am having problems running my model in openmodelica on Ubuntu 20. I tried exporting the path following the documentation and installed libpython3.8-dev.

https://build.openmodelica.org/Documentation/Buildings.Utilities.IO.Python_3_8.UsersGuide.html

I ran the model, but I am getting this error, but I am not sure if it is my python code or it is something wrong the pythonpath

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)"

My modelica code

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;

My python code (saved to /.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)

Thank you for the help

cc flag
Does the directory/file ... .openmodelica/libraries/Buildings 9.1.0/Resources/Python-Sources/peak_shaving_no_soc.py exist? What is your PYTHONPATH?
Luis Enriquez-Contreras avatar
bz flag
@ubfan1 It does. How would I know what my PYTHONPATH is? What I did is use these two commands: export PYTHONPATH=${PYTHONPATH}:'/home/sigi-laptop/.openmodelica/libraries/Buildings 9.1.0/Resources/Python-Sources' and export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:'/home/sigi-laptop/.openmodelica/libraries/Buildings 9.1.0/Resources/Library/linux64'. The directory where the code is at is: '/home/sigi-laptop/.openmodelica/libraries/Buildings 9.1.0/Resources/Python-Sources'
Score:0
bz flag

I just figured out that I forgot to add an extra parenthesis to my if statements, so it works now (which is weird since I tested it on jupyter before):

def peak_shaving(dblInp):
    [net_load, SOC] = dblInp
    if ((net_load <= -15) and (SOC > 20) and (net_load >= -100)):
        ivt_ctrl = abs(net_load + 15)
    elif ((net_load <= -100) and (SOC > 20)):
        ivt_ctrl = 100
    elif ((net_load >= 0) and (SOC < 90) and (net_load < 100)):
        ivt_ctrl = -1*(net_load);
    elif ((SOC < 90) and (net_load < 100)):
        ivt_ctrl = -100
    else:
        ivt_ctrl = 0
    return int(ivt_ctrl)
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.