about summary refs log tree commit diff
path: root/pkgs/development/python-modules/qutip/default.nix
blob: 8cc5ccba6c30654c48a7067a8eb1695781e9ce08 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
{
  lib,
  buildPythonPackage,
  cvxopt,
  cvxpy,
  cython_0,
  fetchFromGitHub,
  ipython,
  matplotlib,
  numpy,
  oldest-supported-numpy,
  packaging,
  pytest-rerunfailures,
  pytestCheckHook,
  python,
  pythonOlder,
  scipy,
  setuptools,
}:

buildPythonPackage rec {
  pname = "qutip";
  version = "5.0.2";
  pyproject = true;

  disabled = pythonOlder "3.7";

  src = fetchFromGitHub {
    owner = pname;
    repo = pname;
    rev = "refs/tags/v${version}";
    hash = "sha256-lMPzgmUaoEQB5TzmqEJFiFTuS3AGpyMMjPHlPUKTLvk=";
  };

  nativeBuildInputs = [
    cython_0
    setuptools
    oldest-supported-numpy
  ];

  propagatedBuildInputs = [
    numpy
    packaging
    scipy
  ];

  nativeCheckInputs = [
    pytestCheckHook
    pytest-rerunfailures
  ] ++ lib.flatten (builtins.attrValues passthru.optional-dependencies);

  # QuTiP tries to access the home directory to create an rc file for us.
  # We need to go to another directory to run the tests from there.
  # This is due to the Cython-compiled modules not being in the correct location
  # of the source tree.
  preCheck = ''
    export HOME=$(mktemp -d);
    export OMP_NUM_THREADS=$NIX_BUILD_CORES
    mkdir -p test && cd test
  '';

  # For running tests, see https://qutip.org/docs/latest/installation.html#verifying-the-installation
  checkPhase = ''
    runHook preCheck
    ${python.interpreter} -c "import qutip.testing; qutip.testing.run()"
    runHook postCheck
  '';

  pythonImportsCheck = [ "qutip" ];

  passthru.optional-dependencies = {
    graphics = [ matplotlib ];
    ipython = [ ipython ];
    semidefinite = [
      cvxpy
      cvxopt
    ];
  };

  meta = with lib; {
    description = "Open-source software for simulating the dynamics of closed and open quantum systems";
    homepage = "https://qutip.org/";
    changelog = "https://github.com/qutip/qutip/releases/tag/v${version}";
    license = licenses.bsd3;
    maintainers = with maintainers; [ fabiangd ];
  };
}