1{ lib, stdenv, fetchFromGitHub, buildPythonPackage, python, packaging, numpy
2, cython, scipy, matplotlib, pytestCheckHook, pytest-rerunfailures }:
3
4buildPythonPackage rec {
5 pname = "qutip";
6 version = "4.6.2";
7
8 src = fetchFromGitHub {
9 owner = pname;
10 repo = pname;
11 rev = "v${version}";
12 sha256 = "04g7ixq1yrrid4lliqbcamnzyw5r0fjbl8ipklps234hvsjfwmxb";
13 };
14
15 # QuTiP says it needs specific (old) Numpy versions. We overwrite them here
16 # as the tests work perfectly fine with up-to-date packages.
17 postPatch = ''
18 substituteInPlace setup.cfg --replace "numpy>=1.16.6,<1.20" "numpy>=1.16.6"
19 '';
20
21 # Disabling OpenMP support on Darwin.
22 setupPyGlobalFlags = lib.optional (!stdenv.isDarwin) "--with-openmp";
23
24 propagatedBuildInputs = [
25 packaging
26 numpy
27 cython
28 scipy
29 matplotlib
30 ];
31
32 checkInputs = [
33 pytestCheckHook
34 pytest-rerunfailures
35 ];
36
37 # - QuTiP tries to access the home directory to create an rc file for us.
38 # This of course fails and therefore, we provide a writable temp dir as HOME.
39 # - We need to go to another directory to run the tests from there.
40 # This is due to the Cython-compiled modules not being in the correct location
41 # of the source tree.
42 # - For running tests, see:
43 # https://qutip.org/docs/latest/installation.html#verifying-the-installation
44 checkPhase = ''
45 export OMP_NUM_THREADS=$NIX_BUILD_CORES
46 export HOME=$(mktemp -d)
47 mkdir -p test && cd test
48 ${python.interpreter} -c "import qutip.testing; qutip.testing.run()"
49 '';
50
51 meta = with lib; {
52 description = "Open-source software for simulating the dynamics of closed and open quantum systems";
53 homepage = "https://qutip.org/";
54 license = licenses.bsd3;
55 maintainers = [ maintainers.fabiangd ];
56 };
57}