TestDicke fails with scipy 1.6.1: TypeError: can't convert complex to float
See original GitHub issueSome TestDicke tests in test_piqs.py
(test_lindbladian, test_lindbladian_dims, test_liouvillian) fail with the recent scipy 1.6.1 release. They were previously passing with scipy 1.6.0.
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
.
Your Environment
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()`
Issue Analytics
- State:
- Created 3 years ago
- Comments:9 (9 by maintainers)
Top Results From Across the Web
SciPy Can't Convert Complex to Float - Stack Overflow
Evidently the error is the result of trying to build a larger array from a mix of scalar(s) and arrays, one of which...
Read more >[SciPy-user] TypeError: can't convert complex to float; use abs(z)
Hi,guys. I encountered this error message in other place,then I simplify the code and paste it and the output messages in the end...
Read more >Complex floating issue - Python Forum
You have to chose the right data type. Use numpy.complex128 as dtype . The real part is a 64 bit float and the...
Read more >Untitled
The change also fixes bug 523913 - Added COPYING file to the package - Removed ping interval change from ypbind-mt-1.20.4-log-binds.patch Resolves #594693 ...
Read more >Python for Programmers
includes testdrives of the IPython interpreter and Jupyter Notebooks. C hapter 2, Introduction to Python Programming, presents Python programming.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
No worries, I’ll stick with just piq.pyx then.
Numpy interprets the Python base type
complex
as equal tonp.complex128
when passed as a dtype. Personally I thinknp.complex128
is much clearer (since it specifies the size in the name too), but I wouldn’t worry too much about changing everything everywhere.cqobjevo.pyx
in particular is going to be nearly entirely rewritten in the next major QuTiP release anyway.