summaryrefslogtreecommitdiff
path: root/pkgs/development/python-modules/compressai/default.nix
blob: e56ce6e7f05c4043dbb026eaeedc00316f9cf494 (plain)
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
{
  lib,
  stdenv,
  buildPythonPackage,
  fetchFromGitHub,
  pythonAtLeast,

  # build-system
  pybind11,
  setuptools,

  # dependencies
  einops,
  matplotlib,
  numpy,
  pandas,
  pytorch-msssim,
  scipy,
  tomli,
  torch,
  torch-geometric,
  torchvision,
  tqdm,
  typing-extensions,

  # optional-dependencies
  ipywidgets,
  jupyter,

  # tests
  plotly,
  pytestCheckHook,
}:

buildPythonPackage (finalAttrs: {
  pname = "compressai";
  version = "1.2.8";
  pyproject = true;

  src = fetchFromGitHub {
    owner = "InterDigitalInc";
    repo = "CompressAI";
    tag = "v${finalAttrs.version}";
    fetchSubmodules = true;
    hash = "sha256-Fgobh7Q1rKomcqAT4kJl2RsM1W13ErO8sFB2urCqrCk=";
  };

  build-system = [
    pybind11
    setuptools
  ];

  pythonRelaxDeps = [
    "numpy"
  ];
  dependencies = [
    einops
    matplotlib
    numpy
    pandas
    pytorch-msssim
    scipy
    tomli
    torch
    torch-geometric
    torchvision
    tqdm
    typing-extensions
  ];

  optional-dependencies = {
    tutorials = [
      ipywidgets
      jupyter
    ];
  };

  pythonImportsCheck = [
    "compressai"
    "compressai._CXX"
  ];

  # We have to delete the source because otherwise it is used intead the installed package.
  preCheck = ''
    rm -rf compressai
  '';

  nativeCheckInputs = [
    plotly
    pytestCheckHook
  ];

  disabledTests = [
    # Those tests require internet access to download some weights
    "test_image_codec"
    "test_update"
    "test_eval_model_pretrained"
    "test_cheng2020_anchor"
    "test_pretrained"

    # Flaky (AssertionError: assert 0.08889999999999998 < 0.064445)
    "test_compiling"
    "test_find_close"
  ]
  ++ lib.optionals (pythonAtLeast "3.14") [
    # AttributeError: '...' object has no attribute '__annotations__'
    "test_gdn"
    "test_gdn1"
    "test_lower_bound_script"
  ];

  disabledTestPaths = lib.optionals stdenv.hostPlatform.isDarwin [
    # Cause pytest to hang on Darwin after the tests are done
    "tests/test_eval_model.py"
    "tests/test_train.py"

    # fails in sandbox as it tries to launch a web browser (which fails due to missing `osascript`)
    "tests/test_plot.py::test_plot[plotly-ms-ssim-rgb]"
  ];

  meta = {
    description = "PyTorch library and evaluation platform for end-to-end compression research";
    homepage = "https://github.com/InterDigitalInc/CompressAI";
    license = lib.licenses.bsd3Clear;
    maintainers = with lib.maintainers; [ GaetanLepage ];
  };
})