1{ lib
2, stdenv
3, buildPythonPackage
4, cvxopt
5, cvxpy
6, cython
7, doCheck ? true
8, fetchFromGitHub
9, matplotlib
10, numpy
11, packaging
12, pytest-rerunfailures
13, pytestCheckHook
14, python
15, pythonOlder
16, scipy
17}:
18
19buildPythonPackage rec {
20 pname = "qutip";
21 version = "4.7.0";
22 format = "setuptools";
23
24 disabled = pythonOlder "3.7";
25
26 src = fetchFromGitHub {
27 owner = pname;
28 repo = pname;
29 rev = "v${version}";
30 hash = "sha256-wGr6uTM6pFL2nvN4zdqPdEO8O3kjrRtKWx8luL1t9Sw=";
31 };
32
33 nativeBuildInputs = [
34 cython
35 ];
36
37 propagatedBuildInputs = [
38 numpy
39 packaging
40 scipy
41 ];
42
43 checkInputs = [
44 pytestCheckHook
45 pytest-rerunfailures
46 ] ++ passthru.optional-dependencies.graphics;
47
48 # Disabling OpenMP support on Darwin.
49 setupPyGlobalFlags = lib.optionals (!stdenv.isDarwin) [
50 "--with-openmp"
51 ];
52
53 # QuTiP tries to access the home directory to create an rc file for us.
54 # We need to go to another directory to run the tests from there.
55 # This is due to the Cython-compiled modules not being in the correct location
56 # of the source tree.
57 preCheck = ''
58 export HOME=$(mktemp -d);
59 export OMP_NUM_THREADS=$NIX_BUILD_CORES
60 mkdir -p test && cd test
61 '';
62
63 # For running tests, see https://qutip.org/docs/latest/installation.html#verifying-the-installation
64 checkPhase = ''
65 runHook preCheck
66 ${python.interpreter} -c "import qutip.testing; qutip.testing.run()"
67 runHook postCheck
68 '';
69
70 pythonImportsCheck = [
71 "qutip"
72 ];
73
74 passthru.optional-dependencies = {
75 graphics = [
76 matplotlib
77 ];
78 semidefinite = [
79 cvxpy
80 cvxopt
81 ];
82 };
83
84 meta = with lib; {
85 broken = (stdenv.isLinux && stdenv.isAarch64);
86 description = "Open-source software for simulating the dynamics of closed and open quantum systems";
87 homepage = "https://qutip.org/";
88 license = licenses.bsd3;
89 maintainers = with maintainers; [ fabiangd ];
90 };
91}