segmenation fault when running cvxpy in modelica buildings python module

asked 2023-08-04 22:55:26 -0500

grid_designer's avatar

updated 2023-08-06 18:36:58 -0500

Hello all,

I am not sure if this is a CVXPy, modelica, python, or maybe even a C problem (I believe CVXPy and/or the SCS solver calls functions written in C). I am simulating a microgrid using openmodelica that has a python module that calls a CVXPy function as a control algorithm. I tested the function using Python 3.8(modelica buildings does not use newer versions of python) and it runs without error, however when I run it in openmodelica I get a segmentation fault, and then it crashes. Is there a way to adjust memory in openmodelica, or what else may be causing the error? Note: For the optimization to work it needs to gather data from the modelica for the first 96 iterations, it is not until the 97th iteration when the modelica optimizer is called, and it runs fine. Both the modelica and CVXPy work independently, I only see the problem when Modelica tries to run CVXPy.

Python function test:

Input:

for i in range(100):
    tou_cvx_one_day([abs(df.building_load[i]), abs(df.solar[i]), 0.5, i * 900])

Output:

===============================================================================
                                     CVXPY                                     
                                     v1.3.1                                    
===============================================================================
(CVXPY) Aug 01 02:03:02 PM: Your problem has 480 variables, 960 constraints, and 0 parameters.
(CVXPY) Aug 01 02:03:02 PM: It is compliant with the following grammars: DCP, DQCP
(CVXPY) Aug 01 02:03:02 PM: (If you need to solve this problem multiple times, but with different data, consider using parameters.)
(CVXPY) Aug 01 02:03:02 PM: CVXPY will first compile your problem; then, it will invoke a numerical solver to obtain a solution.
-------------------------------------------------------------------------------
                                  Compilation                                  
-------------------------------------------------------------------------------
(CVXPY) Aug 01 02:03:02 PM: Compiling problem (target solver=SCS).
(CVXPY) Aug 01 02:03:02 PM: Reduction chain: Dcp2Cone -> CvxAttr2Constr -> ConeMatrixStuffing -> SCS
(CVXPY) Aug 01 02:03:02 PM: Applying reduction Dcp2Cone
(CVXPY) Aug 01 02:03:02 PM: Applying reduction CvxAttr2Constr
(CVXPY) Aug 01 02:03:02 PM: Applying reduction ConeMatrixStuffing
(CVXPY) Aug 01 02:03:03 PM: Applying reduction SCS
(CVXPY) Aug 01 02:03:03 PM: Finished problem compilation (took 5.538e-01 seconds).
-------------------------------------------------------------------------------
                                Numerical solver                               
-------------------------------------------------------------------------------
(CVXPY) Aug 01 02:03:03 PM: Invoking solver SCS  to obtain a solution.
------------------------------------------------------------------
           SCS v3.2.3 - Splitting Conic Solver
    (c) Brendan O Donoghue, Stanford University, 2012
------------------------------------------------------------------
problem:  variables n: 483, constraints m: 1248
cones:    z: primal zero / dual free vars: 288
      l: linear vars: 960
settings: eps_abs: 1.0e-05, eps_rel: 1.0e-05, eps_infeas: 1.0e-07
      alpha: 1.50, scale: 1.00e-01, adaptive_scale: 1
      max_iters: 100000, normalize: 1, rho_x: 1.00e-06
      acceleration_lookback: 10, acceleration_interval: 10
lin-sys:  sparse-direct-amd-qdldl
      nnz(A): 1917, nnz(P): 0
------------------------------------------------------------------
 iter | pri res | dua res |   gap   |   obj   |  scale  | time (s)
------------------------------------------------------------------
     0| 4.50e+02  1.96e+01  2.85e+03  1.43e+03  1.00e-01  1.59e-02 
   250| 4.05e-01  6.32e-03  1.90e+00 -1.81e+01  9.53e-03  2.55e-02 
   500| 2.89e-01  3.57e-03  1.79e+00 -1.95e+01  9.53e-03  3.37e-02 
   750| 1.07e-01  2.15e-03 ...
(more)
edit retag flag offensive close merge delete