Repository navigation
Eliminate the equality constraints of a problem with a factored Hessian - #211
Conversation
A problem whose Hessian is given by its Cholesky factor (problem_type 2) was never reduced. The reduction now uses the factor R of H = R'R: - The factor of the reduced Hessian Z'HZ = (RZ)'(RZ) is formed by a Householder QR factorization of RZ (eq_chol_factored), which forms neither H nor Z'HZ and does not square the condition number. Its pivots are tested as in eq_chol; a singular Z'HZ is formed from the factor and posed as DAQP_EQ_PATH_QP, as for an unfactored Hessian. - The identity of DAQP_EQ_PATH_LDP is passed as a factor, so that the reduced problem is not regularized, as a factored Hessian is not (daqp_update_R, daqp_finish_Rinv). The conditioning check after the factorization is not applied to a factored Hessian for the same reason. - H x is formed as R'(R x), and a diagonal factor is used as a metric. The Eigen test 21_eq_reduction_factored and a Julia test compare the factored reduction with the reduction of the Hessian and with the solve without the reduction (dependent equalities, equalities that determine x, a diagonal factor, a singular reduced Hessian, binary variables, eps_prox > 0, and updates of the bounds and of f). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CogBfu3Xrhk7eUcMoX8BVT
Form Z'HZ = (RZ)'(RZ) and reuse the existing Cholesky, conditioning check and path selection, instead of a separate QR factorization of RZ. The reduced problem is posed with an unfactored Hessian (problem_type 0), as for the reduction of H, which removes the special cases for a factored reduced problem. Cut the test down to the cases that exercise the new code (dense and diagonal factor, equalities that determine x, updates of the bounds and f), and drop the Julia testset, which duplicated it.
|
Simplified the logic a bit. The price is that we form the reduced Hessian instead of just a reduced factor. I made the call to do that to keep the code more maintainable. Let me know if you agree, or want us to revert to the more advanced option. |
…m#213 and darnstrom#214 The tree is that of master 3709fd2 with darnstrom#208 (ad267d9), darnstrom#210 (88f9fbe) and darnstrom#211 (3fb7d78, with the simplification of darnstrom) merged, and the fork-only change that takes the C sources of the code generation from the DAQP_jll artifact. The previous merges of darnstrom#207 and darnstrom#209 are replaced: darnstrom#207 is merged upstream in its revised form (exit flag 5 DAQP_EXIT_FEASIBLE, no DAQP_EXIT_CUTOFF), and darnstrom#209 is superseded by darnstrom#214, after which fval_bound refers to the reported objective. The C++ tests 21_bnb_update_binaries (darnstrom#208) and 21_eq_reduction_factored (darnstrom#211) are renumbered to 22 and 23. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CogBfu3Xrhk7eUcMoX8BVT
|
Agreed, the simplified version is preferable. We compared both versions on dense factored problems (n = 40, 16 equalities, 20 inequalities, cond(R) from 1e1 to 1e7): the objective values agree to about 1e-8 relative, and we found no case in which the QR factorization of RZ gave a more accurate solution. On our house MPC (827 variables, 97 equalities eliminated) the closed loop and the solve times are the same with both versions. One observation: |
|
Right, I have fixed such that `nc is counted correctly when a factor is provided. |
@baggepinnen, for review before this is marked ready.
Goal
A problem whose Hessian is given by its Cholesky factor (
problem_type2, for exampleDAQPBase.setup(model, cholesky(H), ...)) is never reduced by the equality elimination:daqp_eq_wantedreturns 0 for it with every policy. LinearMPC 0.11 passes DAQP the factor of the condensed Hessian, since the factor, which it forms by a QR factorization of a stacked square root, is more accurate than H. For the mixed-integer QP of darnstrom/daqp#205 (919 variables of which 14 binary, 4430 constraints, 195 equality and 762 soft constraints), the branch and bound with the reduction takes about two thirds of the time without it (77 s against 117 to 124 s, table below), and this is not available with the factor.The goal is that a problem with a factored Hessian is reduced under the same conditions as one with an unfactored Hessian (
eq_reduction = 1, or0where the existing heuristics reduce), with the reduction formed from the factor and without forming H.Change
a6feca0, all in
src/eq_elim.c. For H = R'R, with R upper triangular and packed by rows as forproblem_type2:daqp_eq_wantedno longer excludesproblem_type2 (L436-L449).eq_chol_factored(L660-L704) forms L with L L' = Z'HZ = (RZ)'(RZ) by a Householder QR factorization of RZ, left-looking in panels of four columns witheq_apply_QT_manyandeq_reflect, aseq_build_qrdoes. Neither H nor Z'HZ is formed, and the factorization operates on a matrix with the condition number cond(Z'HZ)^(1/2). The diagonal of L is made positive, so that L is, in exact arithmetic, the factor thateq_cholforms from Z'HZ, and its pivots L_kk^2 are tested as ineq_chol.eq_build_reduction, the factored branch (L824-L833) replaces the formation of Z'HZ (eq_twosideoreq_gemm_tn) andeq_chol. W = Z L^-T, the reduced constraints and the right-hand side are formed by the existing code. If Z'HZ is singular in the sense ofeq_chol, it is formed from L and the reduced problem is posed asDAQP_EQ_PATH_QPwithproblem_type0, as for an unfactored Hessian.DAQP_EQ_PATH_LDPis passed as a factor (packed,problem_type2; L894-L900, L963-L964). The reduced problem is then not regularized foreps_prox > 0, as a factored Hessian is not (utils.c#L328). For the same reason, the conditioning check that moves an ill-conditioned Z'HZ toDAQP_EQ_PATH_QPis not applied to a factored Hessian (L873-L893), asdaqp_finish_Rinvdoes not regularize a factored Hessian (utils.c#L517-L520).eq_hess_timesforms H x as R'(R x) (L352-L377, witheq_triu_times, L319-L340) for the particular solution, the right-hand side of a warm-started update and the multipliers of the eliminated equalities. A diagonal factor is used as the metric of the QR factorization as a diagonal Hessian is (eq_hess_diagandeq_is_diagonal, L341-L350, L404-L411), which also applies the heuristic ofDAQP_EQ_REDUCTION_AUTOfor diagonal Hessians to a diagonal factor.The path of an unfactored Hessian is unchanged: every change is conditioned on
problem_type2.Tests
qp_cold1 of #205
qp_cold1throughDAQPBase0.6.0 with the settings of the issue (cycle_tol = 100,abs_subopt = 0.4,rho_soft = 1), in the ten combinations of the form of the Hessian and theeq_reductionsetting.DAQPBase.setuppassesinit_mask = 0, so the reduction is decided at setup, andeq_reduction = 1takes effect only when it is set beforesetup("before and after"). The state of the reduction is read from theDAQPEqElimof the workspace aftersetup. The ten solves of a column ran concurrently on a shared 64-core machine, so the times indicate magnitudes.Master and this branch:
eq_reductionsetupsetupsetupsetupsetupsetupsetupsetupsetupsetupThe exit flag -1 of the solves without the reduction is the defect of #205, which #210 addresses. With #207, #208, #209 and #210 merged as well (branch
daqp-integrationof the fork, aedbbe7 before and c602e0f after merging this branch), every configuration returns exit flag 1, 131 nodes, objective 4006.8031:eq_reductionsetupsetupsetupsetupsetupsetupsetupsetupsetupsetupThe reduction of the factored problem is the same as that of H: path
DAQP_EQ_PATH_LDP, 128 eliminated equality constraints (the general ones; the other 67 are bounds of fixed variables), 791 reduced variables, 4302 constraints in the reduced problem. The setup in C (withPROFILING) takes 0.44 s with H and 0.48 s with the factor.Accuracy
qp_cold1 (cond(H) = 1.1e6, cond(Z'HZ) = 1.1e6), each path measured with respect to its data (H, or R'R of the factor):
BigFloat)In the QP relaxation (binary constraints made continuous), the solutions of the two reduced paths differ by at most 6.0e-10, and the factored reduced solution differs from the solution without the reduction by at most 1.1e-9.
Small problems (n from 20 to 40; dense, ill-conditioned, dependent equalities, equalities only, equalities that determine x, diagonal, soft constraints, binary variables, and a factor with a small diagonal entry whose near-null direction lies in the null space of the equalities), with
eq_reduction = 1beforesetup:W'HW - I is evaluated with 128-bit
BigFloat. In all reduced solves, the largest violation of a hard constraint is 5.8e-9 and the largest residual of an equality constraint 2.2e-14. After four updates of the bounds and of f of a reduced workspace (warm-started right-hand side) for five of the problems, the factored and the unfactored reduction agree to 1.2e-14 in x. With soft constraints, both reductions differ from the solve without the reduction by 2.6e-6 in x, which master shows for the unfactored reduction as well. The problem with the small diagonal entry of the factor returns exit flag -1 when it is solved as a factored problem without the reduction (a path that this change does not alter; master gives the same result), and exit flag 1 with the reduction, as the problem given by H does.Test suites
interfaces/daqp-eigen/tests/21_eq_reduction_factored.cpp(new) compares the factored reduction with the reduction of H and with the solve without the reduction, for the cases of the existing reduction tests: AUTO for a one-shot solve and for a workspace that is to be updated, dependent equalities, equalities that determine x, a diagonal factor (metric), a singular reduced Hessian (DAQP_EQ_PATH_QP), binary variables,eps_prox > 0, and updates of the bounds and of f. It fails on master (the factored problem is not reduced).core_tests.jl, testset "Equality elimination with a factored Hessian" (new): the factored reduction against the reduction of H and the solve without the reduction (dense, dependent equalities, equalities that determine x, diagonal), a one-shotquadprogwith the factor, and an update of the bounds.-DTEST=ON -DEIGEN=ON,ctest, Release)Pkg.test()from the layout of the build tree, Julia 1.12)The new Eigen test also passes in a Debug build.
Open question
For a factored Hessian, the reduced problem keeps
problem_type2 (with the identity as its factor), and the conditioning check that regularizes an ill-conditioned Z'HZ of an unfactored Hessian is not applied, following the treatment of a factored Hessian without the reduction. Is this the intended treatment, or should an ill-conditioned reduced Hessian of a factored problem also be moved toDAQP_EQ_PATH_QP?Host: battomenstation · Claude Code session ef50c8ca-f82f-4e37-8009-9861ba10460e · working directory ~/.julia/dev/HomeAssistantBot.jl/.claude/worktrees/validated-crafting-fern
🤖 Generated with Claude Code
https://claude.ai/code/session_01CogBfu3Xrhk7eUcMoX8BVT