CombineBond() and Permute() do not work together properly when Bonds have Qnums
Summary
This problem was originally pointed out by @rezah back on the old v1 Github. When the bonds of a UniTensor have Z2 quantum numbers, the operations of CombineBond() and Permute() do not commute. So if a UniTensor is initialized with symmetric bonds, then permuted, then some bonds are combined, the result is a tensor T1. If instead that tensor is first "CombineBonded" and then permuted such that an identical result is expected, the resulting tensor T2 is not the same as T1. If all the bonds only contain PRT_EVEN Qnums, this problem goes away.
This problem was patched in v1, but the solution was extremely expensive (essentially making the function unable to be used if it is in a critical subroutine of the code). It seems the problem has reappeared in v2. For a current project that @rezah and myself are working on, a reasonably fast CombineBond() function is essential; and in general it is very challenging to write any finite PEPS code without relying heavily on CombineBond().
Steps to reproduce
Here are a few tiny scripts to illuminate the problem:
Behavior of the patched v1 code (correct behavior): qnum_combine1_v1.py
Behavior of the v2 code (I think the same as the original broken v1 code?): qnum_combine1.py
Recovery of expected result in v2 when all Qnums are PRT_EVEN: qnum_combine1_nosym.py
What is the current bug behavior?
The two printed tensors in the second script above are different from each other, while the two tensors in scripts 1 and 3 are identical.
What is the expected correct behavior?
The 2 printed tensors in script 2 should also be identical.
It's possible that the test in these scripts is a strange corner case, but I believe it is not an ill-posed test (as in, I think permuting bonds from out-->in is well-defined for Z2 symmetric bonds).