qutip / QuantumToolbox.jl

Quantum Toolbox in Julia
https://qutip.org/QuantumToolbox.jl/dev/
BSD 3-Clause "New" or "Revised" License
38 stars 15 forks source link

Support `permute` to re-order the tensor (Kronecker) product #95

Closed ytdHuang closed 4 months ago

ytdHuang commented 5 months ago

Support the function permute in QuTiP, something like:

function permute(A::QuantumObject, order::Vector{Int}) ... end

a = Qobj(rand(2, 2))
b = Qobj(rand(3, 3))
c = Qobj(rand(4, 4))
d = Qobj(rand(5, 5))
abcd = tensor(a, b, c, d)

permute(abcd, [4, 1, 3, 2]) == tensor(d, a, c, b) # true

Should support for the following types of quantum object:

aarontrowbridge commented 4 months ago

the tensor or kron function, seems to be only defined for Kets, Bras, and Operators, is it still necessary to write methods for the super operators

albertomercurio commented 4 months ago

I can’t figure out what a tensor product between two superoperators should make, physically. So, I think that the definition of tensor product on the superoperators is meaningless

aarontrowbridge commented 4 months ago

It is defined in the qutip permute for these types but i'm not sure how to think about them either atm.

ytdHuang commented 4 months ago

@albertomercurio @aarontrowbridge

There are some rare situations which we want the SuperOperator to be in block matrix form (easier to analyze the dynamics in some specific topics).

Consider a Operator with sub-systems $A$ and $B$ ($\mathcal{H}_A \otimes \mathcal{H}_B$). The Hilbert space of it's corresponding SuperOperator could be written as:

$$\mathcal{H}_A \otimes \mathcal{H}_B \otimes \mathcal{H}_{A'} \otimes \mathcal{H}_{B'}$$

What I have in my mind is some functions that allow me to obtain the SuperOperator with the following Hilbert space order:

$$\mathcal{H}_A \otimes \mathcal{H}_{A'} \otimes \mathcal{H}_B \otimes \mathcal{H}_{B'}$$

But this could actually be done by transferring the SuperOperator back to Operator form, apply the permute, and then transfer it back to SuperOperator type:

A = Qobj(rand(NA, NA))
B = Qobj(rand(NB, NB))
AB = tensor(A, B)
S = spre(AB) # super operator

op1 = Qobj(S, type = Operator, dims = [NA, NB, NA, NB])
op2 = permute(op1, [1, 3, 2, 4])
S_new = Qobj(op2, type = SuperOperator, dims = [NA, NB])

So, yes ! I think for current stage, we can just focus on permute for Ket, Bra, and Operator types of QuantumObject.

aarontrowbridge commented 4 months ago

@ytdHuang thanks for the feedback! I'm in the process of making all of the changes you suggested. I'm in the process of groking what's going on in the ptrace function as it relates to permutations, it is definitely a more elegant approach than mine!