You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A * B syntax where A and B are NDTensors leads to standard matrix multiplication, which in many cases has nothing to do with tensor contraction. @brian-dellabetta
Minimal code demonstrating the bug or unexpected behavior
Minimal runnable code
index1 =Index(2)
index2 =Index(3)
A =randomTensor((index1, index2))
B =randomTensor((index2, index1))
C =randomTensor((index1, index2))
A * B # leads to a matrix (tensors with two identical indices) rather than to a scalar
A * C # errors because of not matching dimensions
Expected output or behavior
Expected tensor contraction as for ITensors. Operations above should return a 0-dim tensor.
Possible workaround
To resolve this issue, we commented out this function and added the following code:
Workaround
using ITensors
import Base:*function (a::Tensor* b::Tensor)
labels_a, labels_b = ITensors.compute_contraction_labels(inds(a), inds(b))
returncontract(a, labels_a, b, labels_b)
end
Ideally we wanted to add this code inside generic_tensor_operations, but we were not able to do so because compute_contraction_labels is defined inside ITensors and not exported to NDTensors.
Version information
Output from versioninfo():
julia>versioninfo()
Julia Version 1.9.3
Commit bed2cd540a1 (2023-08-2414:43 UTC)
Build Info:
Official https://julialang.org/ release
Platform Info:
OS: macOS (arm64-apple-darwin22.4.0)
CPU:10× Apple M1 Max
WORD_SIZE:64
LIBM: libopenlibm
LLVM: libLLVM-14.0.6 (ORCJIT, apple-m1)
Threads:2 on 8 virtual cores
Environment:
JULIA_PKG_USE_CLI_GIT =true
Click
Output from using Pkg; Pkg.status("ITensors"):
julia>using Pkg; Pkg.status("ITensors")
Status `~/.julia/environments/v1.9/Project.toml`
[9136182c] ITensors v0.3.43`~/Documents/ITensors.jl`
The text was updated successfully, but these errors were encountered:
We never intended * to work as tensor contraction for NDTensors.Tensors, it is meant to be matrix multiplication. NDTensors.Tensors are meant to be agnostic about whether or not the indices have identifiers (like the Index). The syntax for performing tensor contraction of NDTensors.Tensors is contract(a, labels_a, b, labels_b). More broadly, NDTensors.Tensors are meant to have the same syntax and interface as other AbstractArrays.
Something that would be nice would be to allow more general labels. Currently we use the ncon convention of just positive and negative integers (https://arxiv.org/abs/1402.0939). We could still use that internally but for high level interfaces like contract we could allow any objects that define equality to be labels (and compile that down to the ncon label convention). That would allow someone to write:
contract(A, inds(A), B, inds(B))
which would then work if inds(A) and inds(B) had modes with identifiers, like Index.
Description of bug
A * B
syntax whereA
andB
are NDTensors leads to standard matrix multiplication, which in many cases has nothing to do with tensor contraction. @brian-dellabettaMinimal code demonstrating the bug or unexpected behavior
Minimal runnable code
Expected output or behavior
Expected tensor contraction as for ITensors. Operations above should return a 0-dim tensor.
Possible workaround
To resolve this issue, we commented out this function and added the following code:
Workaround
Ideally we wanted to add this code inside generic_tensor_operations, but we were not able to do so because
compute_contraction_labels
is defined inside ITensors and not exported to NDTensors.Version information
versioninfo()
:using Pkg; Pkg.status("ITensors")
:The text was updated successfully, but these errors were encountered: