about summary refs log tree commit diff
path: root/pkgs/development/python-modules/pot/default.nix
blob: 9d361a3ff11c07a89b0fb4de1208d7d98429ee61 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
{
  lib,
  autograd,
  buildPythonPackage,
  fetchFromGitHub,
  cvxopt,
  cython,
  jax,
  jaxlib,
  matplotlib,
  numpy,
  pymanopt,
  pytestCheckHook,
  pythonOlder,
  scikit-learn,
  scipy,
  setuptools,
  tensorflow,
  torch,
}:

buildPythonPackage rec {
  pname = "pot";
  version = "0.9.4";
  pyproject = true;

  disabled = pythonOlder "3.6";

  src = fetchFromGitHub {
    owner = "PythonOT";
    repo = "POT";
    rev = "refs/tags/${version}";
    hash = "sha256-Yx9hjniXebn7ZZeqou0JEsn2Yf9hyJSu/acDlM4kCCI=";
  };

  build-system = [
    setuptools
    cython
    numpy
  ];

  dependencies = [
    numpy
    scipy
  ];

  optional-dependencies = {
    backend-numpy = [ ];
    backend-jax = [
      jax
      jaxlib
    ];
    backend-cupy = [ ];
    backend-tf = [ tensorflow ];
    backend-torch = [ torch ];
    cvxopt = [ cvxopt ];
    dr = [
      scikit-learn
      pymanopt
      autograd
    ];
    gnn = [
      torch
      # torch-geometric
    ];
    plot = [ matplotlib ];
    all =
      with optional-dependencies;
      (
        backend-numpy
        ++ backend-jax
        ++ backend-cupy
        ++ backend-tf
        ++ backend-torch
        ++ optional-dependencies.cvxopt
        ++ dr
        ++ gnn
        ++ plot
      );
  };

  nativeCheckInputs = [ pytestCheckHook ];

  postPatch = ''
    substituteInPlace setup.cfg \
      --replace " --cov-report= --cov=ot" "" \
      --replace " --durations=20" "" \
      --replace " --junit-xml=junit-results.xml" ""

    substituteInPlace pyproject.toml \
      --replace-fail "numpy>=2.0.0" "numpy"

    # we don't need setup.py to find the macos sdk for us
    sed -i '/sdk_path/d' setup.py
  '';

  # need to run the tests with the built package next to the test directory
  preCheck = ''
    pushd build/lib.*
    ln -s -t . "$OLDPWD/test"
  '';

  postCheck = ''
    popd
  '';

  disabledTests = [
    # GPU tests are always skipped because of sandboxing
    "warnings"
    # Fixture is not available
    "test_conditional_gradient"
    "test_convert_between_backends"
    "test_emd_backends"
    "test_emd_emd2_types_devices"
    "test_emd1d_type_devices"
    "test_emd2_backends"
    "test_factored_ot_backends"
    "test_free_support_barycenter_backends"
    "test_func_backends"
    "test_generalized_conditional_gradient"
    "test_line_search_armijo"
    "test_loss_dual"
    "test_max_sliced_backend"
    "test_plan_dual"
    "test_random_backends"
    "test_sliced_backend"
    "test_to_numpy"
    "test_wasserstein_1d_type_devices"
    "test_wasserstein"
    "test_weak_ot_bakends"
    # TypeError: Only integers, slices...
    "test_emd1d_device_tf"
  ];

  pythonImportsCheck = [
    "ot"
    "ot.lp"
  ];

  meta = with lib; {
    description = "Python Optimal Transport Library";
    homepage = "https://pythonot.github.io/";
    license = licenses.mit;
    maintainers = with maintainers; [ yl3dy ];
  };
}