1{
2 lib,
3 stdenv,
4 buildPythonPackage,
5 fetchFromGitLab,
6
7 # build-system
8 setuptools,
9
10 # dependencies
11 astropy,
12 ducc0,
13 h5py,
14 jax,
15 jaxlib,
16 matplotlib,
17 mpi,
18 mpi4py,
19 numpy,
20 scipy,
21
22 # test
23 pytestCheckHook,
24 pytest-xdist,
25 mpiCheckPhaseHook,
26 openssh,
27}:
28
29buildPythonPackage rec {
30 pname = "nifty8";
31 version = "8.5.7";
32 pyproject = true;
33
34 src = fetchFromGitLab {
35 domain = "gitlab.mpcdf.mpg.de";
36 owner = "ift";
37 repo = "nifty";
38 tag = "v${version}";
39 hash = "sha256-5KPmM1UaXnS/ZEsnyFyxvDk4Nc4m6AT5FDgmCG6U6YU=";
40 };
41
42 # nifty8.re is the jax-backed version of nifty8 (the regular one uses numpy).
43 # It is not compatible with the latest jax update:
44 # https://gitlab.mpcdf.mpg.de/ift/nifty/-/issues/414
45 # While the issue is being fixed by upstream, we completely remove this package from the source and the tests.
46 postPatch = ''
47 rm -r src/re
48 rm -r test/test_re
49 '';
50
51 build-system = [ setuptools ];
52
53 dependencies = [
54 astropy
55 ducc0
56 h5py
57 jax
58 jaxlib
59 matplotlib
60 mpi4py
61 mpi
62 numpy
63 scipy
64 ];
65
66 nativeCheckInputs = [
67 pytestCheckHook
68 pytest-xdist
69 mpiCheckPhaseHook
70 openssh
71 ];
72
73 disabledTests = lib.optionals stdenv.hostPlatform.isDarwin [
74 # Fatal Python error: Aborted
75 # matplotlib/backend_bases.py", line 2654 in create_with_canvas
76 "test_optimize_kl_domain_expansion"
77 "test_plot_priorsamples"
78 ];
79
80 disabledTestPaths = lib.optionals stdenv.hostPlatform.isDarwin [
81 # Fatal Python error: Aborted
82 # matplotlib/backend_bases.py", line 2654 in create_with_canvas
83 "test/test_plot.py"
84 ];
85
86 __darwinAllowLocalNetworking = true;
87 postCheck =
88 lib.optionalString
89 (
90 # Fails on aarch64-linux with:
91 # hwloc/linux: failed to find sysfs cpu topology directory, aborting linux discovery.
92 # All nodes which are allocated for this job are already filled.
93 !(stdenv.hostPlatform.isLinux && stdenv.hostPlatform.isAarch64)
94 )
95 ''
96 ${lib.getExe' mpi "mpirun"} -n 2 --bind-to none python3 -m pytest test/test_mpi
97 '';
98
99 pythonImportsCheck = [ "nifty8" ];
100
101 meta = {
102 homepage = "https://gitlab.mpcdf.mpg.de/ift/nifty";
103 changelog = "https://gitlab.mpcdf.mpg.de/ift/nifty/-/blob/v${version}/ChangeLog.md";
104 description = "Bayesian Imaging library for high-dimensional posteriors";
105 longDescription = ''
106 NIFTy, "Numerical Information Field Theory", is a Bayesian imaging library.
107 It is designed to infer the million to billion dimensional posterior
108 distribution in the image space from noisy input data. At the core of
109 NIFTy lies a set of powerful Gaussian Process (GP) models and accurate
110 Variational Inference (VI) algorithms.
111 '';
112 license = lib.licenses.gpl3;
113 maintainers = with lib.maintainers; [ parras ];
114 };
115}