ProjectQ
ProjectQ copied to clipboard
`PendingDeprecationWarning` for `numpy.matrix`
The matrix-class of numpy is currently being deprecated. I therefore get the following warning when running the below example using numpy>=1.15.0:
/path/projectq/ops/_gates.py:57: PendingDeprecationWarning: the matrix subclass is not the recommended way to represent matrices or deal with linear algebra (see https://docs.scipy.org/doc/numpy/user/numpy-for-matlab-users.html). Please adjust your code to use regular ndarray.
return 1. / cmath.sqrt(2.) * np.matrix([[1, 1], [1, -1]])
Example:
import projectQ as pQ
import unittest
class Test(unittest.TestCase):
def test(self):
eng = pQ.MainEngine()
q = eng.allocate_qubit()[0]
pQ.ops.H | q
pQ.ops.Measure | q
eng.flush()
print(int(q))
Yes, we currently suppress this warning https://github.com/ProjectQ-Framework/ProjectQ/blob/develop/pytest.ini#L6
The idea was waiting until Python2.7 is depricated so that everyone switches to Python3.5+ which allows to use @ for matrix multiplications (for which we currently can use * by using numpy.matrix)...
But I don't mind from changing already before, e.g., in the context of #282
Any thoughts?
An option would be to use numpy.dot instead of @ if you don't want to wait for Python2.7 to be deprecated.