Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ptrace error with large kets #828

Closed
ciri opened this issue Feb 26, 2018 · 3 comments
Closed

ptrace error with large kets #828

ciri opened this issue Feb 26, 2018 · 3 comments
Assignees

Comments

@ciri
Copy link

ciri commented Feb 26, 2018

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?

@nonhermitian
Copy link
Member

There is no official size limit. The code probably just needs int64 support.

@ciri
Copy link
Author

ciri commented Feb 28, 2018

I spent some time looking into patching this last night, but it seems like it would require a complete overhaul of many parts of the code so not an easy fix unfortunately. Perhaps this is something to put on the todo/request list, because without this, most ML QIP research that I've been looking at would not be implementable (need around 10-20 qubits, just a 2 qubit QRAM already requires 11 working qubits).

@Ericgig
Copy link
Member

Ericgig commented Jul 12, 2019

From 4.4.0, ptrace works up to 31Qbit

@Ericgig Ericgig closed this as completed Jul 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants