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

Could someone kindly explain to me how to use the examples in the “tests”? Thank you. #173

Closed
moonBuff opened this issue Nov 6, 2024 · 8 comments

Comments

@moonBuff
Copy link

moonBuff commented Nov 6, 2024

When I try to use the test cases in the tests folder, I get the error: Unknown CMake command "add_osqpeigen_test". I think I might have done something wrong. Could someone please help me figure it out? Thank you!

@traversaro
Copy link
Member

The files in tests are not examples, but rather tests that are supposed to be compiled and run as part of the osqp-eigen CMake build.

Standalone examples that can be built independently from osqp-eigen can be found in https://github.com/robotology/osqp-eigen/tree/master/example .

@moonBuff
Copy link
Author

moonBuff commented Nov 6, 2024

The files in tests are not examples, but rather tests that are supposed to be compiled and run as part of the osqp-eigen CMake build.

Standalone examples that can be built independently from osqp-eigen can be found in https://github.com/robotology/osqp-eigen/tree/master/example .

I appreciate your prompt response.
I apologize, as I am a beginner and not very familiar with this project, I misunderstood the purpose of these files.
Now I have successfully run the example you pointed out to me.
May I ask you again how to run the tests in the tests folder, which you mentioned should be "run as part of the osqp-eigen CMake build"
I'm sorry for bothering you again.

@traversaro
Copy link
Member

In general, you can compile the project and the tests with this commands on Linux and macOS:

git clone https://github.com/robotology/osqp-eigen
cd osqp-eigen
cmake -Bbuild -S. -DBUILD_TESTING:BOOL=ON
cd build
make
make test

However, you need to make sure that you have all the required depencies (like osqp, eigen and catch2). So to provide an helpful answer, we need to know:

  • On which operating system are you?
  • Which package manager are you using to install C++ dependencies?

@moonBuff
Copy link
Author

moonBuff commented Nov 6, 2024

In general, you can compile the project and the tests with this commands on Linux and macOS:

git clone https://github.com/robotology/osqp-eigen
cd osqp-eigen
cmake -Bbuild -S. -DBUILD_TESTING:BOOL=ON
cd build
make
make test

However, you need to make sure that you have all the required depencies (like osqp, eigen and catch2). So to provide an helpful answer, we need to know:

  • On which operating system are you?
  • Which package manager are you using to install C++ dependencies?

Your assistance has been so prompt that I can hardly express my gratitude. I'm very sorry that I may not be able to respond as quickly as you reply to me. We might be in different time zones,.It’s already quite late here, and I don't want to disturb my roommate as our dorm room is quite small. So I apologize that I might not be able to respond to your help until tomorrow.

What follows might raise your blood pressure, as I am truly a beginner without much understanding. However, by chance, I now find myself needing to work with OSQP-related content.

I'm working in a Windows environment and trying to run this project. My package manager is vcpkg, but it seems that the vcpkg library only contains Catch2 and Eigen3, without support for osqp and osqp-eigen.

As a result, I downloaded osqp and osqp-eigen directly using git clone. To run the MPCExample in osqp-eigen, I configured it in Visual Studio 2022 by going to Project > Properties > VC++ Directories > Library Directories and Include Directories, where I included the paths for the osqp and osqp-eigen repositories I cloned. I then added the .lib files to Linker > Input > Additional Dependencies.

Now, I want to run the tests in the tests folder, but I'm running into issues where vcpkg can't find the manually downloaded osqp and osqp-eigen libraries, even after adding set and find_package statements to the CMakeLists.txt in osqp-eigen.

Since I'm quite new to this, I might be getting things tangled up due to my lack of experience.

I want to thank you once again for your selfless assistance.

@traversaro
Copy link
Member

Your assistance has been so prompt that I can hardly express my gratitude. I'm very sorry that I may not be able to respond as quickly as you reply to me. We might be in different time zones,.It’s already quite late here, and I don't want to disturb my roommate as our dorm room is quite small. So I apologize that I might not be able to respond to your help until tomorrow.

What follows might raise your blood pressure, as I am truly a beginner without much understanding. However, by chance, I now find myself needing to work with OSQP-related content.

No need to worry, really.

If you are working with vcpkg, the following commands should be sufficient to run the tests with vcpkg provided dependencies. First of all, open your "x64 Native Tools command prompt for VS2022" (or VS2019 if using an earlier version).

First of all, create a clean directory called osqpeigenws in your home:

cd %USERPROFILE%
mkdir osqpeigenws

