Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore compatibility with osqp version 0.6.0 #32

Merged
merged 3 commits into from
Sep 24, 2019
Merged

Conversation

GiulioRomualdi
Copy link
Member

This PR restore the compatibility with osqp version 0.6.0.
When this PR is merged, it will be not possible to use osqp 0.5.0 along with osqp-eigen. Indeed osqp/osqp@78d1135 changes osqp_setup() interface. This problem should be taken into account since a custom version of osqp may be used by internal projects (e.g. https://github.com/robotology-dependencies/osqp/tree/fix-lf-problems)

See #31

@@ -32,7 +32,9 @@ bool OsqpEigen::Data::setHessianMatrix(const Eigen::SparseMatrix<T> &hessianMatr
}

//set the hessian matrix
if(!OsqpEigen::SparseMatrixHelper::createOsqpSparseMatrix(hessianMatrix, m_data->P)){
// osqp 0.6.0 required only the upper triangular part of the hessian matrix
Eigen::SparseMatrix<T> hessianMatrixUpperTriangular = hessianMatrix.template triangularView<Eigen::Upper>();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this method allocating memory?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. Could we move this to be a buffer in the class, or we can't because the method is templated?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it allocates memory

Copy link
Collaborator

@S-Dafarra S-Dafarra Sep 9, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest to keep a copy of the hessian and iterate over the upper triangular non-zeros of the input hessian. In case an element is already present you can copy the value, otherwise you add it. The problem is if the saved hessian has more non-zeros than the input hessian.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is called only the first time.
Probably there is a way to avoid to allocate memory

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In which sense "only the first time"? It is not called every time the hessian changes?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, the function called every time the hessian changes is

bool OsqpEigen::Solver::updateHessianMatrix(const Eigen::SparseCompressedBase<Derived> &hessianMatrix)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, sorry. Then it makes sense.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought as well it was called every time. So there are no problems I guess.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, it is not easy to extract the upper triangular matrix from a CSC representation (representation used by osqp). Furthermore, the methods used to retrieve the outerIndexPtr and the innerIndexPtr are defined in Eigen::SparseCompressedBase and the
Eigen::TriangularView class does not inherit from Eigen::SparseCompressedBase.

This is the reason why the following line is needed

Eigen::SparseMatrix<T> hessianMatrixUpperTriangular = hessianMatrix.template triangularView<Eigen::Upper>();

@traversaro
Copy link
Member

Some small suggestions (not directly related to this PR, to be honest):

  • Could you tag and release the last commit before the PR? It will be the last one compatible with osqp 0.5, and it contains a single commit, but quite important w.r.t. to relese 0.3.0 .
  • I would increase the CMake version, either in this PR or in a later commit.
  • Do you think it could make sense to mantain a table in the docs to document the relative compatibility between osqp and osqp-eigen version? Something like:
osqp-eigen version osqp version
0.3 Compatible with osqp <= 0.5
0.4 Compatible with osqp >= 0.6

@GiulioRomualdi
Copy link
Member Author

cc @traversaro

Some small suggestions (not directly related to this PR, to be honest):

  • Could you tag and release the last commit before the PR? It will be the last one compatible with osqp 0.5, and it contains a single commit, but quite important w.r.t. to relese 0.3.0 .
  • I would increase the CMake version, either in this PR or in a later commit.
  • Do you think it could make sense to mantain a table in the docs to document the relative compatibility between osqp and osqp-eigen version? Something like:

osqp-eigen version osqp version
0.3 Compatible with osqp <= 0.5
0.4 Compatible with osqp >= 0.6

Actually 0.3 is the current version of master while 0.4 is the version in devel. Probably before merging the PR I should merge devel into master
By the way, as far as I understood is not possible to check the installed version of osqp from CMake

@traversaro
Copy link
Member

By the way, as far as I understood is not possible to check the installed version of osqp from CMake

Upstream issue on this: osqp/osqp#195 .

Actually 0.3 is the current version of master while 0.4 is the version in devel. Probably before merging the PR I should merge devel into master

Mhh, good to know. independentily on what 0.3 or 0.4 are compatible with, such as table would help. Anyhow, considering that devel branch was never released, you can also merge the 0.6-compatibility in master, and then forward merge to devel.

@GiulioRomualdi
Copy link
Member Author

Mhh, good to know. independentily on what 0.3 or 0.4 are compatible with, such as table would help. Anyhow, considering that devel branch was never released, you can also merge the 0.6-compatibility in master, and then forward merge to devel.

I don't know if this is a good idea. Right now the devel branch ensures back compatibility with master. In details, devel deprecate some functions defined in master.

On the other hand, when this PR will be merged the back-compatibility with a previous version of osqp will be broken. And I'm afraid that it will create problems -- see https://github.com/robotology-dependencies/osqp/tree/fix-lf-problems.

So to overcome possible issues, I would suggest to:

  1. Merge devel into master
  2. Merge this PR in devel (And probably change the version number from 0.4 to 0.4.1)
  3. Because of Export osqp version with CMake configuration files osqp/osqp#195, it is not possible to check the version of osqp directly from CMake. Thus I will update the README.md describing the current status of osqp-eigen
  4. As soon as Use latest tagged version of upstream osqp and osqp-eigen instead of local fork robotology-superbuild#242 will be fixed, devel will be merged into master

What do you think @traversaro @S-Dafarra?

@traversaro
Copy link
Member

As soon as robotology/robotology-superbuild#242 will be fixed, devel will be merged into master

We can fix immediately the version of osqp-eigen in the superbuild, so that you are free to work as you prefer, and we update the osqp and osqp-eigen version when dust has setted .

@traversaro
Copy link
Member

Merge this PR in devel (And probably change the version number from 0.4 to 0.4.1)

To be honest, I think that if the required version of osqp changes, it is better to at least bump the minor version.

@GiulioRomualdi
Copy link
Member Author

GiulioRomualdi commented Sep 23, 2019

I'm updating the version from 0.4.1 to 0.5.0, at the same time I would like also to change the compatibility from AnyNewerVersion to SameMinorVersion

 include(InstallBasicPackageFiles)
 install_basic_package_files(${PROJECT_NAME}
   VERSION ${${PROJECT_NAME}_VERSION}
-  COMPATIBILITY AnyNewerVersion
+  COMPATIBILITY SameMinorVersion
   VARS_PREFIX ${PROJECT_NAME}
   NO_CHECK_REQUIRED_COMPONENTS_MACRO
   CONFIG_TEMPLATE ${CMAKE_SOURCE_DIR}/cmake/OsqpEigenConfig.cmake.in)

Unfortunately, this option is available only from cmake v3.11 and Ubuntu 18.04 supports at most cmake v3.10. @traversaro, do you know if there is a workaround that can be used?

@traversaro
Copy link
Member

@traversaro, do you know if there is a workaround that can be used?

You can just vendor WriteBasicConfigVersionFile and its included files BasicConfigVersion-***.cmake.in in your project, it should work fine (I guess).

@traversaro
Copy link
Member

You can just vendor WriteBasicConfigVersionFile and its included files BasicConfigVersion-***.cmake.in in your project, it should work fine (I guess).

Note that you will need to copy just the BasicConfigVersion-***.cmake.in that you use, and you need to modify the ${CMAKE_ROOT} in https://github.com/Kitware/CMake/blob/master/Modules/WriteBasicConfigVersionFile.cmake#L36 to ${CMAKE_CURRENT_LIST_DIR}.

- upload a custom version of BasicConfigVersion-SameMinorVersion.cmake.in and WriteBasicConfigVersionFile.cmake to guarantee compatibility with cmake < 3.11
- compatibility ensured only if the required version is 0.5.*
@GiulioRomualdi
Copy link
Member Author

@traversaro

You can just vendor WriteBasicConfigVersionFile and its included files BasicConfigVersion-***.cmake.in in your project, it should work fine (I guess).

Note that you will need to copy just the BasicConfigVersion-***.cmake.in that you use, and you need to modify the ${CMAKE_ROOT} in https://github.com/Kitware/CMake/blob/master/Modules/WriteBasicConfigVersionFile.cmake#L36 to ${CMAKE_CURRENT_LIST_DIR}.

Done in ac2a551

@GiulioRomualdi
Copy link
Member Author

This PR is currently blocked by robotology/robotology-superbuild#260

@GiulioRomualdi GiulioRomualdi merged commit c469a83 into master Sep 24, 2019
@GiulioRomualdi GiulioRomualdi deleted the fix/osqp_0.6.0 branch September 24, 2019 09:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants