8000 Work on sensitivity solver: add `setup_qp_matrices_and_factorize` and more by FreyJo · Pull Request #1432 · acados/acados · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Work on sensitivity solver: add setup_qp_matrices_and_factorize and more #1432

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

Merged
merged 47 commits into from
Feb 11, 2025

Conversation

FreyJo
Copy link
Member
@FreyJo FreyJo commented Feb 7, 2025

Added setup_qp_matrices_and_factorize():

This function sets up the QP and factorizes Hessian matrix.

The current NLP iterate is used to setup the QP iterate, which includes t-slacks.
The t and lambda values are clipped according to `solution_sens_qp_t_lam_min` to avoid ill-conditioning.
Then the Hessian matrix is factorized.

If a two-solver approach is used to obtain solution sensitivities from acados, this function should be called before calling `eval_solution_sensitivity`, or `eval_adjoint_solution_sensitivity()`.

This is only implemented for HPIPM QP solver without condensing.

Key differences of using setup_qp_matrices_and_factorize() vs. solve() in the two-solver approach:

  • The QP solver does not need to perform multiple IP iterations to converge and only a single Riccati factorization is performed at the current iterate.
  • In the chain example this reduces the "Median time to factorize exact Hessian QP:" 450.000 ms to 117.000 ms -> roughly 4x faster 🚀
  • In the solve()-approach, the Riccati factorization at the second last QP iterate is used, as the system is not factorized at the final QP iterate. However, for the final iterate the system of equations becomes typically ill-conditioned, which is why the final iterate is modified, by clipping the inequality multipliers and t slacks, see option solution_sens_qp_t_lam_min.
  • Less options that have to be set. The options that were needed to use the solve approach are now commented:
        # Old settings needed, when calling solve() instead of setup_qp_matrices_and_factorize()
        # ocp.solver_options.globalization_fixed_step_length = 0.0 # to not perfrom an SQP step update
        # ocp.solver_options.nlp_solver_max_iter = 1
        # ocp.solver_options.qp_solver_iter_max = 200
        # ocp.solver_options.tol = 1e-10  # to "force" a QP solve

How it works

The option update_fact_exit was added in HPIPM. This option being active, plus the warm start, plus limiting the QP solver iterations to 0, results in the correct behavior.

Other things that changed in this PR

@FreyJo FreyJo changed the title Work on sensitivity solver Work on sensitivity solver: add setup_qp_matrices_and_factorize and more Feb 10, 2025
@FreyJo FreyJo marked this pull request as ready for review February 10, 2025 12:27
@FreyJo FreyJo requested a review from sandmaennchen February 10, 2025 12:27
@sandmaennchen
Copy link
Contributor

Maybe add to the description what the option update_fact_exit does?

@FreyJo
Copy link
Member Author
FreyJo commented Feb 10, 2025

Maybe add to the description what the option update_fact_exit does?

It is mentioned under "How it works" in the PR description.
I addressed all other comments. Thanks for the quick review 🙏

@giaf
Copy link
Collaborator
giaf commented Feb 11, 2025

I see the point of having a separate function for the second solve, mainly to hide details of the second solver setup to the user.
But I'm not too convinced about the name setup_qp_matrices_and_factorize.
What about something like hotstart_and_factorize_kkt, IMO it tells more about the key point: this second solver is hotstarted at the provided solution guess (no iterations are performed), and the KKT system is factorized at that point, so ready to be used for e.g. sensitivity (or also Riccati feedback matrices) computations.

@giaf
Copy link
Collaborator
giaf commented Feb 11, 2025

In HPIPM I added lam0_min and t0_min (with setters and getters) for use only in variables initialization giaf/hpipm@f5ca1ca .
So you should now use these ones instead of lam_min and t_min.
You can use the getters to have local copies of these values before you overwrite them.
Getters for additional opts can be easily added.

@FreyJo
Copy link
Member Author
FreyJo commented Feb 11, 2025

I see the point of having a separate function for the second solve, mainly to hide details of the second solver setup to the user.

Another reason that solve() might exit without a factorization, see #912

I much prefer the name setup_qp_matrices_and_factorize to hotstart_and_factorize_kkt, as creating the QP with an exact Hessian is the more computationally expensive step compared to initializing the QP solver.
In the end, not all details of the function are in the function name, but the docstring describes also the hotstart with the modified iterate.
Also, hotstart does more suggest that some iterations are happening, which they are not in this routine as you wrote.

Regarding the option getters. Since you both mentioned it, and @giaf implemented in HPIPM, I will follow up in this PR accordingly.

@FreyJo
Copy link
Member Author
FreyJo commented Feb 11, 2025

I will make a separate PR for the option cleanup, since it contains a lot of boilerplate code.

@FreyJo FreyJo merged commit 0de2115 into acados:main Feb 11, 2025
14 checks passed
@FreyJo FreyJo deleted the hp_sens branch February 11, 2025 13:16
FreyJo added a commit that referenced this pull request Feb 11, 2025
FreyJo added a commit to leap-c/leap-c that referenced this pull request Feb 28, 2025
FreyJo added a commit to leap-c/leap-c that referenced this pull request Feb 28, 2025
…sensitivity solver (#19)

- Requires less options for sensitivity solver
- Faster, as only one factorization is done in the sensitivity solver
- updated acados submodule
See acados/acados#1432

---------

Co-authored-by: Confectio <leonard.fichtner@gmail.com>
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
0