Comments (5)
Hi @stribor14 ,
- On which operating system are you experiencing this problem?
- With which osqp/osqp-eigen/Eigen commit?
- With which MATLAB version?
Just a curiosity: do you have a Short, Self Contained and Compilable Example for your problem that you can share?
from osqp-eigen.
- Ubuntu 18.04.2
- osqp is on commit 8949e67
- osqp-eigen is on current master
- Eigen is from 18.04.2 official repo (eigen3 v3.3.4-4)
- Matlab R2019a
Sadly, I cannot share an example, but If I don't figure this out, I'll try to create a new one (which might also help me if I figure out how to produce this behavior)
Tomorrow I'll try running Matlab in gdb and see if there is an infinite loop occurring
from osqp-eigen.
Hi @traversaro ,
I think I found the problem, but I would like your thoughts on it. All matrices I give to update functions are class members variables (not pointers):
solver.updateHessianMatrix(P_);
solver.updateLinearConstraintsMatrix(A_);
solver.updateBounds(lo_bound_, up_bound_);
After debugging, I noticed that Matlab hangs when trying to clean up memory, so I removed P-value delete (intentionally introduced memory leak). Now everything works as intended.
My reasoning is that when I call updateSomeMatrix(Mat)
, osqp-eigen or osqp takes ownership of it and frees that memory before class destructor tries to free the same memory. (#16 )
P.S. This all sounds fishy because Valgrind gives 0 errors and memory leaks with c++ plant. I only have problem with Matlab. So far experience with osqp-eigen is great and straightforward (Kudos!)
from osqp-eigen.
Problem solved :)
In MPC class constructor, I had solver initialization (it should be noted that all of the matrices are initialized but still empty at this point):
solver.settings()->setVerbosity(false);
solver.settings()->setWarmStart(true);
solver.data()->setNumberOfVariables((N__ + 1) * n_x__ + N__ * n_u__);
solver.data()->setNumberOfConstraints(2 * (N__ + 1) * n_x__ + N__ * n_u__);
solver.data()->setHessianMatrix(P_);
solver.data()->setGradient(q_);
solver.data()->setLinearConstraintsMatrix(A_);
solver.data()->setUpperBound(up_bound_);
solver.data()->setLowerBound(lo_bound_);
solver.initSolver();
Then, in function call to get a new solution, I recalculate new matrices and update solver with them:
solver.updateHessianMatrix(P_);
solver.updateLinearConstraintsMatrix(A_);
solver.updateBounds(lo_bound_, up_bound_);
But, when this function is called first time, sparsity pattern changes and osqp-eigen has to create new solver. On all other subsequent calls, it only updates values in osqp (since later sparsity pattern doesn't change). This works without any problem with normal C++ application.
When writing Matlab S-function, this doesn't seem to work, so I tried to avoid creating new solver because of sparsity pattern change. I removed initialization from class constructor to function call after all of the matrices are calculated:
static bool first_pass = true;
if (first_pass)
{
first_pass = false;
solver.settings()->setVerbosity(false);
solver.settings()->setWarmStart(true);
solver.data()->setNumberOfVariables((N__ + 1) * n_x__ + N__ * n_u__);
solver.data()->setNumberOfConstraints(2 * (N__ + 1) * n_x__ + N__ * n_u__);
solver.data()->setHessianMatrix(P_);
solver.data()->setGradient(q_);
solver.data()->setLinearConstraintsMatrix(A_);
solver.data()->setUpperBound(up_bound_);
solver.data()->setLowerBound(lo_bound_);
solver.initSolver();
}
else {
solver.updateHessianMatrix(P_);
solver.updateLinearConstraintsMatrix(A_);
solver.updateBounds(lo_bound_, up_bound_);
}
I doubt that Matlab should crash because of that, maybe this is only a workaround for a bug, but it works.
from osqp-eigen.
Thanks @stribor14 ! Given that you found your solution, I think we can close the issue.
from osqp-eigen.
Related Issues (20)
- Simple question on building and running tests HOT 2
- New release HOT 4
- catkin_make error
- ROS catkin_make HOT 15
- Scheduled CI is failing since December 2022
- A bug happened at the end of MPC example program
- Compilation error:‘csc’ has not been declared HOT 6
- Cannot build osqp-eigen from source HOT 2
- there is a problem when building it HOT 4
- ERROR in LDL_factor: Error in KKT matrix LDL factorization when computing the nonzero elements. The problem seems to be non-convex HOT 2
- problems compiling this library HOT 4
- Assert statement in SparseMatrixHelper.tpp HOT 2
- The createOsqpSparseMatrix does not correctly handle empty sparse matrix. HOT 5
- Compile error on Windows with vs2022 and vs2019 when compiling against osqp master branch (future osqp v1) HOT 8
- The possibility to handle huge matrix equation? HOT 4
- Using OSQP-Eigen with OSQP CUDA HOT 2
- have a solution for osqp 0.4.0? HOT 6
- error while loading shared libraries: libosqp.so HOT 3
- undefined reference to `OsqpEigen::Solver::Solver()',undefined reference to `OsqpEigen::Solver::settings() const' HOT 1
- I'm using osqp-eigen v0.7.0, wondering if Hessian Matrix is supporting only symmetric matrix, rather than upper triangular matrix. HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from osqp-eigen.