Repository navigation
Replies: 6 comments
|
Could you elaborate a bit more on what you actually want to see from this interface? I have definitely at some point played around a bit with this, but found it hard to convince myself that just having a closure or callable struct doesn't suffice. For the examples you provide, an anonymous function seems to provide most of the same functionality right? Just to add some things that might be useful to add to such an interface, although this requires quite a bit of redesigning:
|
|
In the example of transfer matrix, a closure indeed can already done this. But we cannot change the contraction and structure of network by hand, nor can we extract the internal structure of the closure, such as matrix ranks and spaces data. This interface can possibly allow general definition of a contraction of a tensor network, which also potentially be applied to MPS, PEPS, ED and TNR as a unified interface for tensor network. For example in MPS, the contraction plan can be chosen as totally dense as long as we do not explicitly do |
|
The problem is a bit that as soon as you allow the tensors to be manipulated, you lose the advantage of being able to precompute/cache anything, without having to keep track which parts get invalidated. The main annoyance is though that most of our machinery is very poorly set up for dynamic contractions, so changing the contraction order or ranks or number of tensors at runtime more or less necessarily makes the contraction lose type stability. If it is mostly convenience you are looking for, this might not matter and maybe this can be fine, but if it is performance I don't think it is straightforward to make this work. Just working this out a little bit, something that could be possible is the following: @tensornetwork function TransferMatrix(x)
return y[i j] := A[i k l] * conj(A[j k m]) * x[l m]
endwhich would then expand to something like: struct TransferMatrix{TA}
A::TA
end
(T::TransferMatrix)(x) = @tensor y[i j] := T.A[i k l] * conj(T.A[j k m]) * x[l m]with possibly a little bit more bells and whistles for input/output structures. Anyways, I'm just thinking out loud here, let me know if any of this makes sense |
|
Thanks for the explanation. I hadn't considered the type-stability issue. I'm not sure how useful a fully dynamic interface would be if it came with a significant performance cost. Does this mean that, to retain type stability and performance, we would generally need to settle on a contraction structure and order before repeatedly evaluating the network? If so, would other approaches effectively be equivalent to generating or writing a specialized contraction function for each network structure and then calling it whenever needed? In the design I had in mind, all tensor types are fixed. The network specifies only the Einstein summation indices, and its connectivity does not change. However, different contraction paths can produce intermediate tensors of different types. Am I understanding correctly that choosing the contraction order at runtime could therefore lead to type instability? Defining the transfer matrix and its action through a fixed function is indeed already sufficient for this purpose, as in the current implementations in |
|
If I'm understanding this correctly, indeed the claim is that changing the contraction order loses the type stability. The problem is just that if we fix the contraction, and its order (as is the case for Note though that for large contractions this overhead can actually sometimes be negligible, as long as the type instability does not leak into the surrounding code. Ultimately, I've never really found a compelling case to introduce this feature and the associated maintenance over just having closures, although MPSKit is kind of filled with these callable structures like the TransferMatrix etc, but I'm not sure that we can provide much more functionality to improve this. For completeness, in case anyone in the future wants to have a look at this, one of the things we could do if we really implemented this is to automatically "prepermute" the fixed tensors of the network into their most efficient orientation, such that repeated applications don't have to pay this cost. |
|
This is actually fairly close to an approach I took in the past. Tensor contractions became a callable struct, and you could initialize them by providing the tensor sizes. Something like that sounds compatible with what you're describing, but I don't think julia provides a way of generating custom optimized code (like the macro does) dependent on runtime values. So you would anyway need to call the tensoroperation primitives at runtime. I do think you could make it entirely type stable. The struct constructor would take in the tensor sizes, work out which contraction order is optimal, and could in theory initialize the callable tensornetwork type as struct{Tuple{temporary1_type, temporary2_type,...}}. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
In ED and diagonalizing transfer matrices (constructed from TNR algorithms), those transfer matrices are usually defined formally by acting on states.
I am wondering whether it is possible for
TensorOperationsto open an interface such that users can directly access and manipulate the evaluation order of contractions, and define our own lazy evaluations?TensorNetworktype and its creationFor example, we can write
to create an object with type
TensorNetwork.Here
Graphtype and its printingHere
Gis some nested graph tree that encodes contraction plan. Maybe of the form:and
This
transfer::TensorNetworkshould never be constructed directly because of the contraction complexity. We can perform a dense contraction byWe may run
complexity(transfer)to see its contraction complexity. And may run
opt!(transfer)to change to an optimal contraction order.
The graph (not this one by another one) can be printed as
Define lazy action in ED
We (users) can then define lazy action on states by manipulating its network and coloring
And finally one can define a method for
eigsolveAll reactions