-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Collect GeneralizedKroneckerProducts in-place #61
Comments
This is good idea. It is simple to either
I am leaning towards the second option to be the better one. What do you think? |
I like this idea. I guess we could add a function This trick will likely work with systems containing only a single Kronecker product, unless the code becomes more involved.
Since |
Before, I've resorted to using the first option by collecting each sum (and manually writing out the vec-trick) collect(τ3 ⊕ τ4) * lmul!(D, collect(transpose(τ1 ⊕ τ2))) In my use case, I use Each The Explicitly collecting the sums (out-of-place) becomes expensive because I have hundreds / thousands of My current version is hard to read and is not very robust. Do I understand correctly that the second option would allow updating the non-zero values of
Perhaps a field for the matrix
I'd say this is only important for Admittedly, I don't have any specific usage for this, as I need to collect sums of larger, sparse matrices. I'd rather consider this as a simple (optional) utility function we can use to store large (dense or sparse) matrices as sparse matrices in higher order products/sums. and allow the user to update them in-place in a manner of their choosing. Here's a dummy example with calculating a linear combination of Kronecker products, Kronecker sums or the higher order example at the top of this issue. # Small dense matrices
A = rand(4,4);
B = rand(3,3);
Anew = rand(4,4);
Bnew = rand(3,3);
result = kron(A,B) + kron(Anew, Bnew);
C = zeros(12,12);
K = A ⊗ B; # or ⊕
C .+= collect(K) # or an equivalent in-place method
K.A .= Anew;
K.B .= Bnew;
C .+= collect(K) # or an equivalent in-place method
C ≈ result If the sizes of K = sparse(A ⊗ B) # or ⊕, should not automatically collect to a sparse matrix
...
K.A.nzval .= vec(Anew)
K.B.nzval .= vec(Bnew) |
Hi I came across from @elisno message on discourse and his comment under my PR JuliaLang/julia#31069, I'll just reply both here so it's easier to keep track. Generally speaking, the implementation of It was not well optimized for performance since in quantum circuits there are much more space to optimize the performance for quantum gates specifically. Thus sparse matrices type defined in LuxurySparse is not optimized specifically, but in principle by specializing Regarding compatibility, you can depend on |
I've looked over the I think it would be a good idea to use In CuYao.jl, I'm not sure how it would work with higher order products / sums or how lazy batches would look like, but @MichielStock, what are your thoughts on using using I'm still trying to figure out how to collect (sparse) KroneckerSums on GPUs.
|
I think we could consider move all |
For this issue, it would make sense to use LuxurySparse.jl for sparse I'll leave the GPU implementation for another issue later. |
Yeah, I think the best way to support GPU is to have a new package for GPUs specifically since the best way to support conditional dependency is to have a new package as I discussed with Stefan a year ago, tho there are some plans to support conditional dependency in Pkg. So a new special array package made for GPUs specifically would make more sense. |
Are you sure you need to use |
Ok, I will summarize the discussion (as I see it)
Do I have the gist of it? If so, I would move these to respective issues. Further thoughts:
|
Using the vec-trick with higher order Kronecker products, such as
should result in the lower-order products (
(τ1 ⊕ τ2)
and(τ3 ⊕ τ4)
) being collected.In my use case, the size of each (sparse) matrix is around
N x N = 128 x 128
. These matrices are stored inτ::Array{T<:Complex,4}
withsize(τ)= (N,N,M,L)
. The sparsity pattern alongM
andL
is assumed to be the same.This would be more efficient if (sparse) workspace matrices are used to store the intermediate results,
reducing the number of allocations,
Last year, some work was started on
kron!
(JuliaLang/julia#31069) that computed the Kronecker product in-place.Should this implementation by used? If so, should we wait for the PR to go through, or write these methods in
Kronecker.jl
?Would it be enough to apply this to
KroneckerProduct
s or do we need methods that specialize on other types, such asKroneckerSum
s andIndexedKroneckerProduct
s?Currently
sparse
collectsKroneckerSum
s. Shouldn't it be lazy by default to accommodate these in-place methods? I'm not sure how to generalize over all types, but do something like:The text was updated successfully, but these errors were encountered: