More tweaks#375
Conversation
3bed38d to
8665c4a
Compare
eabfce9 to
0c903ac
Compare
Codecov Report❌ Patch coverage is
... and 43 files with indirect coverage changes 🚀 New features to boost your workflow:
|
|
Let's make this a draft too to cut down on CI thrash |
f5857b3 to
32e182d
Compare
f5faaf6 to
2359d28
Compare
lkdvos
left a comment
There was a problem hiding this comment.
Left some comment throughout, there are some things that I am not entirely convinced by but the rest looks great, thanks for working through all of this!
For the similarstoragetype(tensor, storagetype) calls that you added, this seems like something we should probably discuss over a separate PR, and it would be great if we could consolidate this one to get the remainder of the fixes in.
Would you be up for splitting these two things, and then getting this merged?
The same kind of holds for some of the comments I made too, if we can just postpone the things that are not obvious, but already get the other parts in, that would probably be helpful.
(Note that I am very much aware that none of this is your fault and this PR has lived for too long so the design shifts a bit, for which I do apologize!)
| twistB = false | ||
| end | ||
|
|
||
| TTC = storagetype(C) |
There was a problem hiding this comment.
I guess this effectively means that we are deciding to promote inputs to the storagetype of the output. I'm not sure if I am fully convinced that we should solve this automatically at all, since I think that is also inconsistent with how regular matrices work (same for adding):
julia> CUDA.rand(2, 2) * rand(Float32, 2, 2)
ERROR: Scalar indexing is disallowed.I do think that this might be the right approach, and requiring explicit conversions in the cases of mixed inputs seems like the right call to me. (Even though I can see how that is annoying for MPSKit 😉 )
There was a problem hiding this comment.
No, it's for
TTC = storagetype(C)
# Bring A in the correct form for BLAS contraction
if copyA
Anew = TO.tensoralloc_add(TTC, A, pA, false, Val(true), allocator)
Anew = TO.tensoradd!(Anew, A, pA, false, One(), Zero(), backend, allocator)
twistA && twist!(Anew, filter(!isdual ∘ Base.Fix1(space, Anew), domainind(Anew)))
else
Anew = permute(A, pA)
endWithout this change, Anew will always have Vector{scalartype(T)} storage even if A was a BraidingTensor or some other object that only gets instantiated here. With the changes in #393 this won't be necessary. It's more than "annoying", with this change or #393 you have to define new tensoralloc methods for the mixed case, it's quite painful 😭
There was a problem hiding this comment.
reopening this since it seems like you changed this again: I'm really confused about why you are claiming that Anew will have the wrong storagetype: it should have the same storage type as A, not as C no? It sounds like you are trying to make contractions with mismatching storagetypes in the inputs work, while I would have expected that this is not what we want to support? Am I missing something here, or am I wrong?
There was a problem hiding this comment.
What seems to be happening is that:
TTC = scalartype(C)gives you aFloat64(let's say)Anew = TO.tensoralloc_add(TTC, A, pA, false, Val(true), allocator)then spits out something with storage typeVector{Float64}ifAis aSparseBlockMatrix{AbstractTensorMap}even if it should in fact be giving youAnewhaving storage typeCuVector{Float64}-- this is because of the fact thatAbstractTensorMapstorage type forcibly defaults toVector, I think
So it's not that I'm trying to mix incompatible storage types, it's that TensorKit as currently set up forces me to do so without this change.
There was a problem hiding this comment.
Does this make sense? I think the JordanMPOTensor changes could obviate this but I think we should link that issue in a comment and keep this moving
There was a problem hiding this comment.
That does make sense, but that mostly seems to indicate that we should remove the storagetype(::Type{<:AbstractTensorMap}) default, as that is just incorrect, and instead make storagetype(x::SparseBlockTensorMap{AbstractTensorMap}) do a runtime computation of the storagetype when this isn't possible to deduce from the type itself.
There was a problem hiding this comment.
Maybe so but does this have to happen in this PR?
There was a problem hiding this comment.
It raises additional problems if the SparseBlockTensorMap or BlockTensorMap has empty blocks
|
It's completely fine!! This has stayed open as I work through adding more tests for MPSKit, so I think we can pare off the simpler stuff we agree on, and then discuss things that are more contentious. |
|
Your PR no longer requires formatting changes. Thank you for your contribution! |
8a12178 to
ad62dad
Compare
d29251a to
3c5a575
Compare
lkdvos
left a comment
There was a problem hiding this comment.
It seems like some of the rebasing and the github UI has made it hard to spot the comments I left before, although I think many of them are still unresolved and could be discussed :)
|
I'm happy to discuss them, you'll note this PR is still in draft state. |
|
My bad, I got my notifications messed up and thought this was a review request 🙃 I will still blame github, but this one might actually also be (partially) on me |
|
GitHub UI against the world |
| end | ||
|
|
||
| perm = sortperm(parent(values); strategy.by, strategy.rev) | ||
| perm = isempty(parent(values)) ? () : sortperm(parent(values); strategy.by, strategy.rev) |
There was a problem hiding this comment.
I assume sortperm returns a type of AbstractVector{Int}, not sure if it is Vector{Int} or CuVector{Int} in this case. Is the problem that empty arrays fail? Should the isempty case return (Cu)Vector{Int}(undef, 0) to avoid a type stability?
There was a problem hiding this comment.
The problem is deeper within GPUArrays, it tries to launch a kernel of size 0 which is not allowed
| end | ||
|
|
||
| perm = sortperm(parent(values); by = abs, rev = false) | ||
| perm = isempty(parent(values)) ? () : sortperm(parent(values); by = abs, rev = false) |
Needed to get more MPSKit examples working