Skip to content

Commit

Permalink
Start using ITensorMPS.jl (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
mtfishman authored May 12, 2024
1 parent 7879d95 commit 8c37b37
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 29 deletions.
4 changes: 3 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@ Accessors = "7d9f7c33-5ae7-4f3b-8dc6-eff91059b697"
Compat = "34da2185-b29b-5c13-b0c7-acf172513d20"
Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b"
Folds = "41a02a25-b8f0-4f67-bc48-60067656b558"
ITensorMPS = "0d1a4710-d33b-49a5-8f18-73bdf49b47e2"
ITensors = "9136182c-28ba-11e9-034c-db9fb085ebd5"
MPI = "da04e1cc-30fd-572f-bb4f-1f8673147195"

[compat]
Accessors = "0.1.26"
Compat = "4.8"
Folds = "0.2.8"
ITensors = "0.3.58"
ITensorMPS = "0.1.7"
ITensors = "0.3.58, 0.4, 0.5, 0.6"
MPI = "0.20"
julia = "1.6"

Expand Down
16 changes: 10 additions & 6 deletions examples/01_parallel_mpo_sum_2d_hubbard_conserve_momentum.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,19 @@ rmprocs(setdiff(procs(), 1))
addprocs(2)
@show nprocs()

@everywhere using ITensors
@everywhere using ITensorMPS
@everywhere using ITensorParallel
using Random
@everywhere using ITensors
using LinearAlgebra: BLAS
using Random: Random
using Strided: Strided

include(joinpath(pkgdir(ITensors), "examples", "src", "electronk.jl"))
include(joinpath(pkgdir(ITensors), "examples", "src", "hubbard.jl"))
electronk_path = joinpath(pkgdir(ITensors), "src", "lib", "ITensorMPS", "examples", "src")
include(joinpath(electronk_path, "electronk.jl"))
include(joinpath(electronk_path, "hubbard.jl"))

ITensors.BLAS.set_num_threads(1)
ITensors.Strided.disable_threads()
BLAS.set_num_threads(1)
Strided.disable_threads()

"""
Run with:
Expand Down
20 changes: 12 additions & 8 deletions examples/02_mpi_mpo_sum_2d_hubbard_conserve_momentum.jl
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
using MPI
using MPI: MPI
MPI.Init()
using ITensors
using ITensorMPS
using ITensorParallel
using Random
using ITensors
using LinearAlgebra: BLAS
using Random: Random
using Strided: Strided

include(joinpath(pkgdir(ITensors), "examples", "src", "electronk.jl"))
include(joinpath(pkgdir(ITensors), "examples", "src", "hubbard.jl"))
electronk_path = joinpath(pkgdir(ITensors), "src", "lib", "ITensorMPS", "examples", "src")
include(joinpath(electronk_path, "electronk.jl"))
include(joinpath(electronk_path, "hubbard.jl"))

ITensors.BLAS.set_num_threads(1)
ITensors.Strided.disable_threads()
BLAS.set_num_threads(1)
Strided.disable_threads()

"""
Run at the command line with 4 processes:
Expand Down Expand Up @@ -84,7 +88,7 @@ function main(;

if disk
# Write-to-disk
mpo_sum_term = ITensors.disk(mpo_sum_term)
mpo_sum_term = ITensorMPS.disk(mpo_sum_term)
end

energy, psi = @time dmrg(mpo_sum_term, psi0; nsweeps, maxdim, cutoff, noise)
Expand Down
3 changes: 2 additions & 1 deletion examples/03_partition_2d_heisenberg.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using ITensors
using ITensorMPS
using ITensorParallel
using ITensors

function heisenberg_2d(nx, ny)
lattice = square_lattice(nx, ny; yperiodic=false)
Expand Down
8 changes: 8 additions & 0 deletions examples/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[deps]
Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b"
ITensorMPS = "0d1a4710-d33b-49a5-8f18-73bdf49b47e2"
ITensorParallel = "0fccfcd2-f061-4985-9740-339d3f86bfce"
ITensors = "9136182c-28ba-11e9-034c-db9fb085ebd5"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Strided = "5e0ebb24-38b0-5f93-81fe-25c709ecae67"
10 changes: 5 additions & 5 deletions src/ITensorParallel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,24 @@ using Accessors
using Compat
using Distributed
using Folds
using MPI
using ITensorMPS
using ITensors
using ITensors.NDTensors
using MPI

using ITensors: Algorithm, @Algorithm_str
using ITensors.ITensorMPS: AbstractSum
using ITensorMPS: AbstractSum

import Base: eltype, length, size
import ITensors: product
import ITensors.ITensorMPS:
import ITensors: product, replaceind!
import ITensorMPS:
disk,
linkind,
lproj,
noiseterm,
nsite,
orthogonalize!,
position!,
replaceind!,
replacebond!,
rproj,
set_terms,
Expand Down
3 changes: 3 additions & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
ArgParse = "c7e460c6-2fb9-53a9-8c5b-16f535851c63"
Compat = "34da2185-b29b-5c13-b0c7-acf172513d20"
Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b"
ITensorMPS = "0d1a4710-d33b-49a5-8f18-73bdf49b47e2"
ITensorParallel = "0fccfcd2-f061-4985-9740-339d3f86bfce"
ITensors = "9136182c-28ba-11e9-034c-db9fb085ebd5"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
MPI = "da04e1cc-30fd-572f-bb4f-1f8673147195"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Strided = "5e0ebb24-38b0-5f93-81fe-25c709ecae67"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
12 changes: 5 additions & 7 deletions test/test_mpi_example.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using MPI
using MPI: MPI, mpiexec
using ITensorParallel
using Test
using Test: @testset

@testset "Test $(@__FILE__)" begin
examples_dir = joinpath(pkgdir(ITensorParallel), "examples")
Expand All @@ -18,10 +18,8 @@ using Test
Ny = 4
nsweeps = 2
maxdim = 20
mpiexec() do exe # MPI wrapper
run(
`$exe -n $(nprocs) $(Base.julia_cmd()) --threads $(Threads.nthreads()) $(joinpath(examples_dir, example_file)) --Nx $(Nx) --Ny $(Ny) --nsweeps $(nsweeps) --maxdim $(maxdim) --disk $(disk) --threaded_blocksparse $(threaded_blocksparse)`,
)
end
run(
`$(mpiexec()) -n $(nprocs) $(Base.julia_cmd()) --threads $(Threads.nthreads()) $(joinpath(examples_dir, example_file)) --Nx $(Nx) --Ny $(Ny) --nsweeps $(nsweeps) --maxdim $(maxdim) --disk $(disk) --threaded_blocksparse $(threaded_blocksparse)`,
)
end
end
2 changes: 1 addition & 1 deletion test/test_sequential_threaded_distributed_example.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using ITensorParallel
using Test
using Test: @testset

@testset "Test $(@__FILE__)" begin
examples_dir = joinpath(pkgdir(ITensorParallel), "examples")
Expand Down

0 comments on commit 8c37b37

Please sign in to comment.