python-quaec
python-quaec copied to clipboard
Different behaviors of division in python 2 and python 3
Many files in this project uses some sort of division, but didn't do from __future__ import division. As a result, there are some bugs specific to the python version.
For example, in python 2, Pauli.__str__ will try to use the sparse format for very dense Paulis:
>>> q.Pauli('XXXXXXXXXXI')
i^0 XXXXXXXXXXI
>>> str(_)
'i^0 X[0] X[1] X[2] X[3] X[4] X[5] X[6] X[7] X[8] X[9]'
Because in this line, the division is treated as integer division:
if len(self) <= SPARSE_NQ or self.wt/len(self) > SPARSE_THRESH:
On the other hand, in python 3, generic_clifford does not work at all, because this division will return a floating point number:
nq=len(paulis_in)/2
Causing an error to be raised when using nq as a slice index.
Those problems should be fixed by from __future__ import division in both files, and changing the latter instance of / to //.