gpt4 book ai didi

python - python 中的 cvxopt.solvers.qp 导致内核死亡

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:21:41 24 4
gpt4 key购买 nike

当我尝试使用 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'] 选项是什么意思。但即使我不考虑它,它也会给我内核的“意外”死亡。我也尝试了肯定有解决方案的qp问题。就像 x^2+y^2 在没有约束或非负性约束下......无论我做什么,它都会杀死我的内核。可能是什么问题?

也许重要的是,那

  • 我使用 Ubuntu 16
  • 我使用 Python 3.5
  • 我使用 cvxopt 1.1.9
  • cvxopt 包也使用 C 文件。

最佳答案

我在 Jupyter Lab 中运行 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"

关于python - python 中的 cvxopt.solvers.qp 导致内核死亡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41880144/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com