From d1b2225e92ac3d3c6f7c9316eb7e26bb58c36b1e Mon Sep 17 00:00:00 2001 From: Alberto Hernandez <7albertoh@gmail.com> Date: Sat, 25 Apr 2026 21:55:33 -0400 Subject: [PATCH] Add qr build option for numerically stable GAP fitting Add a new meson build option 'qr' (default: true) that enables the -DHAVE_QR compiler flag. This activates the QR decomposition solve path in gp_predict.F90, which is numerically stable for ill-conditioned kernel matrices that cause Cholesky (dpotrf) to fail with 'LA_Matrix_Factorise: cannot factorise'. The QR code path already exists in the GAP source (gp_predict.F90, lines 782-905) but was never wired into the build system. Fixes issues where gap_fit crashes on SOAP descriptors with moderate sparse point counts (500-2000). --- meson.build | 8 ++++++-- meson.options | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/meson.build b/meson.build index b73b35b93..323c841d7 100644 --- a/meson.build +++ b/meson.build @@ -27,11 +27,15 @@ add_global_arguments([ if get_option('gap') gap_version_res = run_command('src/GAP/gapversion',check:true) - add_global_arguments([ + gap_args = [ '-DGAP_VERSION='+gap_version_res.stdout().strip(), '-DHAVE_GAP', '-DHAVE_TB', - ], language:'fortran') + ] + if get_option('qr') + gap_args += '-DHAVE_QR' + endif + add_global_arguments(gap_args, language:'fortran') endif # Determine QUIP_ARCH dynamically based on host machine diff --git a/meson.options b/meson.options index 944c33196..1921eb659 100644 --- a/meson.options +++ b/meson.options @@ -1,2 +1,3 @@ option('mpi', type: 'boolean', value : false) option('gap', type: 'boolean', value : true) +option('qr', type: 'boolean', value : true, description : 'Use QR decomposition for numerically stable GAP fitting (requires GAP)')