1{
2 lib,
3 stdenv,
4 buildPythonPackage,
5 fetchFromGitHub,
6
7 # build-system
8 cython_0,
9 oldest-supported-numpy,
10 setuptools,
11
12 # dependencies
13 numpy,
14 packaging,
15 scipy,
16
17 # tests
18 pytestCheckHook,
19 pytest-rerunfailures,
20 writableTmpDirAsHomeHook,
21 python,
22
23 # optional-dependencies
24 matplotlib,
25 ipython,
26 cvxopt,
27 cvxpy,
28}:
29
30buildPythonPackage rec {
31 pname = "qutip";
32 version = "5.1.1";
33 pyproject = true;
34
35 src = fetchFromGitHub {
36 owner = "qutip";
37 repo = "qutip";
38 tag = "v${version}";
39 hash = "sha256-5j47Wqt9i6vC3uwRzQ9+8pk+ENl5w6PvnP+830RLCls=";
40 };
41
42 postPatch =
43 # build-time constraint, used to ensure forward and backward compat
44 ''
45 substituteInPlace pyproject.toml setup.cfg \
46 --replace-fail "numpy>=2.0.0" "numpy"
47 '';
48
49 build-system = [
50 cython_0
51 oldest-supported-numpy
52 setuptools
53 ];
54
55 dependencies = [
56 numpy
57 packaging
58 scipy
59 ];
60
61 nativeCheckInputs = [
62 pytestCheckHook
63 pytest-rerunfailures
64 writableTmpDirAsHomeHook
65 ] ++ lib.flatten (builtins.attrValues optional-dependencies);
66
67 # QuTiP tries to access the home directory to create an rc file for us.
68 # We need to go to another directory to run the tests from there.
69 # This is due to the Cython-compiled modules not being in the correct location
70 # of the source tree.
71 preCheck = ''
72 export OMP_NUM_THREADS=$NIX_BUILD_CORES
73 mkdir -p test && cd test
74 '';
75
76 # For running tests, see https://qutip.org/docs/latest/installation.html#verifying-the-installation
77 checkPhase = ''
78 runHook preCheck
79 ${python.interpreter} -c "import qutip.testing; qutip.testing.run()"
80 runHook postCheck
81 '';
82
83 pythonImportsCheck = [ "qutip" ];
84
85 optional-dependencies = {
86 graphics = [ matplotlib ];
87 ipython = [ ipython ];
88 semidefinite = [
89 cvxopt
90 cvxpy
91 ];
92 };
93
94 meta = {
95 description = "Open-source software for simulating the dynamics of closed and open quantum systems";
96 homepage = "https://qutip.org/";
97 changelog = "https://github.com/qutip/qutip/releases/tag/${src.tag}";
98 license = lib.licenses.bsd3;
99 maintainers = with lib.maintainers; [ fabiangd ];
100 badPlatforms = [
101 # Tests fail at ~80%
102 # ../tests/test_animation.py::test_result_state Fatal Python error: Aborted
103 lib.systems.inspect.patterns.isDarwin
104
105 # Several tests fail with a segfault
106 # ../tests/test_random.py::test_rand_super_bcsz[int-CSR-choi-None-rep(1)] Fatal Python error: Aborted
107 "aarch64-linux"
108 ];
109 };
110}