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

  # build-system
  setuptools,

  # dependencies
  jax,
  jaxlib,
  multipledispatch,
  numpy,
  tqdm,

  # tests
  dm-haiku,
  equinox,
  flax,
  funsor,
  graphviz,
  optax,
  pyro-api,
  pytest-xdist,
  pytestCheckHook,
  scikit-learn,
  tensorflow-probability,
}:

buildPythonPackage rec {
  pname = "numpyro";
  version = "0.19.0";
  pyproject = true;

  src = fetchFromGitHub {
    owner = "pyro-ppl";
    repo = "numpyro";
    tag = version;
    hash = "sha256-3kzaINsz1Mjk97ERQsQIYIBz7CVmXtVDn0edJFMHQWs=";
  };

  build-system = [ setuptools ];

  dependencies = [
    jax
    jaxlib
    multipledispatch
    numpy
    tqdm
  ];

  nativeCheckInputs = [
    dm-haiku
    equinox
    flax
    funsor
    graphviz
    optax
    pyro-api
    pytest-xdist
    pytestCheckHook
    scikit-learn
    tensorflow-probability
  ];

  pythonImportsCheck = [ "numpyro" ];

  pytestFlags = [
    # Tests memory consumption grows significantly with the number of parallel processes (reaches ~200GB with 80 jobs)
    "--maxprocesses=8"

    # A few tests fail with:
    # UserWarning: There are not enough devices to run parallel chains: expected 2 but got 1.
    # Chains will be drawn sequentially. If you are running MCMC in CPU, consider using `numpyro.set_host_device_count(2)` at the beginning of your program.
    # You can double-check how many devices are available in your system using `jax.local_device_count()`.
    "-Wignore::UserWarning"

    # FutureWarning: In the future `np.object` will be defined as the corresponding NumPy scalar.
    "-Wignore::FutureWarning"
  ];

  disabledTests = [
    # ValueError: Found unexpected Arrays on value of type <class 'list'> in static attribute 'layers'
    # of Pytree type '<class 'test_module.test_random_nnx_module_mcmc_sequence_params.<locals>.MLP'>'.
    # This is an error starting from Flax version 0.12.0.
    "test_random_nnx_module_mcmc_sequence_param"

    # AssertionError, assert GLOBAL["count"] == 4 (assert 5 == 4)
    "test_mcmc_parallel_chain"

    # AssertionError due to tolerance issues
    "test_bijective_transforms"
    "test_cpu"
    "test_entropy_categorical"
    "test_gaussian_model"

    # >       with pytest.warns(UserWarning, match="Hessian of log posterior"):
    # E       Failed: DID NOT WARN. No warnings of type (<class 'UserWarning'>,) were emitted.
    # E        Emitted warnings: [].
    "test_laplace_approximation_warning"

    # ValueError: compiling computation that requires 2 logical devices, but only 1 XLA devices are available (num_replicas=2)
    "test_chain"
  ]
  ++ lib.optionals stdenv.hostPlatform.isDarwin [
    # AssertionError: Not equal to tolerance rtol=0.06, atol=0
    "test_functional_map"
  ];

  disabledTestPaths = [
    # Require internet access
    "test/test_example_utils.py"
  ];

  meta = {
    description = "Library for probabilistic programming with NumPy";
    homepage = "https://num.pyro.ai/";
    changelog = "https://github.com/pyro-ppl/numpyro/releases/tag/${version}";
    license = lib.licenses.asl20;
    maintainers = with lib.maintainers; [ fab ];
  };
}