Don't assume transpose makes a copy
#337
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Here I address a range of subtle bugs that were already there and some new ones that got introduced when the TensorKit update happened.
The primary problem is that we shouldn't assume that
transposeor any of its variants produces independent data. Obvious offenders were e.g.qr_compact!(repartition(t, 2, 2)), which isn't guaranteed to not altert.The problem wasn't caught before because in most cases, a copy has to be made anyways (e.g. when there are symmetries involved, or for most array sizes), but after a bug report by @20akshay00 the issue shows itself when working with product states, since there
1xdx1arrays can always trivially be permuted without copies.I hope that I caught all of the cases here, but it's a bit hard to test this in general since some of the algorithms seem to even be somewhat robust against these kinds of issues.