From b9d5e098af3310de3e8e97151b9fd193001882d7 Mon Sep 17 00:00:00 2001 From: mtfishman Date: Thu, 9 May 2024 16:30:05 -0400 Subject: [PATCH] Use ITensorMPS --- Project.toml | 6 +- examples/Project.toml | 1 + .../broken/hubbard_1d_no_spin_conservation.jl | 84 ---------------- .../broken/hubbard_2d_no_spin_conservation.jl | 96 ------------------- examples/hubbard_1d_spin_conservation.jl | 3 +- examples/hubbard_2d_spin_conservation.jl | 3 +- examples/mps_to_determinants.jl | 3 +- examples/spinless_fermion.jl | 3 +- examples/spinless_fermion_pairing.jl | 5 +- test/Project.toml | 1 + test/electron.jl | 1 + test/gmera.jl | 1 + test/gmps.jl | 1 + 13 files changed, 20 insertions(+), 188 deletions(-) delete mode 100644 examples/broken/hubbard_1d_no_spin_conservation.jl delete mode 100644 examples/broken/hubbard_2d_no_spin_conservation.jl diff --git a/Project.toml b/Project.toml index 75b4b4a..252284c 100644 --- a/Project.toml +++ b/Project.toml @@ -1,15 +1,17 @@ name = "ITensorGaussianMPS" uuid = "2be41995-7c9f-4653-b682-bfa4e7cebb93" authors = ["Matthew Fishman and contributors"] -version = "0.1.6" +version = "0.1.7" [deps] Compat = "34da2185-b29b-5c13-b0c7-acf172513d20" +ITensorMPS = "0d1a4710-d33b-49a5-8f18-73bdf49b47e2" ITensors = "9136182c-28ba-11e9-034c-db9fb085ebd5" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" [compat] Compat = "3.40.0, 4" -ITensors = "0.3.58, 0.4, 0.5" +ITensorMPS = "0.1" +ITensors = "0.3.58, 0.4, 0.5, 0.6" LinearAlgebra = "1.6" julia = "1.6" diff --git a/examples/Project.toml b/examples/Project.toml index 8787f2a..5f87a9b 100644 --- a/examples/Project.toml +++ b/examples/Project.toml @@ -1,3 +1,4 @@ [deps] ITensorGaussianMPS = "2be41995-7c9f-4653-b682-bfa4e7cebb93" +ITensorMPS = "0d1a4710-d33b-49a5-8f18-73bdf49b47e2" ITensors = "9136182c-28ba-11e9-034c-db9fb085ebd5" diff --git a/examples/broken/hubbard_1d_no_spin_conservation.jl b/examples/broken/hubbard_1d_no_spin_conservation.jl deleted file mode 100644 index c1bb8e3..0000000 --- a/examples/broken/hubbard_1d_no_spin_conservation.jl +++ /dev/null @@ -1,84 +0,0 @@ -using ITensors -using ITensorGaussianMPS -using LinearAlgebra - -# Electrons - -# Half filling -N = 50 -Nf = N - -@show N, Nf - -# Maximum MPS link dimension -_maxlinkdim = 200 - -@show _maxlinkdim - -# DMRG cutoff -_cutoff = 1e-8 - -# Hopping -t = 1.0 - -# Electron-electron on-site interaction -U = 1.0 - -@show t, U - -# Make the free fermion Hamiltonian for the up spins -os_up = OpSum() -for n in 1:(N - 1) - os_up .+= -t, "Cdagup", n, "Cup", n + 1 - os_up .+= -t, "Cdagup", n + 1, "Cup", n -end - -# Make the free fermion Hamiltonian for the down spins -os_dn = OpSum() -for n in 1:(N - 1) - os_dn .+= -t, "Cdagdn", n, "Cdn", n + 1 - os_dn .+= -t, "Cdagdn", n + 1, "Cdn", n -end - -# Hopping Hamiltonian with 2*N spinless fermions, -# alternating up and down spins -h = hopping_hamiltonian(os_up, os_dn) - -# Get the Slater determinant -Φ = slater_determinant_matrix(h, Nf) - -# Create an MPS from the slater determinant. -# In this example, we will turn off spin conservation (so this would -# work with a Hamiltonian that mixed the up and down spin sectors) -s = siteinds("Electron", N; conserve_qns=true, conserve_sz=false) -println("Making free fermion starting MPS") -@time ψ0 = slater_determinant_to_mps( - s, Φ; eigval_cutoff=1e-4, cutoff=_cutoff, maxdim=_maxlinkdim -) -@show maxlinkdim(ψ0) - -@show U -os = os_up + os_dn -for n in 1:N - os .+= U, "Nupdn", n -end -H = MPO(os, s) - -# Random starting state -ψr = randomMPS(s, n -> n ≤ Nf ? (isodd(n) ? "↑" : "↓") : "0") - -println("Random starting state energy") -@show flux(ψr) -@show inner(ψr', H, ψr) -println() -println("Free fermion starting state energy") -@show flux(ψ0) -@show inner(ψ0', H, ψ0) - -println("\nStart from product state") -@time dmrg(H, ψr; nsweeps=10, maxdim=[10, 20, _maxlinkdim], cutoff=_cutoff) - -println("\nStart from free fermion state") -@time dmrg(H, ψ0; nsweeps=5, maxdim=_maxlinkdim, cutoff=_cutoff) - -nothing diff --git a/examples/broken/hubbard_2d_no_spin_conservation.jl b/examples/broken/hubbard_2d_no_spin_conservation.jl deleted file mode 100644 index f69a551..0000000 --- a/examples/broken/hubbard_2d_no_spin_conservation.jl +++ /dev/null @@ -1,96 +0,0 @@ -using ITensors -using ITensorGaussianMPS -using LinearAlgebra - -# Electrons - -# Half filling -Nx, Ny = 6, 3 -N = Nx * Ny -Nf = N - -@show Nx, Ny -@show N, Nf - -# Maximum MPS link dimension -_maxlinkdim = 1_000 - -@show _maxlinkdim - -# DMRG cutoff -_cutoff = 1e-5 - -# Hopping -t = 1.0 - -# Electron-electon on-site interaction -U = 4.0 - -@show t, U - -lattice = square_lattice(Nx, Ny; yperiodic=true) - -# Make the free fermion Hamiltonian for the up spins -os_up = OpSum() -for b in lattice - os_up .+= -t, "Cdagup", b.s1, "Cup", b.s2 - os_up .+= -t, "Cdagup", b.s2, "Cup", b.s1 -end - -# Make the free fermion Hamiltonian for the down spins -os_dn = OpSum() -for b in lattice - os_dn .+= -t, "Cdagdn", b.s1, "Cdn", b.s2 - os_dn .+= -t, "Cdagdn", b.s2, "Cdn", b.s1 -end - -# Hopping Hamiltonian with 2*N spinless fermions, -# alternating up and down spins -h = hopping_hamiltonian(os_up, os_dn) - -# Get the Slater determinant -Φ = slater_determinant_matrix(h, Nf) - -println() -println("Exact free fermion energy: ", tr(Φ'h * Φ)) -println() - -# Create an MPS from the slater determinant. -# In this example we are turning of spin conservation. -s = siteinds("Electron", N; conserve_qns=true, conserve_sz=false) -println("Making free fermion starting MPS") -@time ψ0 = slater_determinant_to_mps( - s, Φ; eigval_cutoff=1e-4, cutoff=_cutoff, maxdim=_maxlinkdim -) -@show maxlinkdim(ψ0) - -os = os_up + os_dn -for n in 1:N - os .+= U, "Nupdn", n -end -H = MPO(os, s) - -# Random starting state -ψr = randomMPS(s, n -> n ≤ Nf ? (isodd(n) ? "↑" : "↓") : "0") - -println("\nRandom starting state energy") -@show flux(ψr) -@show inner(ψr, H, ψr) - -println("\nFree fermion MPS starting state energy") -@show flux(ψ0) -@show inner(ψ0, H, ψ0) - -println("\nStart from random product state") -dmrg_kwargs = (; - nsweeps=10, - maxdim=[10, 20, 100, 200, _maxlinkdim], - cutoff=_cutoff, - noise=[1e-7, 1e-8, 1e-10, 0.0], -) -@time dmrg(H, ψr; dmrg_kwargs...) - -println("\nStart from free fermion state") -@time dmrg(H, ψ0; nsweeps=10, maxdim=_maxlinkdim, cutoff=_cutoff) - -nothing diff --git a/examples/hubbard_1d_spin_conservation.jl b/examples/hubbard_1d_spin_conservation.jl index 460bdd4..f7df6e5 100644 --- a/examples/hubbard_1d_spin_conservation.jl +++ b/examples/hubbard_1d_spin_conservation.jl @@ -1,5 +1,6 @@ -using ITensors using ITensorGaussianMPS +using ITensorMPS +using ITensors using LinearAlgebra # Electrons diff --git a/examples/hubbard_2d_spin_conservation.jl b/examples/hubbard_2d_spin_conservation.jl index 41274b5..23d316c 100644 --- a/examples/hubbard_2d_spin_conservation.jl +++ b/examples/hubbard_2d_spin_conservation.jl @@ -1,5 +1,6 @@ -using ITensors using ITensorGaussianMPS +using ITensorMPS +using ITensors using LinearAlgebra # Electrons diff --git a/examples/mps_to_determinants.jl b/examples/mps_to_determinants.jl index c3590b4..3f34b42 100644 --- a/examples/mps_to_determinants.jl +++ b/examples/mps_to_determinants.jl @@ -1,5 +1,6 @@ -using ITensors using ITensorGaussianMPS +using ITensorMPS +using ITensors using LinearAlgebra # Half filling diff --git a/examples/spinless_fermion.jl b/examples/spinless_fermion.jl index 7d2f74b..6f80608 100644 --- a/examples/spinless_fermion.jl +++ b/examples/spinless_fermion.jl @@ -1,5 +1,6 @@ -using ITensors using ITensorGaussianMPS +using ITensorMPS +using ITensors using LinearAlgebra # Half filling diff --git a/examples/spinless_fermion_pairing.jl b/examples/spinless_fermion_pairing.jl index 145b042..3d01be4 100644 --- a/examples/spinless_fermion_pairing.jl +++ b/examples/spinless_fermion_pairing.jl @@ -1,8 +1,9 @@ # This script shows a minimal example of the GMPS-MPS conversion # of the ground state of quadratic fermionic Hamiltonian with pairing terms. -using LinearAlgebra -using ITensors using ITensorGaussianMPS +using ITensorMPS +using ITensors +using LinearAlgebra ITensors.disable_contraction_sequence_optimization() let diff --git a/test/Project.toml b/test/Project.toml index 622e01b..73d5956 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -1,4 +1,5 @@ [deps] +ITensorMPS = "0d1a4710-d33b-49a5-8f18-73bdf49b47e2" ITensors = "9136182c-28ba-11e9-034c-db9fb085ebd5" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" diff --git a/test/electron.jl b/test/electron.jl index 4d260d1..03f19b9 100644 --- a/test/electron.jl +++ b/test/electron.jl @@ -1,4 +1,5 @@ using ITensorGaussianMPS +using ITensorMPS using ITensors using LinearAlgebra using Test diff --git a/test/gmera.jl b/test/gmera.jl index 9b5dd5d..c4acac8 100644 --- a/test/gmera.jl +++ b/test/gmera.jl @@ -1,4 +1,5 @@ using ITensorGaussianMPS +using ITensorMPS using ITensors using LinearAlgebra using Test diff --git a/test/gmps.jl b/test/gmps.jl index 64adb70..f3d362d 100644 --- a/test/gmps.jl +++ b/test/gmps.jl @@ -1,4 +1,5 @@ using ITensorGaussianMPS +using ITensorMPS using ITensors using LinearAlgebra using Test