Skip to content

Different behaviors of division in python 2 and python 3 #11

Description

@bbbbbbbbba

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 //.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions