···11+{ lib, stdenv, fetchFromGitHub, buildPythonPackage, python, packaging, numpy
22+, cython, scipy, matplotlib, pytestCheckHook, pytest-rerunfailures }:
33+44+buildPythonPackage rec {
55+ pname = "qutip";
66+ version = "4.6.2";
77+88+ src = fetchFromGitHub {
99+ owner = pname;
1010+ repo = pname;
1111+ rev = "v${version}";
1212+ sha256 = "04g7ixq1yrrid4lliqbcamnzyw5r0fjbl8ipklps234hvsjfwmxb";
1313+ };
1414+1515+ # QuTiP says it needs specific (old) Numpy versions. We overwrite them here
1616+ # as the tests work perfectly fine with up-to-date packages.
1717+ postPatch = ''
1818+ substituteInPlace setup.cfg --replace "numpy>=1.16.6,<1.20" "numpy>=1.16.6"
1919+ '';
2020+2121+ # Disabling OpenMP support on Darwin.
2222+ setupPyGlobalFlags = lib.optional (!stdenv.isDarwin) "--with-openmp";
2323+2424+ propagatedBuildInputs = [
2525+ packaging
2626+ numpy
2727+ cython
2828+ scipy
2929+ matplotlib
3030+ ];
3131+3232+ checkInputs = [
3333+ pytestCheckHook
3434+ pytest-rerunfailures
3535+ ];
3636+3737+ # - QuTiP tries to access the home directory to create an rc file for us.
3838+ # This of course fails and therefore, we provide a writable temp dir as HOME.
3939+ # - We need to go to another directory to run the tests from there.
4040+ # This is due to the Cython-compiled modules not being in the correct location
4141+ # of the source tree.
4242+ # - For running tests, see:
4343+ # https://qutip.org/docs/latest/installation.html#verifying-the-installation
4444+ checkPhase = ''
4545+ export OMP_NUM_THREADS=$NIX_BUILD_CORES
4646+ export HOME=$(mktemp -d)
4747+ mkdir -p test && cd test
4848+ ${python.interpreter} -c "import qutip.testing; qutip.testing.run()"
4949+ '';
5050+5151+ meta = with lib; {
5252+ description = "Open-source software for simulating the dynamics of closed and open quantum systems";
5353+ homepage = "https://qutip.org/";
5454+ license = licenses.bsd3;
5555+ maintainers = [ maintainers.fabiangd ];
5656+ };
5757+}