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

Add Ceres Solver #10

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from
Draft

Add Ceres Solver #10

wants to merge 12 commits into from

Conversation

simon-wacker
Copy link

@simon-wacker simon-wacker commented Feb 2, 2024

Ceres Solver is a large scale non-linear optimization library. It's documented and versioned.

It comes with its own system dependencies that are partly added as external projects with CMake and you can install the ones that are not on Debian-base Linux distributions with

sudo apt-get install libatlas-base-dev # Use ATLAS for BLAS & LAPACK
sudo apt-get install libsuitesparse-dev # SuiteSparse (optional)

I updated the getting started wiki entry accordingly.

Note that I had to patch GFlags with https://github.com/ise-bipv/Windows-CalcEngine/pull/10/files#diff-eca6055ba39d4288773ba85b17d27e756d0eb1bff21c7456fa41de77797fa674 to add it as external project. This patch may become obsolete or may need to be updated in new versions of GFlags

To-Dos:


For the final setup and understanding cmake I took inspiration and learned from


Note that this merge request has the fork as target and that there is another merge request of this branch into the LBNL code base. We need this merge request to talk about changes and ask for ISE-internal reviews. We cannot do so in the other merge request because we are not members of LBNL.

@simon-wacker
Copy link
Author

simon-wacker commented Feb 2, 2024

@vidanovic I tried to add Ceres Solver with ExternalProject_Add and the cmake argument DBUILD_TESTING=OFF. However, running cmake .. within the build directory, fails with the error

Make Error at build/ceres-solver-src/internal/ceres/CMakeLists.txt:401 (add_library):
  add_library cannot create target "gtest" because another target with the
  same name already exists.  The existing target is a static library created
  in source directory
  "/home/simon/Projects/Windows-CalcEngine/build/googletest-src/googletest".
  See documentation for policy CMP0002 for more details.

I tried to figure out whether the argument DBUILD_TESTING=OFF is passed to Ceres Solver with various cmake debugging arguments (namely -Wdev, --log-level=TRACE, --log-context, --debug-output, and --trace) but didn't succeed. I also used the cmake debugger integration in Visual Studio Code. I suppose it's an easy issue to resolve but I'm floating here with my lack of experience with cmake. Can you shed some light on this issue?

I also would be thankful if you shared how you integrated eigen. You mentioned that you did that in LBNL-ETA#172 (comment)

@vidanovic
Copy link
Collaborator

@simon-wacker No much an expert in CMake either :)
Try renaming variable DBUILD_TESTING in WinCalc-Engine repo and see what is going to happen. Keep in mind that there are some files with cmake extension in cmake folder and you would probably need to extend it there as well. I have given you access to HygroThermFEM repository so you can check there. I only used matrices multiplications but not the solver itself. Tried to use SUNDIALS solver in HygroThermFEM as well, but it did not help with convergence so I removed it.
Please let me know how it goes with Ceres solver and WCE. It is hard to say what is going to happen. I have spent about a day in attempt to detect what is causing the problem with high speed airflow and could not find an easy solution. It was indeed problem with iterations.
Also, one thing to try is to change relaxation parameters in current iterations solver:

namespace IterationConstants
{
const double RELAXATION_PARAMETER_MAX = 0.65;
const double RELAXATION_PARAMETER_MIN = 0.05;
const double RELAXATION_PARAMETER_STEP = 0.05;
const double CONVERGENCE_TOLERANCE = 1e-8;
const size_t NUMBER_OF_STEPS = 200;
const double RELAXATION_PARAMETER_AIRFLOW = 0.9;
const double RELAXATION_PARAMETER_AIRFLOW_MIN = 0.1;
const double RELAXATION_PARAMETER_AIRFLOW_STEP = 0.1;
const double CONVERGENCE_TOLERANCE_AIRFLOW = 1e-6;
} // namespace IterationConstants

I did not have time to try that, but it would be an interesting attempt.
Also, please note that I have two iterations withing WCE. One is external for the entire system and the other one internal for the airflow. The problem occurs in the external equations but it could be as well the problem with some of the internal equations.
Hope this helps.

@simon-wacker simon-wacker force-pushed the add-ceres-solver branch 2 times, most recently from 4ddc9d7 to 6af4d5b Compare February 5, 2024 14:43
@simon-wacker
Copy link
Author

@christoph-maurer Ceres solver is now usable on Ubuntu within the Tarcog project. I added a simple prove of concept test CeresSolver.cpp. It should run without ATLAS installed. However, if that is not the case on your machine, then install it with

sudo apt-get install libatlas-base-dev # Use ATLAS for BLAS & LAPACK

If you want to work with it, I suggest that you drop the branch add-ceres-solver on your machine with git branch -D add-ceres-solver (if it exists there), fetch the latest one with git fetch -p, checkout the branch with git checkout add-ceres-solver, and branch-of this branch with git checkout -b your-new-feature.

I still want to do some cleaning-up in the add-ceres-solver branch, which I need to postpone for about 2 months. We can later rebase your feature branch on top of the cleaned-up version of add-ceres-solver.

@vidanovic Thank you for your help.

@simon-wacker
Copy link
Author

@christoph-maurer And if building fails for some reason, you may also need to clean-up your build directory; maybe with rm -rf ./build/*.

@christoph-maurer
Copy link

@simon-wacker Great! Thank you!

@simon-wacker simon-wacker marked this pull request as draft August 6, 2024 14:31
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