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.
This is an attempt to properly tackle storagetypes, and to expand some methods to allow for less concrete types.
The main issue that sparked this is QuantumKitHub/MPSKit.jl#376, where the blocktensors of an MPO contain
Union{BraidingTensor,TensorMap}aseltype, and therefore give issues when determining thestoragetype.I was aware of this issue, and had resolved it with an evil hack, however as with most evil hacks, this at some point breaks because of small changes.
In this case, the recent change to add a method in TensorKit
storagetype(t) = storagetype(typeof(t))seemed to have bypassed my evil hack (which was utter and complete type piracy), therefore leading to linked issue.The context is that in a sparse blocktensormap of a given element type, I need to be able to instantiate a zero tensor of that given type, and I would really like to keep the option of not having fully specified types as element types, such as the union of braidingtensor and regular tensormaps.
Currently,
similar(::Type{<:AbstractTensorMap}, space)is defined in the type domain, but this ends up callingstoragetype, which is where the error comes from.Therefore I changed the
storagetypedefinition here to have the following fallback behavior:<:AbstractTensorMap, I simply fall back to the default storagetype that is used in e.g.zeros(space), given bysimilarstoragetype(scalartype(t)) = Vector{T}. This is consistent with the previous fallback definition forstoragetype(BraidingTensor), which I therefore removedUniontypes, I try to promote the storagetypes of the components, similar to how contraction or addition would try to do that.This latter promotion system already had most of its skeleton in place, but still needed the actual promotion rules etc, similar to how
base/promotion.jldefines this in Julia Base.I copied over some of that, such that now this should also be easily extensible to GPU and CPU mixes, where we may define conversion types appropriately.
I have not defined any promotion rules in this PR since I don't actually know what the best definition would be though.
I'd be glad to hear some suggestions as to how to test this, but I did run the MPSKit testsuite on top of this and this does seem to resolve the issue.