In there, clone vcpkg and install there catch2 and eigen:

cd %USERPROFILE%\osqpeigenws
git clone https://github.com/microsoft/vcpkg
cd vcpkg
.\bootstrap-vcpkg.bat
.\vcpkg.exe install catch2 eigen3

If the installation was successful, go back in osqpeigenws to download and compile osqp and osqp-eigen. We are going to install the libraries in %HOMEPATH%\osqpeigenws\install, and we will add this directory to CMAKE_PREFIX_PATH to ensure that it is found. We are also going to use the branch #171 for osqp-eigen, to have support for a modern catch as the one installed by default by vcpkg:

cd %USERPROFILE%\osqpeigenws
git clone --recursive -b release-0.6.3 https://github.com/osqp/osqp
git clone -b cleanupci https://github.com/robotology/osqp-eigen
cd osqp
cmake -Bbuild -S. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=%USERPROFILE%\osqpeigenws\install
cmake --build ./build --config Release
cmake --install ./build --config Release
cd %USERPROFILE%\osqpeigenws
cd osqp-eigen
cmake -Bbuild -S. -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH==%USERPROFILE%\osqpeigenws\install -DCMAKE_INSTALL_PREFIX=%USERPROFILE%\osqpeigenws -DBUILD_TESTING:BOOL=ON -DCMAKE_TOOLCHAIN_FILE=%USERPROFILE%\osqpeigenws\vcpkg\scripts\buildsystems\vcpkg.cmake
cmake --build ./build --config Release
cmake --install ./build --config Release

At this point, you can run the tests with the ctest command:

cd %USERPROFILE%\osqpeigenws\osqp-eigen\build
ctest -C Release 

If everything works correctly, you should see the tests running with output:

C:\Users\straversaro\osqpeigenws\osqp-eigen\build>ctest -C Release
Test project C:/Users/straversaro/osqpeigenws/osqp-eigen/build
    Start 1: SparseMatrixUnitTests
1/5 Test #1: SparseMatrixUnitTests ............   Passed    0.12 sec
    Start 2: QPUnitTests
2/5 Test #2: QPUnitTests ......................   Passed    0.07 sec
    Start 3: UpdateMatricesUnitTests
3/5 Test #3: UpdateMatricesUnitTests ..........   Passed    0.06 sec
    Start 4: MPCUnitTests
4/5 Test #4: MPCUnitTests .....................   Passed    0.10 sec
    Start 5: MPCUpdateMatricesUnitTests
5/5 Test #5: MPCUpdateMatricesUnitTests .......   Passed    0.09 sec

On a related note, apparently somebody is working on packaging osqp and osqp-eigen on vcpkg, see: microsoft/vcpkg#39629 and microsoft/vcpkg#41676. However, this is not ready at the moment.

@moonBuff
Copy link
Author

moonBuff commented Nov 7, 2024

Your assistance has been so prompt that I can hardly express my gratitude. I'm very sorry that I may not be able to respond as quickly as you reply to me. We might be in different time zones,.It’s already quite late here, and I don't want to disturb my roommate as our dorm room is quite small. So I apologize that I might not be able to respond to your help until tomorrow.
What follows might raise your blood pressure, as I am truly a beginner without much understanding. However, by chance, I now find myself needing to work with OSQP-related content.

No need to worry, really.

If you are working with vcpkg, the following commands should be sufficient to run the tests with vcpkg provided dependencies. First of all, open your "x64 Native Tools command prompt for VS2022" (or VS2019 if using an earlier version).

First of all, create a clean directory called osqpeigenws in your home:

cd %USERPROFILE%
mkdir osqpeigenws

In there, clone vcpkg and install there catch2 and eigen:

cd %USERPROFILE%\osqpeigenws
git clone https://github.com/microsoft/vcpkg
cd vcpkg
.\bootstrap-vcpkg.bat
.\vcpkg.exe install catch2 eigen3

If the installation was successful, go back in osqpeigenws to download and compile osqp and osqp-eigen. We are going to install the libraries in %HOMEPATH%\osqpeigenws\install, and we will add this directory to CMAKE_PREFIX_PATH to ensure that it is found. We are also going to use the branch #171 for osqp-eigen, to have support for a modern catch as the one installed by default by vcpkg:

