1{
2 lib,
3 buildPythonPackage,
4 fetchFromGitHub,
5
6 # build-system
7 cython,
8 setuptools,
9
10 # dependencies
11 autograd,
12 cma,
13 deprecated,
14 dill,
15 matplotlib,
16 numpy,
17 scipy,
18
19 # tests
20 pytestCheckHook,
21 nbformat,
22 notebook,
23 numba,
24 pythonAtLeast,
25 writeText,
26}:
27
28let
29 pymoo_data = fetchFromGitHub {
30 owner = "anyoptimization";
31 repo = "pymoo-data";
32 rev = "33f61a78182ceb211b95381dd6d3edee0d2fc0f3";
33 hash = "sha256-iGWPepZw3kJzw5HKV09CvemVvkvFQ38GVP+BAryBSs0=";
34 };
35in
36buildPythonPackage rec {
37 pname = "pymoo";
38 version = "0.6.1.3";
39 pyproject = true;
40
41 src = fetchFromGitHub {
42 owner = "anyoptimization";
43 repo = "pymoo";
44 tag = version;
45 hash = "sha256-CbeJwv51lu4cABgGieqy/8DCDJCb8wOPPVqUHk8Jb7E=";
46 };
47
48 postPatch = ''
49 substituteInPlace pymoo/util/display/display.py \
50 --replace-fail "from pymoo.util.display.progress import ProgressBar" "" \
51 --replace-fail \
52 "ProgressBar() if progress else None" \
53 "print('Missing alive_progress needed for progress=True!') if progress else None"
54
55 substituteInPlace pymoo/algorithms/soo/nonconvex/es.py \
56 --replace-fail "np.math.ceil" "np.ceil"
57 substituteInPlace pymoo/util/mnn.py \
58 --replace-fail "np.product" "np.prod"
59
60 substituteInPlace pymoo/config.py \
61 --replace-fail \
62 "https://raw.githubusercontent.com/anyoptimization/pymoo-data/main/" \
63 "file://${pymoo_data}/"
64 '';
65
66 pythonRelaxDeps = [ "cma" ];
67 pythonRemoveDeps = [ "alive-progress" ];
68
69 build-system = [
70 setuptools
71 cython
72 ];
73
74 dependencies = [
75 autograd
76 cma
77 deprecated
78 dill
79 matplotlib
80 numpy
81 scipy
82 ];
83
84 preCheck = ''
85 # Some tests require a grad backend to be configured, this is a hacky way to do so.
86 # The choice must be either "jax.numpy" or "autograd.numpy"
87 echo 'from pymoo.gradient import activate; activate("autograd.numpy")' >> tests/conftest.py
88 '';
89 nativeCheckInputs = [
90 pytestCheckHook
91 nbformat
92 notebook
93 numba
94 ];
95 # Select some lightweight tests
96 pytestFlagsArray = [ "-m 'not long'" ];
97 disabledTests =
98 [
99 # ModuleNotFoundError: No module named 'pymoo.cython.non_dominated_sorting'
100 "test_fast_non_dominated_sorting"
101 "test_efficient_non_dominated_sort"
102 "test_dominance_degree_non_dominated_sort"
103
104 # sensitive to float precision
105 "test_cd_and_pcd"
106
107 # TypeError: 'NoneType' object is not subscriptable
108 "test_dascomp"
109 "test_mw"
110 ]
111 ++ lib.optionals (pythonAtLeast "3.13") [
112 # AttributeError: 'ZDT3' object has no attribute 'elementwise'
113 "test_kktpm_correctness"
114 ];
115 disabledTestPaths = [
116 # sensitive to float precision
117 "tests/algorithms/test_no_modfication.py"
118 ];
119 # Avoid crashing sandboxed build on macOS
120 MATPLOTLIBRC = writeText "" ''
121 backend: Agg
122 '';
123
124 pythonImportsCheck = [ "pymoo" ];
125
126 meta = {
127 description = "Multi-objective Optimization in Python";
128 homepage = "https://pymoo.org/";
129 license = lib.licenses.asl20;
130 maintainers = with lib.maintainers; [ veprbl ];
131 };
132}