Skip to content

ptrace error with large kets #828

Closed
Closed
@ciri

Description

@ciri

I'm hitting the limit of ints in python, which causes troubles with large ket vectors.

Minimal example (I can go up to size 16 before it crashes):

ket = tensor([basis(2,0) for i in range(0,20)])
ket.ptrace(1)

Returns:

OverflowError                             Traceback (most recent call last)
<ipython-input-22-8485eed3b16f> in <module>()
      1 ket = tensor([basis(2,0) for i in range(0,20)])
----> 2 ket.ptrace(1)

/usr/lib/python2.7/site-packages/qutip-4.3.0.dev0+0b068fc4-py2.7-linux-x86_64.egg/qutip/qobj.pyc in ptrace(self, sel)
   1282         """
   1283         q = Qobj()
-> 1284         q.data, q.dims, _ = _ptrace(self, sel)
   1285         return q.tidyup() if settings.auto_tidyup else q
   1286 

/usr/lib/python2.7/site-packages/qutip-4.3.0.dev0+0b068fc4-py2.7-linux-x86_64.egg/qutip/cy/ptrace.pyx in qutip.cy.ptrace._ptrace()
     89     perm = fast_csr_matrix((data,ind,ptr),shape=(M * M, N * N))
     90     # No need to sort here, will be sorted in reshape
---> 91     rhdata = zcsr_mult(perm, zcsr_reshape(rho.data, np.prod(rho.shape), 1), sorted=0)
     92     rho1_data = zcsr_reshape(rhdata, M, M)
     93     dims_kept0 = np.asarray(rho.dims[0], dtype=np.int32).take(sel)

/usr/lib/python2.7/site-packages/qutip-4.3.0.dev0+0b068fc4-py2.7-linux-x86_64.egg/qutip/cy/spconvert.pyx in qutip.cy.spconvert.zcsr_reshape()
    187 @cython.boundscheck(False)
    188 @cython.wraparound(False)
--> 189 def zcsr_reshape(object A not None, int new_rows, int new_cols):
    190     """
    191     Reshapes a complex CSR matrix.

OverflowError: value too large to convert to int

Similar code works fine in MS LiQui|> using the same workstation so my hardware should be able to support this state size. What is the current ket size limit that is officially supported in qutip? 16?

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions