cvxopt.solvers.qp in python 导致内核死亡

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

当我尝试使用 python 中的 cvxopt 包中的 solvers.qp 解决二次规划问题时,它会在几秒钟后杀死我的内核。

包的文档位于 http://cvxopt.org/userguide/coneprog.html#cvxopt.solvers.qp。如果我 运行 该页面的示例代码:

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 ]

大约 2 秒后,我从 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.

...

我也不明白这个 ['x'] 选项是什么意思。但即使我不考虑它,它也会让我 'unexpected' 内核死亡。我也尝试了肯定有解决方案的qp问题。就像 x^2+y^2 在没有约束或非负性约束下......无论我做什么,它都会杀死我的内核。可能是什么问题?

也许重要的是,

您可以 运行 来自终端的脚本来获取此错误的原因。

当我收到此错误时,原因是 Intel MKL FATAL ERROR: Cannot load libmkl_avx2.so or libmkl_def.so。 我使用 conda,所以这是我的解决方案:

conda config --add channels conda-forge
conda install -f cvxopt

当我在 Jupyter 实验室 运行 cvxopt 时,我遇到了同样的问题,所以我将我的代码移动到 PyCharm 并得到了一个错误

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.

我用谷歌搜索并发现 a question 通过

解决了它
    import os
    os.environ["KMP_DUPLICATE_LIB_OK"]="TRUE"