nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{
2 lib,
3 buildPythonPackage,
4 fetchFromGitHub,
5
6 # build-system
7 cython,
8 oldest-supported-numpy,
9 setuptools,
10
11 # dependencies
12 numpy,
13 packaging,
14 scipy,
15
16 # tests
17 pytestCheckHook,
18 pytest-rerunfailures,
19 writableTmpDirAsHomeHook,
20 python,
21
22 # optional-dependencies
23 matplotlib,
24 ipython,
25 cvxopt,
26 cvxpy,
27}:
28
29buildPythonPackage rec {
30 pname = "qutip";
31 version = "5.2.2";
32 pyproject = true;
33
34 src = fetchFromGitHub {
35 owner = "qutip";
36 repo = "qutip";
37 tag = "v${version}";
38 hash = "sha256-Av6OVw3dwZUA13W+5kJ2EwGzIMhNn9lZwEsk5EKTbyk=";
39 };
40
41 postPatch =
42 # build-time constraint, used to ensure forward and backward compat
43 ''
44 substituteInPlace pyproject.toml setup.cfg \
45 --replace-fail "numpy>=2.0.0" "numpy"
46 '';
47
48 build-system = [
49 cython
50 oldest-supported-numpy
51 setuptools
52 ];
53
54 dependencies = [
55 numpy
56 packaging
57 scipy
58 ];
59
60 nativeCheckInputs = [
61 pytestCheckHook
62 pytest-rerunfailures
63 writableTmpDirAsHomeHook
64 ]
65 ++ lib.concatAttrValues 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}