pythonlinuxanacondacvxopt

cvxopt.solvers.qp in python causes the kernel to die


When I try to solve a quadratic programming problem with solvers.qp from the cvxopt package in python, it kills my kernel after a few seconds.

The documentation of the package is found at http://cvxopt.org/userguide/coneprog.html#cvxopt.solvers.qp . If I run the example code from that page:

from math import sqrt
from cvxopt import matrix
from cvxopt.solvers import qp

# Problem data.
n = 4
S = matrix([[ 4e-2,  6e-3, -4e-3,    0.0 ],
        [ 6e-3,  1e-2,  0.0,     0.0 ],
        [-4e-3,  0.0,   2.5e-3,  0.0 ],
        [ 0.0,   0.0,   0.0,     0.0 ]])
pbar = matrix([.12, .10, .07, .03])
G = matrix(0.0, (n,n))
G[::n+1] = -1.0 
h = matrix(0.0, (n,1))
A = matrix(1.0, (1,n))
b = matrix(1.0)

# Compute trade-off.
N = 100
mus = [ 10**(5.0*t/N-1.0) for t in range(N) ]

portfolios = [ qp(mu*S, -pbar, G, h, A, b)['x'] for mu in mus ]

After 2 seconds or so I get the following reply from python:

It seems the kernel died unexpectedly. Use 'Restart kernel' to continue using this console.

It seems the kernel died unexpectedly. Use 'Restart kernel' to continue using this console.

It seems the kernel died unexpectedly. Use 'Restart kernel' to continue using this console.

...

I also don't understand what this ['x'] option is all about. But even if I leave that away it gives me that 'unexpected' death of the kernel. I also tried qp problems that definitely have a solution. Like x^2+y^2 under no constraints or with non-negativity constraints... what ever I do, it kills my kernel. What could be the problem?

Maybe it is important to say, that


Solution

  • I faced the same problem, when I was running cvxopt in Jupyter Lab, so I moved my code to PyCharm and got an error

    OMP: Error #15: Initializing libiomp5md.dll, but found libiomp5md.dll already initialized.

    OMP: Hint This means that multiple copies of the OpenMP runtime have been linked into the program. That is dangerous, since it can degrade performance or cause incorrect results.

    I googled and found a question that solved it via

        import os
        os.environ["KMP_DUPLICATE_LIB_OK"]="TRUE"