Hi Miles,

I'm trying to use the diagHermitian function. As a test I ran the following code:

auto sx = sites.op("Sx",1);
auto sz = sites.op("Sz",1);
IQTensor U,D,U3,D3;
diagHermitian(sx,U,D);
PrintData(D);
diagHermitian(sz,U3,D3);
PrintData(D3);


While the result of sz is +/- 0.5, as expected, for sx I get +/+ 0.5. I also use PrintData to obtain the matrix element, see below. Apparently something is wrong here. I think this may have something to do with the QN system I define. What do you think about this? Thanks!

Best,
Chengshu

sx =
/--------------IQTensor--------------
r=2 div=QN({1,2}) log(scale)=0
IQIndex(S=1/2 1,2,Site|506)
(Up 1,1,Site|592) QN({1,2})
(Dn 1,1,Site|655) QN({0,2})

IQIndex(S=1/2 1,2,Site|506)'
(Up 1,1,Site|592)' QN({1,2})
(Dn 1,1,Site|655)' QN({0,2})

|-- Data -------
QDense Real {2 blocks; data size 2}
(Dn 1,1,Site|655) (Up 1,1,Site|592)'
(2,1) 0.5000000
(Up 1,1,Site|592) (Dn 1,1,Site|655)'
(1,2) 0.5000000

------------------------------------

D =
/--------------IQTensor--------------
r=2 div=QN({0,2}) log(scale)=0

|-- Data -------
QDiagReal
(1,1) 0.5000000
(2,2) 0.5000000

------------------------------------

commented May 18 by (650 points)
Also, if one uses the "Sx" operator in SpinHalf.h, it will throw an error message as "doTask not defined for task Contract and storage types QMixed<Real> QCombiner". Here the symmetry is Z_2 instead of U(1) so it has a well defined QN.

answered May 18 by (16,560 points)

Hi Chengshu,
The Sx operator is not compatible with the requirements for IQTensors. (The non-zero blocks of IQTensors have to all have the same "quantum number flux" i.e. change the total quantum number by a fixed amount when acting on a wavefunction in the case of operators.)

So the issues you're seeing above are related to trying to use the Sx operator in an IQTensor context. You just aren't allowed to do it. If it seems to be partially working in the first case, i.e. diagHermitian is letting you plug sx in as the first argument with U,D defined as IQTensors then either you would get an error message if you were running in debug mode or I need to put a new check there that throws an error message.

Miles

commented May 18 by (650 points)
Hi Miles,

Thanks for the quick reply. Here I'm using a Z_2 QN system, so I expect that the non-zero blocks of Sx operator do have the same "QN flux". (basically s+ & s- both have QN {1,2}.)

Best,
Chengshu
commented May 18 by (16,560 points)
I see - interesting. So are you using a custom site set or one of the standard SpinHalf or SpinOne site sets?
commented May 18 by (650 points)
I'm using a modified SpinHalf with a custom QN system.
commented May 18 by (16,560 points)
I see: you're using a custom one. I didn't read your question carefully enough.

I think one aspect of the issues your seeing is that you shouldn't use the Mixed IQTensor feature for Sx for your site set. That's only a workaround for site sets where Sx isn't a proper IQTensor. Since it is a proper IQTensor for your site set you should just make Sx the same way that you make Sz (using similar code but just with different matrix elements of course).
commented May 18 by (650 points)
Yes I did comment out the mixedIQTensor part.
commented May 18 by (16,560 points)
Oh, I was confused then by the comment on your question. But I see now that was in reference to the SpinHalf site set.

Ok so I took a closer look at it appears that the current diagHermitian is limited to the case of only block-diagonal IQTensors (Hermitian IQTensors with total flux zero). So it's naively treating the blocks of Sx separately as 1x1 Hermitian matrices and diagonalizing them individually which is what's causing the funny output you're seeing. If you had run the code in debug mode, you would have seen a different error noting this limitation of diagHermitian (though with a kind of cryptic error message). In the future please do always run your code in debug mode if you are getting errors to see if you get a more helpful error message.

I will think about what can be done to make diagHermitian apply to your case. It might be kind of tricky to do - not sure.
commented May 18 by (16,560 points)
Thanks for reporting this. It's very helpful to think about. Hopefully there's a simple resolution but it's not obvious to me right at the moment how to fix it.
commented May 18 by (650 points)
Thanks for the comments. For now I will use
diagHermitian(toITensor(sx),U,D)
which gives the correct result.
commented May 18 by (16,560 points)
Ok thanks. That's a good workaround for now in the sense that it ought to give correct results at least. I'll be thinking about if we can generalize diagHermitian for the general Hermitian IQTensor case without making it excessively complicated.