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