Repository navigation
Fix tensor map subtype bounds - #593
Conversation
|
Hmmm, this honestly looks like something that Julia itself might be fixing in the near future. I recall doing this more or less on purpose, such that the bounds are defined in a single place instead of for every type, which can be useful if we ever have to change them, and the weird thing is that I think you can never instantiate a TensorMap with a non-Number element type... Considering your usecase, that looks like a bit of a strange definition of the type alias to begin with, and I think for inference purposes it is probably better to immediately instantiate these as either |
|
In the PEPSKit case, sometimes an MPO with mixed scalar type can be constructed. A simple example is [real(S_x), S_y] with two sites connected by a trivial leg (suppose we keep this leg for test purposes). This thing fails to be recognized as |
|
I think the idea is to make that explicitly |
Codecov Report✅ All modified and coverable lines are covered by tests.
... and 15 files with indirect coverage changes 🚀 New features to boost your workflow:
|
|
Promoting everything to the same scalar type makes sense, and this is now done on the PEPSKit side. This allows us to keep our type alias as is for now, so that's kind of decoupled from this now. Still I think the suggestions here might make sense in their own right. I find For context, I can give some motivation for the choice of the type alias and how this came up:
|
lkdvos
left a comment
There was a problem hiding this comment.
Sorry to be a bit late with my reply on this:
I think for the specific case of MPOTerm as a type alias, my intuition seems to point at dispatch just not being the right abstraction for that job. Do you even need to specify the type, can you not just assume that it is some container with tensors inside? Otherwise this issue will probably persist, it seems like depending on heuristics of Julia deciding when to figure out it will start widening to keep AbstractTensorMap vs when to just do Any is not the best long-term solution. For example, I can imagine something like this:
terms = []
for _ in _
push!(terms, ...)
endwhich resolves as Vector{Any}.
If you really do need to use dispatch on it for the surrounding code, I'd actually say that would be a good argument in favor of having an actual struct defined for this. If the struct feels to clunky, another approach could just be to define new function names for the various input types.
With respect to this PR specifically, ultimately it really doesn't matter that much, and in principle I'm happy to merge as-is. I left some minor comments but otherwise good to go.
| #==========================================================# | ||
| """ | ||
| struct AdjointTensorMap{T, S, N₁, N₂, TT<:AbstractTensorMap} <: AbstractTensorMap{T, S, N₁, N₂} | ||
| struct AdjointTensorMap{T<:Number, S<:IndexSpace, N₁, N₂, TT<:AbstractTensorMap} <: AbstractTensorMap{T, S, N₁, N₂} |
There was a problem hiding this comment.
I know that we aren't super consistent with this, but I've been gradually migrating more of the docstrings to have the same formatting style as the surrounding code, i.e. the runic T <: Number with spaces around <:. No strong opinions about this though, so if you have some time I'd say to update this, but otherwise just leaving it as-is is definitely also fine.
Fix missing type parameter bounds that caused
TensorMap <: AbstractTensorMapto returnfalse.Add
T <: Numberto all four concrete tensor map types, plus the missingS <: IndexSpacebounds onAdjointTensorMapandBraidingTensor. Add regression coverage for unparameterized types and types with real or complex scalar parameters.Background
I bumped into this in QuantumKitHub/PEPSKit.jl#425. There we define
However, if a vector of TensorMaps contains mixed scalar types (e.g. a Float64 tensor and a ComplexF64 tensor) as well as different in/out number of legs, then the vector fails to be recognized as an
MPOTerm, because the inferredTisAny: