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

[NDTensors] Get more Array storage functionality working #1222

Merged
merged 19 commits into from
Oct 30, 2023

Conversation

mtfishman
Copy link
Member

@mtfishman mtfishman commented Oct 27, 2023

This gets more functionality for Tensor directly wrapping an Array (as opposed to Dense) working, such as tensor contraction, QR, eigen, and SVD.

EDIT: This is now working:

using NDTensors
using ITensors

function heisenberg(n)
  os = OpSum()
  for j in 1:(n - 1)
    os += "Sz", j, "Sz", j + 1
    os += 0.5, "S+", j, "S-", j + 1
    os += 0.5, "S-", j, "S+", j + 1
  end
  return os
end

function main(; n=10, nsweeps=5, conserve_qns=false)
  s = siteinds("S=1/2", n; conserve_qns)
  H = MPO(heisenberg(n), s)
  ψ = randomMPS(s, j -> isodd(j) ? "" : ""; linkdims=4)
  ψ1, e1 = dmrg(NDTensors.to_arraystorage.((H, ψ))...; nsweeps, maxdim=10, cutoff=1e-12)
  ψ2, e2 = dmrg(H, ψ; nsweeps, maxdim=10, cutoff=1e-12)
  return e1, e2
end

main()

where NDTensors.to_arraystorage replaces Dense storage with Array.

This outputs:

After sweep 1 energy=-4.256581185494193  maxlinkdim=10 maxerr=2.11E-06 time=0.020
After sweep 2 energy=-4.258028428488432  maxlinkdim=10 maxerr=1.25E-06 time=0.020
After sweep 3 energy=-4.258028444854628  maxlinkdim=10 maxerr=8.24E-07 time=0.030
After sweep 4 energy=-4.258028445008366  maxlinkdim=10 maxerr=8.23E-07 time=0.020
After sweep 5 energy=-4.258028445013943  maxlinkdim=10 maxerr=8.23E-07 time=0.021
After sweep 1 energy=-4.2565811854942  maxlinkdim=10 maxerr=2.11E-06 time=0.021
After sweep 2 energy=-4.258028428488428  maxlinkdim=10 maxerr=1.25E-06 time=0.029
After sweep 3 energy=-4.258028444854625  maxlinkdim=10 maxerr=8.24E-07 time=0.021
After sweep 4 energy=-4.258028445008369  maxlinkdim=10 maxerr=8.23E-07 time=0.021
After sweep 5 energy=-4.258028445013948  maxlinkdim=10 maxerr=8.23E-07 time=0.021

so DMRG is running just as before, but with the Dense type completely removed.

@codecov-commenter
Copy link

codecov-commenter commented Oct 27, 2023

Codecov Report

Attention: 4 lines in your changes are missing coverage. Please review.

Comparison is base (74095ef) 85.38% compared to head (514424f) 67.35%.

❗ Current head 514424f differs from pull request most recent head c14150c. Consider uploading reports for the commit c14150c to get more accurate results

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@             Coverage Diff             @@
##             main    #1222       +/-   ##
===========================================
- Coverage   85.38%   67.35%   -18.03%     
===========================================
  Files          89       88        -1     
  Lines        8449     8415       -34     
===========================================
- Hits         7214     5668     -1546     
- Misses       1235     2747     +1512     
Files Coverage Δ
src/itensor.jl 80.76% <0.00%> (-1.59%) ⬇️
src/mps/abstractmps.jl 49.35% <0.00%> (-37.74%) ⬇️

... and 34 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

mtfishman and others added 5 commits October 30, 2023 11:24
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
mtfishman and others added 2 commits October 30, 2023 11:49
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@mtfishman
Copy link
Member Author

@kmp5VT @emstoudenmire with this PR we would almost be able to remove the Dense type entirely. We might have to add a few more functions for the new Array storage type, but DMRG can be run entirely without the Dense type.

It may be worth just going ahead and doing that soon in a future PR since it will simplify the code base and make future work on removing EmptyStorage, Diag, and BlockSparse simpler. It would only be breaking for users who are reaching into internals (i.e. working at the storage level), and it would make reaching into internals much simpler since the type becomes simpler. We can think about how to coordinate with work like #1213 (which will lead to us being able to remove the EmptyStorage type) but I think they are mostly separate.

mtfishman and others added 2 commits October 30, 2023 13:37
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@mtfishman
Copy link
Member Author

[test ITensors mps]

@github-actions
Copy link
Contributor

Run ITensors mps tests from comment trigger: failed ❌
https://github.com/ITensor/ITensors.jl/actions/runs/6696637447

1 similar comment
@github-actions
Copy link
Contributor

Run ITensors mps tests from comment trigger: failed ❌
https://github.com/ITensor/ITensors.jl/actions/runs/6696637447

@mtfishman
Copy link
Member Author

[test ITensors mps]

@github-actions
Copy link
Contributor

Run ITensors mps tests from comment trigger: failed ❌
https://github.com/ITensor/ITensors.jl/actions/runs/6697351721

@github-actions
Copy link
Contributor

Run ITensors mps tests from comment trigger: failed ❌
https://github.com/ITensor/ITensors.jl/actions/runs/6697351721

@mtfishman mtfishman merged commit 690b219 into main Oct 30, 2023
8 of 10 checks passed
@mtfishman mtfishman deleted the NDTensors_arraytensor_ops branch October 30, 2023 20:42
@emstoudenmire
Copy link
Collaborator

Nice – this is advancing really fast, and I see you're already on to the diagonal case.

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.

None yet

3 participants