Bug#983397: qutip: TestDicke fails with scipy 1.6.1: TypeError: can't convert complex to float

Drew Parsons dparsons at debian.org
Tue Feb 23 14:08:32 GMT 2021


Source: qutip
Version: 4.5.2-1
Severity: normal
Control: forwarded -1 https://github.com/qutip/qutip/issues/1451
Control: affects -1 src:scipy

Some TestDicke tests in test_piqs.py (test_lindbladian,
test_lindbladian_dims, test_liouvillian) fail with the
recent scipy 1.6.1 release, (scipy 1.6.1-1 is uploaded to
experimental). They were previously passing with scipy 1.6.0.

It's probably relevant that scipy 1.6.1 fixed some problems with
sparse matrices (with COO format constructor), see
https://docs.scipy.org/doc/scipy-1.6.1/reference/release.1.6.1.html
including PR#13403 https://github.com/scipy/scipy/pull/13403


To Reproduce

$  cp -r qutip/tests/  /tmp/qutip
$  cd /tmp/qutip
$  pytest-3 -v -k "TestDicke"


The test error message from TestDicke.test_lindbladian is

___________________________________________________________________________________________ TestDicke.test_lindbladian ____________________________________________________________________________________________

self = <tests.test_piqs.TestDicke object at 0x7f55475a0c10>

    def test_lindbladian(self):
        """
        PIQS: Test the generation of the Lindbladian matrix.
        """
        N = 1
        gCE = 0.5
        gCD = 0.5
        gCP = 0.5
        gE = 0.1
        gD = 0.1
        gP = 0.1
    
        system = Dicke(
            N=N,
            emission=gE,
            pumping=gP,
            dephasing=gD,
            collective_emission=gCE,
            collective_pumping=gCP,
            collective_dephasing=gCD,
        )
    
>       lindbladian = system.lindbladian()

tests/test_piqs.py:450: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/usr/lib/python3/dist-packages/qutip/piqs.py:509: in lindbladian
    return cythonized_dicke.lindbladian()
qutip/cy/piqs.pyx:313: in qutip.cy.piqs.Dicke.lindbladian
    ???
qutip/cy/piqs.pyx:431: in qutip.cy.piqs.Dicke.lindbladian
    ???
/usr/lib/python3/dist-packages/scipy/sparse/compressed.py:54: in __init__
    other = self.__class__(coo_matrix(arg1, shape=shape,
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <[AttributeError('dtype not found') raised in repr()] coo_matrix object at 0x7f55475a0ca0>
arg1 = ([(-0.6000000238418579+0j), (0.6000000238418579+0j), (-0.9000000357627869+0j), (-0.9000000357627869+0j), (-0.6000000238418579+0j), (0.6000000014901161+0j)], ([3, 3, 2, 1, 0, 0], [3, 0, 2, 1, 0, 3]))
shape = (4, 4), dtype = None, copy = False

    def __init__(self, arg1, shape=None, dtype=None, copy=False):
        _data_matrix.__init__(self)
    
        if isinstance(arg1, tuple):
            if isshape(arg1):
                M, N = arg1
                self._shape = check_shape((M, N))
                idx_dtype = get_index_dtype(maxval=max(M, N))
                data_dtype = getdtype(dtype, default=float)
                self.row = np.array([], dtype=idx_dtype)
                self.col = np.array([], dtype=idx_dtype)
                self.data = np.array([], dtype=data_dtype)
                self.has_canonical_format = True
            else:
                try:
                    obj, (row, col) = arg1
                except (TypeError, ValueError) as e:
                    raise TypeError('invalid input format') from e
    
                if shape is None:
                    if len(row) == 0 or len(col) == 0:
                        raise ValueError('cannot infer dimensions from zero '
                                         'sized index arrays')
                    M = operator.index(np.max(row)) + 1
                    N = operator.index(np.max(col)) + 1
                    self._shape = check_shape((M, N))
                else:
                    # Use 2 steps to ensure shape has length 2.
                    M, N = shape
                    self._shape = check_shape((M, N))
    
                idx_dtype = get_index_dtype(maxval=max(self.shape))
                data_dtype = getdtype(dtype, obj, default=float)
                self.row = np.array(row, copy=copy, dtype=idx_dtype)
                self.col = np.array(col, copy=copy, dtype=idx_dtype)
>               self.data = np.array(obj, copy=copy, dtype=data_dtype)
E               TypeError: can't convert complex to float

/usr/lib/python3/dist-packages/scipy/sparse/coo.py:161: TypeError

Likewise for TestDicke.test_lindbladian_dims and TestDicke.test_liouvillian.


Test fails also with qutip 4.5.3 built on Debian unstable.

qutip.about()

QuTiP: Quantum Toolbox in Python
================================
Copyright (c) QuTiP team 2011 and later.
Current admin team: Alexander Pitchford, Nathan Shammah, Shahnawaz Ahmed, Neill Lambert, Eric Giguère, Boxi Li and Jake Lishman.
Board members: Daniel Burgarth, Robert Johansson, Anton F. Kockum, Franco Nori and Will Zeng.
Original developers: R. J. Johansson & P. D. Nation.
Previous lead developers: Chris Granade & A. Grimsmo.
Currently developed through wide collaboration. See https://github.com/qutip for details.

QuTiP Version:      4.5.3
Numpy Version:      1.19.5
Scipy Version:      1.6.1
Cython Version:     0.29.21
Matplotlib Version: 3.3.4
Python Version:     3.9.1
Number of CPUs:     4
BLAS Info:          OPENBLAS
OPENMP Installed:   True
INTEL MKL Ext:      False
Platform Info:      Linux (x86_64)
Installation path:  /usr/lib/python3/dist-packages/qutip
================================================================================
Please cite QuTiP in your publication.
================================================================================
For your convenience a bibtex reference can be easily generated using `qutip.cite()`



-- System Information:
Debian Release: bullseye/sid
  APT prefers unstable
  APT policy: (500, 'unstable'), (1, 'experimental')
Architecture: amd64 (x86_64)
Foreign Architectures: i386

Kernel: Linux 5.10.0-3-amd64 (SMP w/8 CPU threads)
Kernel taint flags: TAINT_PROPRIETARY_MODULE, TAINT_OOT_MODULE
Locale: LANG=en_AU.UTF-8, LC_CTYPE=en_AU.UTF-8 (charmap=UTF-8), LANGUAGE=en_AU:en
Shell: /bin/sh linked to /usr/bin/dash
Init: systemd (via /run/systemd/system)
LSM: AppArmor: enabled


More information about the debian-science-maintainers mailing list