kevin-tracy / qpax

Differentiable QP solver in JAX
MIT License
70 stars 6 forks source link

Error solving QP problem without constraints #8

Closed lvjonok closed 1 month ago

lvjonok commented 1 month ago

Hello! I face problem solving QP without constraints at all.

Here is the script to reproduce:

import jax.numpy as np

from qpax import solve_qp

M = np.array([[1.0, 2.0, 0.0], [-8.0, 3.0, 2.0], [0.0, 1.0, 1.0]])
P = np.dot(M.T, M)  # this is a positive definite matrix
q = np.dot(np.array([3.0, 2.0, 3.0]), M).reshape((3,))
A = np.zeros((0, 3))
b = np.zeros((0,))
G = np.zeros((0, 3))
h = np.zeros((0,))

# Solving the QP
x = solve_qp(P, q, A, b, G, h)[0]

# Check that answer is not nan
assert not np.isnan(x).any(), "Solution contains NaN values, expected [-0.64705882, -1.17647059, -1.82352941]"
print(x)
print([-0.64705882, -1.17647059, -1.82352941])
lvjonok commented 1 month ago

Even simpler case could be the following:

import jax.numpy as np

from qpax import solve_qp

P = np.array([5.0])
q = np.array([-5.0])
A = np.zeros((0, 1))
b = np.zeros((0,))
G = np.zeros((0, 1))
h = np.zeros((0,))

# Solving the QP
x = solve_qp(P, q, A, b, G, h)[0]

# Check that answer is not nan
assert not np.isnan(x).any(), "Solution contains NaN values, expected [1.0]"
print(x)
kevin-tracy commented 1 month ago

Same issue as https://github.com/kevin-tracy/qpax/issues/6

kevin-tracy commented 1 month ago

Fixed with https://github.com/kevin-tracy/qpax/commit/2cbd04e984ff30844be3601642240a054b886bac