Skip to content

Conversation

@lkdvos
Copy link
Member

@lkdvos lkdvos commented Feb 9, 2026

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} as eltype, and therefore give issues when determining the storagetype.
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 calling storagetype, which is where the error comes from.

Therefore I changed the storagetype definition here to have the following fallback behavior:

  • For <:AbstractTensorMap, I simply fall back to the default storagetype that is used in e.g. zeros(space), given by similarstoragetype(scalartype(t)) = Vector{T}. This is consistent with the previous fallback definition for storagetype(BraidingTensor), which I therefore removed
  • For Union types, 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.jl defines 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.

@lkdvos lkdvos requested review from Jutho and kshyatt and removed request for kshyatt February 9, 2026 19:35
@codecov
Copy link

codecov bot commented Feb 9, 2026

Codecov Report

❌ Patch coverage is 42.50000% with 23 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/tensors/abstracttensor.jl 25.92% 20 Missing ⚠️
src/tensors/braidingtensor.jl 50.00% 3 Missing ⚠️
Files with missing lines Coverage Δ
src/tensors/diagonal.jl 92.07% <100.00%> (-0.08%) ⬇️
src/tensors/linalg.jl 82.59% <100.00%> (-0.06%) ⬇️
src/tensors/tensor.jl 85.39% <100.00%> (-0.09%) ⬇️
src/tensors/tensoroperations.jl 97.42% <100.00%> (-0.04%) ⬇️
src/tensors/braidingtensor.jl 70.12% <50.00%> (-0.95%) ⬇️
src/tensors/abstracttensor.jl 55.34% <25.92%> (-3.31%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant