qpth
qpth copied to clipboard
torch.eig is deprecated for a long time and is being removed
PyTorch's torch.eig was deprecated since version 1.9 and is being removed by https://github.com/pytorch/pytorch/pull/70982. Please use the torch.linalg.eig function instead if you want your code to continue to work with the latest PyTorch.
Affected file: https://github.com/locuslab/qpth/blob/bc121d59802d43fc6cbd685959e9156030dc1baf/qpth/qp.py#L83
FWIW, if you want to check that a matrix is SPD, as you're doing in that test, you should check that A = A.mT and then that linalg.eigvalsh(A) (perhaps with some tolerance)
Also, note that linalg.eigvalsh supports batches (as all the linalg functions do) so you can remove the for loop, which should make this function much more efficient.
Taking the advice of @lezcano, I simply had to replace the following lines of code
if check_Q_spd:
for i in range(nBatch):
e, _ = torch.eig(Q[i])
if not torch.all(e[:,0] > 0):
raise RuntimeError('Q is not SPD.')
with
if check_Q_spd:
e, _ = torch.linalg.eig(Q)
if not torch.all(e.real > 0):
raise RuntimeError('Q is not SPD.')
FYI, I am using torch == 1.13.1.
Thanks all! I've merged in #48 with this update
That check does not check that a matrix is SPD, as the matrix may not even be symmetric.
When looking closer at what you want to do, actually the best way of doing that would be yo try to perform a cholesky decomposition on it, and seeing if it succeeds.
Thanks @lezcano! I just switched to trying a Cholesky to check if it's SPD: https://github.com/locuslab/qpth/commit/97b1f98794d95902411308c14d1726d826f20d9e
LGTM!