Question about osqp_update_data_mat
behavior when supplying matrix indices in CSC form
#704
Replies: 2 comments 1 reply
-
It is hard to say without seeing an example, but the first things I would check are:
Does specification of a complete index vector cause failures when done for just one of |
Beta Was this translation helpful? Give feedback.
-
Dear @goulart-paul and all potentially interested developers and users, I conducted further investigation and found that updating
Summary of findings
import numpy as np
import scipy.sparse as sp
# Some dense symmetric matrices
# P = ....
# Convert to CSC form
P_csc = sp.csc_matrix(np.triu(P))
# Write header files for C++
cpp_data = "// Custom member variables for QSQP solver\n\n"
cpp_data += f"OSQPFloat m_P_x[{P_sp.nnz}] = {{{', '.join(map(str, P_sp.data.tolist()))}}};\n"
cpp_data += f"OSQPInt m_P_nnz = {P_sp.nnz};\n"
cpp_data += f"OSQPInt m_P_i[{P_sp.nnz}] = {{{', '.join(map(str, P_sp.indices.tolist()))}}};\n"
cpp_data += f"OSQPInt m_P_p[{P_sp.indptr.size}] = {{{', '.join(map(str, P_sp.indptr.tolist()))}}};\n\n"
with open(filename, 'w') as f:
f.write(cpp_data)
Segmentation fault (core dumped)
iter objective prim res dual res gap rel kkt rho time
1 0.0000e+00 0.00e+00 0.00e+00 0.00e+00 0.00e+00 1.00e-01 1.54e-05s
25 0.0000e+00 0.00e+00 0.00e+00 0.00e+00 0.00e+00 1.00e-01 1.38e-04s
status: solved
solution polishing: unsuccessful
number of iterations: 25
optimal objective: 0.0000
dual objective: -0.0000
duality gap: 0.0000e+00
primal-dual integral: 0.0000e+00
run time: 3.05e-04s
optimal rho estimate: 1.00e-06
MPC solution: 0
Segmentation fault (core dumped)
// Case 1 : Update both P and A matrix → Fails
m_exitflag = osqp_update_data_mat(m_solver, m_P_x, m_P_i, m_P_nnz, m_A_x,
m_A_i, m_A_nnz);
// Case 2: Updating only P → Still fails
m_exitflag = osqp_update_data_mat(m_solver, m_P_x, m_P_i, m_P_nnz,
OSQP_NULL,
OSQP_NULL, OSQP_NULL);
// Case 3: Updating only A → Succeeds
m_exitflag = osqp_update_data_mat(m_solver, OSQP_NULL, OSQP_NULL,
OSQP_NULL,
m_A_x, m_A_i, m_A_nnz);
// Case 4: Using OSQP_NULL to force full update → Succeeds
m_exitflag = osqp_update_data_mat(m_solver, m_P_x, OSQP_NULL, m_P_nnz, m_A_x,
OSQP_NULL, m_A_nnz);
// Case 5: Setting m_P_i[i] = i to force a full update of P → Succeeds
for (int i = 0; i < m_P_nnz; i++) {
m_P_i[i] = i;
}
m_exitflag = osqp_update_data_mat(m_solver, m_P_x, m_P_i, m_P_nnz, m_A_x,
m_A_i, m_A_nnz); I hope these tests could help identify the cause of this behavior. Please let me know if further testing is needed—I’d be happy to assist. |
Beta Was this translation helpful? Give feedback.
-
Dear OSQP developers,
We are implementing our MPC on an embedded system and using
osqp_update_data_mat
to update the problem matrices. We observed that when supplying CSC-form indices along with the updated values, the solver fails to solve the MPC problem (control input jumps to bound values), even if we use the same data and indices as before. Specifically:Notably, we also used
P_i_old
andA_i_old
during the initial setup, and the solver worked fine in that case. This suggests that even if we intend to update only the matrix values, supplying the same indices as in the setup might be affecting the behavior.We noticed that the supplied indices are used by
OSQPMatrix_update_values
after unscaling the solver in osqp/src/osqp_api.c:1138 Could you provide any insights into why this might be happening? Are there any specific constraints or considerations when updating matrices with indices?Beta Was this translation helpful? Give feedback.
All reactions