Skip to content
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

[ITensorsNamedDimsArraysExt] Convert symmetric tensors #1578

Merged
merged 3 commits into from
Nov 12, 2024

Conversation

mtfishman
Copy link
Member

@mtfishman mtfishman commented Nov 12, 2024

With this PR, we can now use to_nameddimsarray to convert ITensor, MPS, and MPO objects that contain tensors with the current format for non-fused abelian symmetric ITensors, i.e. an NDTensors.Tensor with BlockSparse storage and QN blocks labels, to the new format we are developing, i.e. a NamedDimsArray wrapping a BlockSparseArray with GradedUnitRange axes. In the current design, the block labels of the graded unit range still use the old format for sector labels, i.e. the ITensors.QuantumNumbers.QN type, but it would be easy to support converting those to the new SymmetrySectors.SectorProduct format. Interestingly, it only required overloading GradedAxes.fuse_labels(::QN, ::QN) to make that work, which I think is a testament to the flexibility of the new code is design!

@ogauthe I also fixed a missing overload for GradedUnitRangeDual that I hit when contracting ITensors with the new data format (similar to the definitions introduced in #1571).

So to be concrete, after this PR you can do the following:

using ITensors: Index, QN, dag, random_itensor
using ITensors.ITensorsNamedDimsArraysExt: to_nameddimsarray
i = Index([QN(0) => 2, QN(1) => 3])
a = random_itensor(i', dag(i))
b = to_nameddimsarray(a)
b' * b  to_nameddimsarray(a' * a)

which returns true. You can see the data format of b is:

julia> using NDTensors: tensor

julia> tensor(b)
5×5 NDTensors.NamedDimsArrays.NamedDimsArray{Float64, 2, NDTensors.BlockSparseArrays.BlockSparseArray{Float64, 2, Matrix{Float64}, NDTensors.SparseArrayDOKs.SparseArrayDOK{Matrix{Float64}, 2, NDTensors.BlockSparseArrays.BlockZero{Tuple{NDTensors.GradedAxes.GradedOneTo{NDTensors.LabelledNumbers.LabelledInteger{Int64, QN}, Vector{NDTensors.LabelledNumbers.LabelledInteger{Int64, QN}}}, NDTensors.GradedAxes.GradedUnitRangeDual{NDTensors.LabelledNumbers.LabelledInteger{Int64, QN}, Vector{NDTensors.LabelledNumbers.LabelledInteger{Int64, QN}}, NDTensors.GradedAxes.GradedOneTo{NDTensors.LabelledNumbers.LabelledInteger{Int64, QN}, Vector{NDTensors.LabelledNumbers.LabelledInteger{Int64, QN}}}}}}}, Tuple{NDTensors.GradedAxes.GradedOneTo{NDTensors.LabelledNumbers.LabelledInteger{Int64, QN}, Vector{NDTensors.LabelledNumbers.LabelledInteger{Int64, QN}}}, NDTensors.GradedAxes.GradedUnitRangeDual{NDTensors.LabelledNumbers.LabelledInteger{Int64, QN}, Vector{NDTensors.LabelledNumbers.LabelledInteger{Int64, QN}}, NDTensors.GradedAxes.GradedOneTo{NDTensors.LabelledNumbers.LabelledInteger{Int64, QN}, Vector{NDTensors.LabelledNumbers.LabelledInteger{Int64, QN}}}}}}, Tuple{ITensors.IndexID, ITensors.IndexID}} with indices GradedOneTo[QN(0) => 1:2, QN(1) => 3:5]×GradedUnitRangeDual[QN(0) => 1:2, QN(1) => 3:5]:
 -0.47797  -0.059555   0.0       0.0        0.0
 -1.14491  -0.121613   0.0       0.0        0.0
  0.0       0.0        1.17931  -0.128576  -0.615945
  0.0       0.0       -1.16749   0.952272  -0.210146
  0.0       0.0        1.15278  -1.20505    1.12212

To-do:

  • Add tests.

@mtfishman mtfishman merged commit cf050da into main Nov 12, 2024
13 checks passed
@mtfishman mtfishman deleted the ITensorsNamedDimsArraysExt_blocksparse_conversion branch November 12, 2024 23:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant