Skip to content

Fix/nightly vcpkg mkl qp - #2931

Open
DLuminary wants to merge 2 commits into
borglab:developfrom
DLuminary:fix/nightly-vcpkg-mkl-qp
Open

DLuminary wants to merge 2 commits into
borglab:developfrom
DLuminary:fix/nightly-vcpkg-mkl-qp

Conversation

@DLuminary

Copy link
Copy Markdown
Contributor

The nightly vcpkg workflow fails on both MKL platforms. The two failures have
separate causes, introduced by #2921 and #2923, and this PR fixes each in its
own commit. The vcpkg baseline resolves to Eigen 5.0.1 and the workflow sets
GTSAM_WITH_EIGEN_MKL=ON, so Eigen routes LAPACK-backed decompositions through
MKL on Linux and Windows. macOS does not install MKL and the other workflows use
the bundled Eigen 3.4, which is why only these two jobs fail.

Ubuntu: DenseQpSolver.cpp does not compile

DenseQpSolver.cpp:269: objectivePermutation = objectiveQr.colsPermutation();
error: static assertion failed: YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD...

The cached objectivePermutation added in #2921 is a
PermutationMatrix<Dynamic, Dynamic>, whose index type is int. Eigen 5
indexes ColPivHouseholderQR permutations with DefaultPermutationIndex, which
is lapack_int whenever LAPACKE is enabled. With MKL's ILP64 interface on Linux
(-DMKL_ILP64), that is long long. Windows links the LP64 interface, so
lapack_int is int there and the file compiles.

The fix declares the member as ColPivHouseholderQR<Matrix>::PermutationType,
so it always matches the decomposition: int with Eigen 3.4, lapack_int with
Eigen 5 and LAPACKE. This is the only such assignment in the library.

Windows (and Ubuntu, once it compiles): failed to converge

testQpSolver.cpp:850: Failure: "Exception: ActiveSetSolver: failed to converge."

SquareRootAffineRhsRefinement, added in #2923, minimizes
‖J x − b‖² with ‖J‖² ≈ 1e16 and the exact minimizer x* = (1, 0). The active-set
convergence certificate, originalQpKktSatisfied, required every stationarity
residual to be at most multiplierTolerance (1e-7) in absolute terms. Evaluating
the gradient Jᵀ(J x − b) at a floating-point optimum has roundoff of order
eps · |J|ᵀ(|J| |x| + |b|) ≈ 3 for this cost. The check could therefore pass only
at a bit-exact iterate.

With EIGEN_USE_MKL_ALL, GTSAM's inplace_QR is routed to MKL's dgeqrf, which
produces an R factor one ulp different from Eigen's. The sparse refinement then
settles at x = (1.0000000000000002, −7.7e-16), which is accurate to 8e-16 but
has a gradient of 1.49. Each iteration recomputes the same candidate until the
iteration limit. Without MKL, the refinement happens to land exactly on (1, 0),
where the gradient is exactly zero. The pre-#2923 refinement was equally
accurate here; the test exercises whether convergence can be certified for an
ill-scaled square-root cost.

The fix gives the stationarity check the same kind of roundoff allowance that
scaledGapSatisfied already applies to the duality gap, 64·eps times the
magnitude of the summed terms:

  • |A_k|ᵀ(|A| |x| + |b|) for (whitened) Jacobian costs,
  • |G_k| |x| + |g_k| for Hessian costs,
  • |A_cᵀ| |λ| for active constraint rows.

Other factor types add no allowance. Primal feasibility, multiplier signs and
the gap check are unchanged.

Effect on other problems

To check that the allowance does not change behavior on well-scaled problems, I
temporarily logged every certificate evaluation in the constrained test suite.
Exactly one decision changed: the one in SquareRootAffineRhsRefinement, with
residual 1.49 and allowance 284. Every other evaluation had an allowance of at
most 2.8e-9, at least 35 times below the 1e-7 tolerance, with residuals far from
that boundary.

Validation

The build used Eigen 5.0.1, EIGEN_USE_MKL_ALL, MKL_ILP64 and
GTSAM_BUILD_WITH_WERROR=ON with GCC on Linux, matching the vcpkg Ubuntu job.

  • Before this PR, DenseQpSolver.cpp fails with the static assertion above.
  • With only the first commit, the full library builds, and testQpSolver
    fails at line 850 with the same message as the Windows job.
  • With both commits, all 20 test programs in gtsam/constrained/tests pass.
  • With both commits, gtsam_unstable/linear testQPSolver and testLPSolver
    (which wrap ActiveSetSolver) pass with GTSAM_ALLOW_DEPRECATED_SINCE_V43
    enabled.
  • git diff --check is clean, and the changed lines follow .clang-format.

The vcpkg nightly (Ubuntu) fails to compile DenseQpSolver.cpp:

  DenseQpSolver.cpp:269: objectivePermutation = objectiveQr.colsPermutation();
  error: static assertion failed: YOU_MIXED_DIFFERENT_NUMERIC_TYPES...

objectivePermutation, added in borglab#2921, was declared as
PermutationMatrix<Dynamic, Dynamic>, whose index type is int. Eigen 5 indexes
ColPivHouseholderQR permutations with DefaultPermutationIndex, which is
lapack_int whenever EIGEN_USE_LAPACKE is defined. The vcpkg workflow enables
GTSAM_WITH_EIGEN_MKL (and so EIGEN_USE_MKL_ALL), and MKL's ILP64 interface on
Linux makes lapack_int a 64-bit long long.

Declare the cache with ColPivHouseholderQR<Matrix>::PermutationType so it
always matches the decomposition: int with the bundled Eigen 3.4, lapack_int
with Eigen 5 + LAPACKE. This is the only such assignment in the library; the
full library builds with Eigen 5.0.1 + MKL ILP64 + -Werror after this change.
The vcpkg nightly (Windows; Ubuntu too once it compiles) fails:

  testQpSolver.cpp:850: Exception: ActiveSetSolver: failed to converge.

SquareRootAffineRhsRefinement, added in borglab#2923, minimizes ||J x - b||^2 with
||J||^2 ~ 1e16. originalQpKktSatisfied required each stationarity residual to
be at most multiplierTolerance (1e-7) in absolute terms, but evaluating
J^T (J x - b) at a floating-point optimum has roundoff of order
eps |J|^T (|J| |x| + |b|) ~ 3. The check could therefore only pass at a
bit-exact iterate.

With EIGEN_USE_MKL_ALL, inplace_QR is routed to MKL dgeqrf, whose R differs
from Eigen's by one ulp. The sparse refinement then settles at
|x - x*| ~ 8e-16 with a gradient of 1.49 instead of exactly zero; every
iteration recomputes the same candidate until the iteration limit. Without
MKL the refinement happens to land exactly on x*.

Mirror scaledGapSatisfied, which already allows 64 eps times the magnitude of
the summed terms: accumulate |A_k|^T (|A| |x| + |b|) for Jacobian costs,
|G_k| |x| + |g_k| for Hessian costs and |A_c^T| |lambda| for constraint rows,
and allow 64 eps of it per stationarity component. Other factor types add no
allowance, and primal-feasibility and dual-sign checks are unchanged.

Across the constrained test suite this changes exactly one certificate
decision, the one in SquareRootAffineRhsRefinement; every other evaluation
has an allowance of at most 2.8e-9, far below the 1e-7 tolerance.

This branch has not been deployed

No deployments
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.

1 participant