cd %USERPROFILE%\osqpeigenws
git clone --recursive -b release-0.6.3 https://github.com/osqp/osqp
git clone -b cleanupci https://github.com/robotology/osqp-eigen
cd osqp
cmake -Bbuild -S. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=%USERPROFILE%\osqpeigenws\install
cmake --build ./build --config Release
cmake --install ./build --config Release
cd %USERPROFILE%\osqpeigenws
cd osqp-eigen
cmake -Bbuild -S. -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH==%USERPROFILE%\osqpeigenws\install -DCMAKE_INSTALL_PREFIX=%USERPROFILE%\osqpeigenws -DBUILD_TESTING:BOOL=ON -DCMAKE_TOOLCHAIN_FILE=%USERPROFILE%\osqpeigenws\vcpkg\scripts\buildsystems\vcpkg.cmake
cmake --build ./build --config Release
cmake --install ./build --config Release

At this point, you can run the tests with the ctest command:

cd %USERPROFILE%\osqpeigenws\osqp-eigen\build
ctest -C Release 

If everything works correctly, you should see the tests running with output:

C:\Users\straversaro\osqpeigenws\osqp-eigen\build>ctest -C Release
Test project C:/Users/straversaro/osqpeigenws/osqp-eigen/build
    Start 1: SparseMatrixUnitTests
1/5 Test #1: SparseMatrixUnitTests ............   Passed    0.12 sec
    Start 2: QPUnitTests
2/5 Test #2: QPUnitTests ......................   Passed    0.07 sec
    Start 3: UpdateMatricesUnitTests
3/5 Test #3: UpdateMatricesUnitTests ..........   Passed    0.06 sec
    Start 4: MPCUnitTests
4/5 Test #4: MPCUnitTests .....................   Passed    0.10 sec
    Start 5: MPCUpdateMatricesUnitTests
5/5 Test #5: MPCUpdateMatricesUnitTests .......   Passed    0.09 sec

On a related note, apparently somebody is working on packaging osqp and osqp-eigen on vcpkg, see: microsoft/vcpkg#39629 and microsoft/vcpkg#41676. However, this is not ready at the moment.

I’m incredibly grateful for your help! Thanks to your guidance, I was finally able to run the tests successfully.

For anyone else who may encounter similar issues, I’ll share some of the challenges I faced and my solutions while following the advice. There may even be better approaches, but here’s what worked for me:

  1. vcpkg Root Path Issue:
    Warning: The vcpkg at C:\Users\max\osqpeigenws\vcpkg\vcpkg.exe is using detected vcpkg root C:\Users\max\osqpeigenws\vcpkg and ignoring mismatched VCPKG_ROOT environment value C:\Non_System\Visual Studio\2022\Enterprise\VC\vcpkg.

    I resolved this by specifying the root path directly in the command:

    .\vcpkg.exe --vcpkg-root C:\Users\max\osqpeigenws\vcpkg install catch2 eigen3
  2. CMake Warning about osqp Configuration Files:
    When I ran the following command:

    cmake -Bbuild -S. -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH==%USERPROFILE%\osqpeigenws\install -DCMAKE_INSTALL_PREFIX=%USERPROFILE%\osqpeigenws -DBUILD_TESTING:BOOL=ON -DCMAKE_TOOLCHAIN_FILE=%USERPROFILE%\osqpeigenws\vcpkg\scripts\buildsystems\vcpkg.cmake

    CMake warned me that it couldn’t locate the osqp configuration files (osqpConfig.cmake or osqp-config.cmake). I resolved this by using the following command:

    cmake -Bbuild -S. -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH=%USERPROFILE%\osqpeigenws -DCMAKE_INSTALL_PREFIX=%USERPROFILE%\osqpeigenws -DBUILD_TESTING:BOOL=ON -DCMAKE_TOOLCHAIN_FILE=%USERPROFILE%\osqpeigenws\vcpkg\scripts\buildsystems\vcpkg.cmake
  3. QPUnitTests Did Not Run:
    When testing, QPUnitTests did not execute. I solved this by running:

    cd C:\Users\max\osqpeigenws\osqp-eigen\build
    ctest -C Release --rerun-failed --output-on-failure

After addressing these issues, everything worked as expected. Once again, thank you for your help!

@traversaro
Copy link
Member

@moonBuff I happy you solved your problem. If everything is resolved, feel free to close the issue, thanks!

@moonBuff
Copy link
Author

@moonBuff I happy you solved your problem. If everything is resolved, feel free to close the issue, thanks!

Thank you so much for your help! The issue is resolved now, and I really appreciate your assistance. I will go ahead and close the issue. Thanks again

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

No branches or pull requests

2 participants