Qutip error partital trace

355 views
Skip to first unread message

ANANT VIJAY

unread,
Apr 7, 2021, 12:08:19 PM4/7/21
to QuTiP: Quantum Toolbox in Python

Hello everyone,

I am trying to calculate partial trace of a state and tis is what the eoor it is showing:

"
TypeError: 'numpy.float64' object cannot be interpreted as an integer"

My code is just this:

x = np.array(v[:,199])
Qobj(x).ptrace(0)

where v is the vector for which I want to calculate the partial trace.

Regards

Jake Lishman

unread,
Apr 7, 2021, 12:36:10 PM4/7/21
to qu...@googlegroups.com
Hi there,

This is a slight bug in ptrace that's already fixed in the master branch on GitHub, and will be released in QuTiP 4.6 (hopefully soon).  It occurs when you try to call ptrace while keeping _all_ of the dimensions of your object.

In normal use, coming up against this error _probably_ indicates a logic error in your own code (though of course we're fixing our part of the bug) - you're asking ptrace to not actually trace anything out.  In your code here, because you've constructed a Qobj directly from a numpy array, QuTiP doesn't known anything about the tensor structure of your Hilbert space, so you'll never get the partial trace to work correctly.  To do that, you'd need to pass some information to the dims parameter of Qobj; for example if I have 2-qubit density matrix
    dm_numpy = np.random.rand(4, 4)
then when I construct the Qobj, I need to tell QuTiP that it's made of 2 qubits, such as
    dm_qutip = qutip.Qobj(dm_numpy, dims=[[2, 2], [2, 2]])

Now QuTiP knows about both qubits, so I can call dm_qutip.ptrace(0) to trace out the second qubit, and it'll work correctly.

Jake
--
You received this message because you are subscribed to the Google Groups "QuTiP: Quantum Toolbox in Python" group.
To unsubscribe from this group and stop receiving emails from it, send an email to qutip+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/qutip/0d737df9-e053-463c-9663-867a782f1b0cn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages