From d1a19f52a1f965dd7140edd9bfc9a0ea691885ba Mon Sep 17 00:00:00 2001 From: Phillip Seeber Date: Tue, 15 Apr 2025 17:26:12 +0200 Subject: [PATCH 1/2] openmolcas: 24.10 -> 25.02 --- pkgs/by-name/op/openmolcas/package.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/by-name/op/openmolcas/package.nix b/pkgs/by-name/op/openmolcas/package.nix index 35d244cec9a0..5ae14f4aa888 100644 --- a/pkgs/by-name/op/openmolcas/package.nix +++ b/pkgs/by-name/op/openmolcas/package.nix @@ -56,13 +56,13 @@ let in stdenv.mkDerivation rec { pname = "openmolcas"; - version = "24.10"; + version = "25.02"; src = fetchFromGitLab { owner = "Molcas"; repo = "OpenMolcas"; rev = "v${version}"; - hash = "sha256-LXxr/xqBHG7a0rOBrb8IMZ4IjZak3NsBw40Qf+z1fic="; + hash = "sha256-Ty7C7zj1lQixuUzeKLcwQCmcPexZXtIGDzp1wUMKDi0="; }; patches = [ From 7814422e8bc5e391758b5d0915cebfa64d828484 Mon Sep 17 00:00:00 2001 From: Phillip Seeber Date: Wed, 16 Apr 2025 14:51:04 +0200 Subject: [PATCH 2/2] openmolcas: fix blas/lapack usage and qcmaquis builds --- pkgs/by-name/op/openmolcas/nevpt2.patch | 22 ++++ pkgs/by-name/op/openmolcas/openblasPath.patch | 12 --- pkgs/by-name/op/openmolcas/package.nix | 100 +++++++++--------- pkgs/by-name/op/openmolcas/qcmaquis.patch | 55 ++++++++++ 4 files changed, 129 insertions(+), 60 deletions(-) create mode 100644 pkgs/by-name/op/openmolcas/nevpt2.patch delete mode 100644 pkgs/by-name/op/openmolcas/openblasPath.patch diff --git a/pkgs/by-name/op/openmolcas/nevpt2.patch b/pkgs/by-name/op/openmolcas/nevpt2.patch new file mode 100644 index 000000000000..0033a17af196 --- /dev/null +++ b/pkgs/by-name/op/openmolcas/nevpt2.patch @@ -0,0 +1,22 @@ +diff --git a/src/gctime.c b/src/gctime.c +index 34fcb6f..832459c 100644 +--- a/src/gctime.c ++++ b/src/gctime.c +@@ -1,14 +1,15 @@ ++#include + typedef long f77_int; /* Fortran integer type */ + typedef char * f77_char; /* Fortran character argument */ + #define CH_F2C(X) ((char *) (X)) /* How to get char ptr from F77 argument */ +-gctime (fstr, lstr) f77_char *fstr; int lstr; { ++int gctime (fstr, lstr) f77_char *fstr; int lstr; { + long time(), t; + char *ctime(); + t = time ( (long *) 0); + strcpy(CH_F2C(fstr),ctime(&t)); + return (0); + } +-gctime_(fstr, lstr) f77_char *fstr; int lstr; { ++int gctime_(fstr, lstr) f77_char *fstr; int lstr; { + long time(), t; + char *ctime(); + t = time ( (long *) 0); diff --git a/pkgs/by-name/op/openmolcas/openblasPath.patch b/pkgs/by-name/op/openmolcas/openblasPath.patch deleted file mode 100644 index e47adcc3e9a3..000000000000 --- a/pkgs/by-name/op/openmolcas/openblasPath.patch +++ /dev/null @@ -1,12 +0,0 @@ -diff --git a/CMakeLists.txt b/CMakeLists.txt -index 276ae4e2..db13e6e3 100644 ---- a/CMakeLists.txt -+++ b/CMakeLists.txt -@@ -1507,7 +1507,6 @@ if (LINALG STREQUAL "OpenBLAS") - NAMES openblas - PATHS ${OPENBLASROOT} - PATH_SUFFIXES lib -- NO_DEFAULT_PATH - ) - - if (NOT LIBOPENBLAS) diff --git a/pkgs/by-name/op/openmolcas/package.nix b/pkgs/by-name/op/openmolcas/package.nix index 5ae14f4aa888..87e27a8a390a 100644 --- a/pkgs/by-name/op/openmolcas/package.nix +++ b/pkgs/by-name/op/openmolcas/package.nix @@ -7,6 +7,7 @@ gfortran, perl, blas-ilp64, + lapack-ilp64, hdf5-cpp, python3, texliveMinimal, @@ -16,7 +17,7 @@ gsl, boost, autoPatchelfHook, - enableQcmaquis ? false, + enableQcmaquis ? true, # Note that the CASPT2 module is broken with MPI # See https://gitlab.com/Molcas/OpenMolcas/-/issues/169 enableMpi ? false, @@ -25,11 +26,7 @@ }: assert blas-ilp64.isILP64; -assert lib.elem blas-ilp64.passthru.implementation [ - "openblas" - "mkl" -]; -assert enableQcmaquis -> lib.elem blas-ilp64.passthru.implementation "mkl"; +assert lapack-ilp64.isILP64; let python = python3.withPackages ( @@ -46,11 +43,27 @@ let rev = "release-3.1.4"; # Must match tag in cmake/custom/qcmaquis.cmake hash = "sha256-vhC5k+91IPFxdCi5oYt1NtF9W08RxonJjPpA0ls4I+o="; }; - nevtp2Src = fetchFromGitHub { - owner = "qcscine"; - repo = "nevpt2"; - rev = "e1484fd"; # Must match tag in cmake/custom/nevpt2.cmake - hash = "sha256-Vl+FhwhJBbD/7U2CwsYE9BClSQYLJ8DKXV9EXxQUmz0="; + + # NEVPT2 sources must be patched to be valid C code in gctime.c + nevpt2Src = stdenv.mkDerivation { + pname = "nevpt2-src"; + version = "unstable"; + phases = [ + "unpackPhase" + "patchPhase" + "installPhase" + ]; + src = fetchFromGitHub { + owner = "qcscine"; + repo = "nevpt2"; + rev = "e1484fd"; # Must match tag in cmake/custom/nevpt2.cmake + hash = "sha256-Vl+FhwhJBbD/7U2CwsYE9BClSQYLJ8DKXV9EXxQUmz0="; + }; + patches = [ ./nevpt2.patch ]; + installPhase = '' + mkdir $out + cp -r * $out/. + ''; }; in @@ -66,10 +79,7 @@ stdenv.mkDerivation rec { }; patches = [ - # Required to handle openblas multiple outputs - ./openblasPath.patch - - # Required for a local QCMaquis build + # Required for a local QCMaquis build. Also sanitises QCMaquis BLAS/LAPACK handling ./qcmaquis.patch ]; @@ -83,7 +93,7 @@ stdenv.mkDerivation rec { --subst-var-by "qcmaquis_src_url" "file://${qcmaquisSrc}" substituteInPlace cmake/custom/nevpt2.cmake \ - --subst-var-by "nevpt2_src_url" "file://${nevtp2Src}" + --subst-var-by "nevpt2_src_url" "file://${nevpt2Src}" ''; nativeBuildInputs = [ @@ -97,13 +107,14 @@ stdenv.mkDerivation rec { buildInputs = [ - blas-ilp64.passthru.provider hdf5-cpp python armadillo libxc gsl.dev boost + blas-ilp64 + lapack-ilp64 ] ++ lib.optionals enableMpi [ mpi @@ -112,38 +123,31 @@ stdenv.mkDerivation rec { passthru = lib.optionalAttrs enableMpi { inherit mpi; }; - cmakeFlags = - [ - "-DOPENMP=ON" - "-DTOOLS=ON" - "-DHDF5=ON" - "-DFDE=ON" - "-DEXTERNAL_LIBXC=${lib.getDev libxc}" - (lib.strings.cmakeBool "DMRG" enableQcmaquis) - (lib.strings.cmakeBool "NEVPT2" enableQcmaquis) - "-DCMAKE_SKIP_BUILD_RPATH=ON" - (lib.strings.cmakeBool "BUILD_STATIC_LIBS" stdenv.hostPlatform.isStatic) - (lib.strings.cmakeBool "BUILD_SHARED_LIBS" (!stdenv.hostPlatform.isStatic)) - ] - ++ lib.optionals (blas-ilp64.passthru.implementation == "openblas") [ - "-DOPENBLASROOT=${blas-ilp64.passthru.provider.dev}" - "-DLINALG=OpenBLAS" - ] - ++ lib.optionals (blas-ilp64.passthru.implementation == "mkl") [ - "-DMKLROOT=${blas-ilp64.passthru.provider}" - "-DLINALG=MKL" - ] - ++ lib.optionals enableMpi [ - "-DGA=ON" - "-DMPI=ON" - ]; - - preConfigure = lib.optionalString enableMpi '' - export GAROOT=${globalarrays}; - ''; + preConfigure = + '' + cmakeFlagsArray+=( + "-DOPENMP=ON" + "-DTOOLS=ON" + "-DHDF5=ON" + "-DFDE=ON" + "-DEXTERNAL_LIBXC=${lib.getDev libxc}" + ${lib.strings.cmakeBool "DMRG" enableQcmaquis} + ${lib.strings.cmakeBool "NEVPT2" enableQcmaquis} + "-DCMAKE_SKIP_BUILD_RPATH=ON" + ${lib.strings.cmakeBool "BUILD_STATIC_LIBS" stdenv.hostPlatform.isStatic} + ${lib.strings.cmakeBool "BUILD_SHARED_LIBS" (!stdenv.hostPlatform.isStatic)} + "-DLINALG=Manual" + "-DLINALG_LIBRARIES=-lblas -llapack" + ${lib.strings.cmakeBool "DGA" enableMpi} + ${lib.strings.cmakeBool "MPI" enableMpi} + ) + '' + + lib.optionalString enableMpi '' + export GAROOT=${globalarrays}; + ''; + # The Makefile will install pymolcas during the build grrr. postConfigure = '' - # The Makefile will install pymolcas during the build grrr. mkdir -p $out/bin export PATH=$PATH:$out/bin ''; @@ -158,8 +162,8 @@ stdenv.mkDerivation rec { # removed by autopatchelf noAuditTmpdir = true; + # Wrong store path in shebang (bare Python, no Python pkgs), force manual re-patching postFixup = '' - # Wrong store path in shebang (bare Python, no Python pkgs), force manual re-patching for exe in $(find $out/bin/ -type f -name "*.py"); do sed -i "1s:.*:#!${python}/bin/python:" "$exe" done diff --git a/pkgs/by-name/op/openmolcas/qcmaquis.patch b/pkgs/by-name/op/openmolcas/qcmaquis.patch index c388f699a1cc..c4b5261a6cf6 100644 --- a/pkgs/by-name/op/openmolcas/qcmaquis.patch +++ b/pkgs/by-name/op/openmolcas/qcmaquis.patch @@ -45,3 +45,58 @@ index 5fd1ef207..8d2957c6e 100644 SOURCE_SUBDIR dmrg CMAKE_ARGS ${EP_CMAKE_ARGS} CMAKE_CACHE_ARGS ${EP_CMAKE_CACHE_ARGS} +diff --git a/cmake/custom/qcmaquis.cmake b/cmake/custom/qcmaquis.cmake +index 5fd1ef207..4291ec3d7 100644 +--- a/cmake/custom/qcmaquis.cmake ++++ b/cmake/custom/qcmaquis.cmake +@@ -94,47 +94,9 @@ if (NOT MAQUIS_DMRG_FOUND) # Does the opposite work? + ) + endif (BOOST_ROOT) + +- if (LINALG STREQUAL "Manual") +- target_files (LINALG_LIBRARIES_FILES ${LINALG_LIBRARIES}) +- list (APPEND LINALG_LIBRARIES_FILES ${CMAKE_Fortran_IMPLICIT_LINK_LIBRARIES}) +- string (REPLACE ";" '\' LINALG_LIBRARIES_FILES "${LINALG_LIBRARIES_FILES}") +- list (APPEND QCMaquisCMakeArgs +- "-DBLAS_LAPACK_SELECTOR=manual" +- "-DMAQUISLapack_LIBRARIES=${LINALG_LIBRARIES_FILES}" +- ) +- elseif (LINALG STREQUAL "MKL") +- list (APPEND QCMaquisCMakeArgs +- "-DBLAS_LAPACK_SELECTOR=mkl_sequential" +- ) +- elseif (LINALG STREQUAL "OpenBLAS") +- list (APPEND QCMaquisCMakeArgs +- "-DBLAS_LAPACK_SELECTOR=openblas" +- "-DOPENBLASROOT=${OPENBLASROOT}" +- ) +- elseif (LINALG STREQUAL "Accelerate") +- list (APPEND QCMaquisCMakeArgs +- "-DBLAS_LAPACK_SELECTOR:STRING=veclib" +- ) +- elseif (LINALG STREQUAL "Internal") +- +- # To link QCMaquis with Fortran static libraries, we +- # need to add -lgfortran for gfortran +- # It seems that ${CMAKE_Fortran_IMPLICIT_LINK_LIBRARIES} +- # is not suited for this because it contains also other unnecessary libraries +- +- # for some reason, the list does not work if the generator expression -lgfortran is not first +- # but for correct linking it needs to be last AND with a prepended "-l" +- if (CMAKE_Fortran_COMPILER_ID STREQUAL "GNU") +- set (Fortran_RUNTIME_LIBRARY "gfortran") +- endif () +- +- list (APPEND QCMaquisCMakeArgs +- "-DBLAS_LAPACK_SELECTOR=manual" +- "-DMAQUISLapack_LIBRARIES=$<$:${Fortran_RUNTIME_LIBRARY}\ >$\ $\ $\ -l$<$:${Fortran_RUNTIME_LIBRARY}>" +- ) +- else () +- message (FATAL_ERROR "LINALG=${LINALG} is not supported by QCMaquis") +- endif () ++ list (APPEND QCMaquisCMakeArgs ++ "-DBLAS_LAPACK_SELECTOR=auto" ++ ) + + # Enabling source changes to keep ExternalProject happy + set (CMAKE_DISABLE_SOURCE_CHANGES OFF