1{
2 lib,
3 autograd,
4 buildPythonPackage,
5 fetchFromGitHub,
6 cupy,
7 cvxopt,
8 cython,
9 oldest-supported-numpy,
10 matplotlib,
11 numpy,
12 tensorflow,
13 pymanopt,
14 pytestCheckHook,
15 pythonOlder,
16 scikit-learn,
17 scipy,
18 enableDimensionalityReduction ? false,
19 enableGPU ? false,
20}:
21
22buildPythonPackage rec {
23 pname = "pot";
24 version = "0.9.3";
25 pyproject = true;
26
27 disabled = pythonOlder "3.6";
28
29 src = fetchFromGitHub {
30 owner = "PythonOT";
31 repo = "POT";
32 rev = "refs/tags/${version}";
33 hash = "sha256-fdqDM0V6zTFe1lcqi53ZZNHAfmuR2I7fdX4SN9qeNn8=";
34 };
35
36 nativeBuildInputs = [
37 cython
38 oldest-supported-numpy
39 ];
40
41 propagatedBuildInputs =
42 [
43 numpy
44 scipy
45 ]
46 ++ lib.optionals enableGPU [ cupy ]
47 ++ lib.optionals enableDimensionalityReduction [
48 autograd
49 pymanopt
50 ];
51
52 nativeCheckInputs = [
53 cvxopt
54 matplotlib
55 numpy
56 tensorflow
57 scikit-learn
58 pytestCheckHook
59 ];
60
61 postPatch = ''
62 substituteInPlace setup.cfg \
63 --replace " --cov-report= --cov=ot" "" \
64 --replace " --durations=20" "" \
65 --replace " --junit-xml=junit-results.xml" ""
66
67 # we don't need setup.py to find the macos sdk for us
68 sed -i '/sdk_path/d' setup.py
69 '';
70
71 # need to run the tests with the built package next to the test directory
72 preCheck = ''
73 pushd build/lib.*
74 ln -s -t . "$OLDPWD/test"
75 '';
76
77 postCheck = ''
78 popd
79 '';
80
81 disabledTests = [
82 # GPU tests are always skipped because of sandboxing
83 "warnings"
84 # Fixture is not available
85 "test_conditional_gradient"
86 "test_convert_between_backends"
87 "test_emd_backends"
88 "test_emd_emd2_types_devices"
89 "test_emd1d_type_devices"
90 "test_emd2_backends"
91 "test_factored_ot_backends"
92 "test_free_support_barycenter_backends"
93 "test_func_backends"
94 "test_generalized_conditional_gradient"
95 "test_line_search_armijo"
96 "test_loss_dual"
97 "test_max_sliced_backend"
98 "test_plan_dual"
99 "test_random_backends"
100 "test_sliced_backend"
101 "test_to_numpy"
102 "test_wasserstein_1d_type_devices"
103 "test_wasserstein"
104 "test_weak_ot_bakends"
105 # TypeError: Only integers, slices...
106 "test_emd1d_device_tf"
107 ];
108
109 disabledTestPaths = lib.optionals (!enableDimensionalityReduction) [ "test/test_dr.py" ];
110
111 pythonImportsCheck = [
112 "ot"
113 "ot.lp"
114 ];
115
116 meta = with lib; {
117 description = "Python Optimal Transport Library";
118 homepage = "https://pythonot.github.io/";
119 license = licenses.mit;
120 maintainers = with maintainers; [ yl3dy ];
121 };
122}