From 0cbe02b3385dbcbbf5c16942ee6d2d1391f65d80 Mon Sep 17 00:00:00 2001 From: qbisi Date: Fri, 14 Mar 2025 03:45:40 +0800 Subject: [PATCH 01/11] petsc: do not install examples by default Petsc examples take up 58M and can be found in source code. Thus we do not ship petsc with examples by default. --- pkgs/by-name/pe/petsc/package.nix | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pkgs/by-name/pe/petsc/package.nix b/pkgs/by-name/pe/petsc/package.nix index c3a642e0656c..70a0e5e76970 100644 --- a/pkgs/by-name/pe/petsc/package.nix +++ b/pkgs/by-name/pe/petsc/package.nix @@ -19,6 +19,7 @@ petsc-precision ? "double", mpiSupport ? true, withPetsc4py ? false, # petsc python binding + withExamples ? false, withFullDeps ? false, # full External libraries support # External libraries options @@ -165,6 +166,8 @@ stdenv.mkDerivation rec { configureScript = "python ./configure"; + installTargets = [ (if withExamples then "install" else "install-lib") ]; + enableParallelBuilding = true; # This is needed as the checks need to compile and link the test cases with From e1b955a3a7a63369acc5be25ba3c63c5205857ed Mon Sep 17 00:00:00 2001 From: qbisi Date: Fri, 14 Mar 2025 07:26:26 +0800 Subject: [PATCH 02/11] petsc: remove redundant configureScript shebang in configure script is auto patched --- pkgs/by-name/pe/petsc/package.nix | 2 -- 1 file changed, 2 deletions(-) diff --git a/pkgs/by-name/pe/petsc/package.nix b/pkgs/by-name/pe/petsc/package.nix index 70a0e5e76970..391de457d789 100644 --- a/pkgs/by-name/pe/petsc/package.nix +++ b/pkgs/by-name/pe/petsc/package.nix @@ -164,8 +164,6 @@ stdenv.mkDerivation rec { "fortify3" ]; - configureScript = "python ./configure"; - installTargets = [ (if withExamples then "install" else "install-lib") ]; enableParallelBuilding = true; From 84a09d48d8879efe86d9a0bd6625c8ec7db58e42 Mon Sep 17 00:00:00 2001 From: qbisi Date: Sun, 16 Mar 2025 22:32:22 +0800 Subject: [PATCH 03/11] python312packages.petsc4py: replace withPetsc4py with pythonSupport pythonSupport is more commonly used in toPythonModule --- pkgs/by-name/pe/petsc/package.nix | 8 ++++---- pkgs/top-level/python-packages.nix | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pkgs/by-name/pe/petsc/package.nix b/pkgs/by-name/pe/petsc/package.nix index 391de457d789..0d0ae9cf3cc3 100644 --- a/pkgs/by-name/pe/petsc/package.nix +++ b/pkgs/by-name/pe/petsc/package.nix @@ -18,7 +18,7 @@ petsc-scalar-type ? "real", petsc-precision ? "double", mpiSupport ? true, - withPetsc4py ? false, # petsc python binding + pythonSupport ? false, # petsc python binding withExamples ? false, withFullDeps ? false, # full External libraries support @@ -70,7 +70,7 @@ stdenv.mkDerivation rec { pkg-config ] ++ lib.optional mpiSupport mpi - ++ lib.optionals withPetsc4py [ + ++ lib.optionals pythonSupport [ python3Packages.setuptools python3Packages.cython ]; @@ -88,7 +88,7 @@ stdenv.mkDerivation rec { ++ lib.optional withScalapack scalapack ++ lib.optional withMumps mumps_par; - propagatedBuildInputs = lib.optional withPetsc4py python3Packages.numpy; + propagatedBuildInputs = lib.optional pythonSupport python3Packages.numpy; patches = [ (replaceVars ./fix-petsc4py-install-prefix.patch { @@ -113,7 +113,7 @@ stdenv.mkDerivation rec { "--with-precision=${petsc-precision}" "--with-mpi=${if mpiSupport then "1" else "0"}" ] - ++ lib.optional withPetsc4py "--with-petsc4py=1" + ++ lib.optional pythonSupport "--with-petsc4py=1" ++ lib.optionals mpiSupport [ "--CC=mpicc" "--with-cxx=mpicxx" diff --git a/pkgs/top-level/python-packages.nix b/pkgs/top-level/python-packages.nix index 85ac3492daa4..216d02868456 100644 --- a/pkgs/top-level/python-packages.nix +++ b/pkgs/top-level/python-packages.nix @@ -10504,7 +10504,7 @@ self: super: with self; { petsc4py = toPythonModule (pkgs.petsc.override { python3 = python; python3Packages = self; - withPetsc4py = true; + pythonSupport = true; withFullDeps = true; }); From 9ced50e8f818309947726371892d0e706e49fa3e Mon Sep 17 00:00:00 2001 From: qbisi Date: Tue, 18 Mar 2025 20:48:05 +0800 Subject: [PATCH 04/11] petsc: add pythonSupport to passthru attributes --- pkgs/by-name/pe/petsc/package.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/by-name/pe/petsc/package.nix b/pkgs/by-name/pe/petsc/package.nix index 0d0ae9cf3cc3..c00d34d61006 100644 --- a/pkgs/by-name/pe/petsc/package.nix +++ b/pkgs/by-name/pe/petsc/package.nix @@ -177,7 +177,7 @@ stdenv.mkDerivation rec { nativeInstallCheckInputs = [ mpiCheckPhaseHook ]; passthru = { - inherit mpiSupport; + inherit mpiSupport pythonSupport; }; setupHook = ./setup-hook.sh; From 887ad07236743d90e008561b2771770ccf4caf53 Mon Sep 17 00:00:00 2001 From: qbisi Date: Sat, 15 Mar 2025 16:50:24 +0800 Subject: [PATCH 05/11] python312packages.petsc4py: do not build withFullDeps The `withFullDeps` flag was used to make petsc4py meet the requirements of downstream projects like Fenics and Firedrake. However, this flag breaks the build on other platforms if any external packages of PETSc fail. Therefore, I disabled this flag in petsc4py and made PETSc bundle some commonly used external packages by default. Users can still have a minimally featured PETSc by setting `withCommonDeps = false`. --- pkgs/by-name/pe/petsc/package.nix | 10 ++++++---- pkgs/top-level/python-packages.nix | 1 - 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/pkgs/by-name/pe/petsc/package.nix b/pkgs/by-name/pe/petsc/package.nix index c00d34d61006..69833766c963 100644 --- a/pkgs/by-name/pe/petsc/package.nix +++ b/pkgs/by-name/pe/petsc/package.nix @@ -21,13 +21,14 @@ pythonSupport ? false, # petsc python binding withExamples ? false, withFullDeps ? false, # full External libraries support + withCommonDeps ? true, # common External libraries support # External libraries options - withHdf5 ? true, - withMetis ? withFullDeps, - withParmetis ? false, # parmetis is unfree and should be enabled manualy - withPtscotch ? withFullDeps, + withHdf5 ? withCommonDeps, + withMetis ? withCommonDeps, withScalapack ? withFullDeps, + withParmetis ? withFullDeps, # parmetis is unfree + withPtscotch ? withFullDeps, withMumps ? withFullDeps, withP4est ? withFullDeps, @@ -41,6 +42,7 @@ pkg-config, p4est, }: +assert withFullDeps -> withCommonDeps; # This version of PETSc does not support a non-MPI p4est build assert withP4est -> (p4est.mpiSupport && mpiSupport); diff --git a/pkgs/top-level/python-packages.nix b/pkgs/top-level/python-packages.nix index 216d02868456..6b6971212507 100644 --- a/pkgs/top-level/python-packages.nix +++ b/pkgs/top-level/python-packages.nix @@ -10505,7 +10505,6 @@ self: super: with self; { python3 = python; python3Packages = self; pythonSupport = true; - withFullDeps = true; }); pex = callPackage ../development/python-modules/pex { }; From 9aa034835b3f711f3c9e65402ac58f832e11219f Mon Sep 17 00:00:00 2001 From: qbisi Date: Sun, 16 Mar 2025 22:43:44 +0800 Subject: [PATCH 06/11] petsc: remove unneccessary substitue of install_name_tool This substitueInplace was an old patch and will fail if use --replace-fail. --- pkgs/by-name/pe/petsc/package.nix | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/pkgs/by-name/pe/petsc/package.nix b/pkgs/by-name/pe/petsc/package.nix index 69833766c963..cb9470b47428 100644 --- a/pkgs/by-name/pe/petsc/package.nix +++ b/pkgs/by-name/pe/petsc/package.nix @@ -2,7 +2,6 @@ lib, stdenv, fetchzip, - cctools, gfortran, replaceVars, python3, @@ -98,14 +97,9 @@ stdenv.mkDerivation rec { }) ]; - postPatch = - '' - patchShebangs ./lib/petsc/bin - '' - + lib.optionalString stdenv.hostPlatform.isDarwin '' - substituteInPlace config/install.py \ - --replace /usr/bin/install_name_tool ${cctools}/bin/install_name_tool - ''; + postPatch = '' + patchShebangs ./lib/petsc/bin + ''; configureFlags = [ From e3b2cfa523cf588edf83459b23d62af8b3f1c845 Mon Sep 17 00:00:00 2001 From: qbisi Date: Tue, 18 Mar 2025 19:20:29 +0800 Subject: [PATCH 07/11] petsc: patch shebang in template string of example_template.py This patch does not fix the shebang at the begining of the example_template.py file. It only replaces the shebang in the template string of that file. --- pkgs/by-name/pe/petsc/package.nix | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pkgs/by-name/pe/petsc/package.nix b/pkgs/by-name/pe/petsc/package.nix index cb9470b47428..8e0abca000e2 100644 --- a/pkgs/by-name/pe/petsc/package.nix +++ b/pkgs/by-name/pe/petsc/package.nix @@ -11,6 +11,7 @@ zlib, # propagated by p4est but required by petsc mpi, # generic mpi dependency mpiCheckPhaseHook, + bash, # Build options petsc-optimized ? true, @@ -99,6 +100,9 @@ stdenv.mkDerivation rec { postPatch = '' patchShebangs ./lib/petsc/bin + + substituteInPlace config/example_template.py \ + --replace-fail "/usr/bin/env bash" "${bash}/bin/bash" ''; configureFlags = From c47cf8cca0dde145b9e5e45050b2667107eef03e Mon Sep 17 00:00:00 2001 From: qbisi Date: Sun, 16 Mar 2025 03:27:26 +0800 Subject: [PATCH 08/11] petsc: fix and add python related tests --- pkgs/by-name/pe/petsc/package.nix | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/pkgs/by-name/pe/petsc/package.nix b/pkgs/by-name/pe/petsc/package.nix index 8e0abca000e2..9e169fa48436 100644 --- a/pkgs/by-name/pe/petsc/package.nix +++ b/pkgs/by-name/pe/petsc/package.nix @@ -174,7 +174,28 @@ stdenv.mkDerivation rec { # the library is installed and available. doInstallCheck = true; installCheckTarget = "check_install"; - nativeInstallCheckInputs = [ mpiCheckPhaseHook ]; + + # The PETSC4PY=no flag disables the ex100 test, + # which compiles C code to load Python modules for solving a math problem. + # This test fails on the Darwin platform but is rarely a common use case for petsc4py. + installCheckFlags = lib.optional stdenv.hostPlatform.isDarwin "PETSC4PY=no"; + + nativeInstallCheckInputs = + [ + mpiCheckPhaseHook + ] + ++ lib.optionals pythonSupport [ + python3Packages.pythonImportsCheckHook + python3Packages.unittestCheckHook + ]; + + unittestFlagsArray = [ + "-s" + "src/binding/petsc4py/test" + "-v" + ]; + + pythonImportsCheck = [ "petsc4py" ]; passthru = { inherit mpiSupport pythonSupport; From 1cde35aa8fd67e82ab67d9e96882b87cca426c18 Mon Sep 17 00:00:00 2001 From: qbisi Date: Tue, 18 Mar 2025 19:49:55 +0800 Subject: [PATCH 09/11] petsc: add meta.platforms --- pkgs/by-name/pe/petsc/package.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/pkgs/by-name/pe/petsc/package.nix b/pkgs/by-name/pe/petsc/package.nix index 9e169fa48436..d31359143af8 100644 --- a/pkgs/by-name/pe/petsc/package.nix +++ b/pkgs/by-name/pe/petsc/package.nix @@ -207,6 +207,7 @@ stdenv.mkDerivation rec { description = "Portable Extensible Toolkit for Scientific computation"; homepage = "https://petsc.org/release/"; license = licenses.bsd2; + platforms = lib.platforms.unix; maintainers = with maintainers; [ cburstedde qbisi From 05f78eb5853059125594d9f3655c8458ef0ddd8b Mon Sep 17 00:00:00 2001 From: qbisi Date: Sat, 15 Mar 2025 16:47:20 +0800 Subject: [PATCH 10/11] sowing: init at 1.1.26.12 --- pkgs/by-name/so/sowing/package.nix | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 pkgs/by-name/so/sowing/package.nix diff --git a/pkgs/by-name/so/sowing/package.nix b/pkgs/by-name/so/sowing/package.nix new file mode 100644 index 000000000000..a81fc9fdc654 --- /dev/null +++ b/pkgs/by-name/so/sowing/package.nix @@ -0,0 +1,25 @@ +{ + lib, + stdenv, + fetchFromBitbucket, +}: + +stdenv.mkDerivation (finalAttrs: { + pname = "sowing"; + version = "1.1.26.12"; + + src = fetchFromBitbucket { + owner = "petsc"; + repo = "pkg-sowing"; + rev = "v${finalAttrs.version}"; + hash = "sha256-ol0xNAnL7ULU1CiGCFZrV37IAV4z1bcWa0f+tuMhQC8="; + }; + + meta = { + description = "Tools for documenting and improving portability"; + homepage = "https://wgropp.cs.illinois.edu/projects/software/sowing/"; + license = lib.licenses.mit; + maintainers = with lib.maintainers; [ qbisi ]; + platforms = lib.platforms.unix; + }; +}) From faab78f8d71622c85f0d72dbcf0bd58ab9e7c3b0 Mon Sep 17 00:00:00 2001 From: qbisi Date: Sat, 15 Mar 2025 16:47:45 +0800 Subject: [PATCH 11/11] slepc: init at 3.22.2 --- pkgs/by-name/sl/slepc/package.nix | 119 ++++++++++++++++++++++++++++ pkgs/by-name/sl/slepc/setup-hook.sh | 1 + pkgs/top-level/python-packages.nix | 7 ++ 3 files changed, 127 insertions(+) create mode 100644 pkgs/by-name/sl/slepc/package.nix create mode 100644 pkgs/by-name/sl/slepc/setup-hook.sh diff --git a/pkgs/by-name/sl/slepc/package.nix b/pkgs/by-name/sl/slepc/package.nix new file mode 100644 index 000000000000..371cd1d15805 --- /dev/null +++ b/pkgs/by-name/sl/slepc/package.nix @@ -0,0 +1,119 @@ +{ + lib, + stdenv, + fetchFromGitLab, + sowing, + python3, + python3Packages, + arpack-mpi, + petsc, + mpi, + mpiCheckPhaseHook, + pythonSupport ? false, + withExamples ? false, + withArpack ? stdenv.hostPlatform.isLinux, +}: +assert petsc.mpiSupport; +assert pythonSupport -> petsc.pythonSupport; +stdenv.mkDerivation (finalAttrs: { + pname = "slepc"; + version = "3.22.2"; + + src = fetchFromGitLab { + owner = "slepc"; + repo = "slepc"; + tag = "v${finalAttrs.version}"; + hash = "sha256-a5DmsA7NAlhrEaS43TYPk7vtDfhXLEP+5sftu2A9Yt4="; + }; + + postPatch = '' + # Fix slepc4py install prefix + substituteInPlace config/packages/slepc4py.py \ + --replace-fail "slepc.prefixdir,'lib'" \ + "slepc.prefixdir,'${python3.sitePackages}'" + + patchShebangs lib/slepc/bin + + # Use system bfort + substituteInPlace config/packages/sowing.py \ + --replace-fail "bfort = os.path.join(archdir,'bin','bfort')" \ + "bfort = '${sowing}/bin/bfort'" + ''; + + # Usually this project is being built as part of a `petsc` build or as part of + # other projects, e.g when `petsc` is `./configure`d with + # `--download-slepc=1`. This instructs the slepc to be built as a standalone + # project. + preConfigure = '' + export SLEPC_DIR=$PWD + ''; + + nativeBuildInputs = + [ + python3 + ] + ++ lib.optionals pythonSupport [ + python3Packages.setuptools + python3Packages.cython + ]; + + configureFlags = + lib.optionals withArpack [ + "--with-arpack=1" + ] + ++ lib.optionals pythonSupport [ + "--with-slepc4py=1" + ]; + + buildInputs = + [ + mpi + ] + ++ lib.optionals withArpack [ + arpack-mpi + ]; + + propagatedBuildInputs = [ + petsc + ]; + + enableParallelBuilding = true; + + installTargets = [ (if withExamples then "install" else "install-lib") ]; + + nativeInstallCheckInputs = + [ + mpiCheckPhaseHook + ] + ++ lib.optionals pythonSupport [ + python3Packages.pythonImportsCheckHook + python3Packages.unittestCheckHook + ]; + + doInstallCheck = true; + + installCheckTarget = [ "check_install" ]; + + unittestFlagsArray = [ + "-s" + "src/binding/slepc4py/test" + "-v" + ]; + + pythonImportsCheck = [ "slepc4py" ]; + + shellHook = ./setup-hook.sh; + + meta = { + description = "Scalable Library for Eigenvalue Problem Computations"; + homepage = "https://slepc.upv.es"; + changelog = "https://gitlab.com/slepc/slepc/blob/${finalAttrs.src.tag}/CHANGELOG.md"; + license = with lib.licenses; [ + bsd2 + ]; + platforms = lib.platforms.unix; + maintainers = with lib.maintainers; [ qbisi ]; + # Possible error running Fortran src/eps/tests/test7f with 1 MPI process + broken = stdenv.hostPlatform.isDarwin && withArpack; + }; +}) diff --git a/pkgs/by-name/sl/slepc/setup-hook.sh b/pkgs/by-name/sl/slepc/setup-hook.sh new file mode 100644 index 000000000000..838c82aaeee9 --- /dev/null +++ b/pkgs/by-name/sl/slepc/setup-hook.sh @@ -0,0 +1 @@ +export SLEPC_DIR=@out@ diff --git a/pkgs/top-level/python-packages.nix b/pkgs/top-level/python-packages.nix index 6b6971212507..fc41fd196b00 100644 --- a/pkgs/top-level/python-packages.nix +++ b/pkgs/top-level/python-packages.nix @@ -15350,6 +15350,13 @@ self: super: with self; { sleepyq = callPackage ../development/python-modules/sleepyq { }; + slepc4py = toPythonModule (pkgs.slepc.override { + pythonSupport = true; + python3 = self.python; + python3Packages = self; + petsc = petsc4py; + }); + sleqp = toPythonModule (pkgs.sleqp.override { pythonSupport = true; python3Packages = self; }); slicedimage = callPackage ../development/python-modules/slicedimage { };