Skip to content

[WIP] Rewrite based on NamedDimsArrays.jl #108

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

Draft
wants to merge 36 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
fb4c69d
Get package to compile
mtfishman Jan 10, 2025
0d16b94
Merge branch 'main' into nameddimsarrays
mtfishman Jan 10, 2025
ca7418d
Work towards getting non-QN DMRG working
mtfishman Jan 12, 2025
7ed11a4
Start fixing MPO constructor
mtfishman Jan 12, 2025
0ac4690
Progress getting DMRG working
mtfishman Jan 17, 2025
e3d740d
More fixes
mtfishman Jan 17, 2025
01bb8ae
Overload LinearAlgebra.norm
mtfishman Jan 17, 2025
924854c
Fix inner
mtfishman Jan 18, 2025
a16f115
More fixes for inner, dmrg
mtfishman Jan 18, 2025
e323265
Make use of new quantum operator libraries
mtfishman Jan 20, 2025
f550c6d
Fix op call
mtfishman Jan 20, 2025
6350e39
Simplifications
mtfishman Jan 26, 2025
549b05d
Simplifications
mtfishman Jan 28, 2025
79d4b7e
Use BackendSelection
mtfishman Jan 28, 2025
58a3a0b
Delete deprecations
mtfishman Jan 28, 2025
f738f58
Improve siteinds, simplify example
mtfishman Jan 31, 2025
d896610
Simplified siteinds
mtfishman Feb 2, 2025
1846b58
Replace `onehot` with new `SparseArraysBase.oneelement`
mtfishman Feb 3, 2025
df4a99f
Updates for dependent packages
mtfishman Feb 12, 2025
9a9399d
Use settag
mtfishman Feb 12, 2025
b278cb6
Add back non-QN random_mps
mtfishman Feb 13, 2025
775f797
Get more of random_mps working
mtfishman Feb 14, 2025
4b9759a
Fix shape issue in randomU
mtfishman Feb 14, 2025
dd63d7f
Fix example
mtfishman Feb 19, 2025
cfb04a3
Start rewriting random_mps
mtfishman Feb 21, 2025
4f7f0b2
Start adding apply/product for ITensors
mtfishman Feb 21, 2025
c8eec73
Start updating apply
mtfishman Feb 22, 2025
419a1c3
Gate application and new random_mps implementation
mtfishman Feb 24, 2025
5647236
Merge main
mtfishman Feb 24, 2025
e536fd9
Bump package versions
mtfishman Mar 10, 2025
ad20fce
Merge main
mtfishman Mar 19, 2025
f0b8717
Remove stale example deps
mtfishman Apr 9, 2025
7359f70
Update for dependent packages
mtfishman Apr 11, 2025
8d0245c
Merge main
mtfishman Apr 11, 2025
35f04d8
Fix
mtfishman Apr 11, 2025
5e79373
Format
mtfishman Apr 14, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 28 additions & 8 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,20 +1,30 @@
name = "ITensorMPS"
uuid = "0d1a4710-d33b-49a5-8f18-73bdf49b47e2"
authors = ["Matthew Fishman <[email protected]>", "Miles Stoudenmire <[email protected]>"]
version = "0.3.17"
version = "0.4.0"

[deps]
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
BackendSelection = "680c2d7c-f67a-4cc9-ae9c-da132b1447a5"
Compat = "34da2185-b29b-5c13-b0c7-acf172513d20"
DiagonalArrays = "74fd4be6-21e2-4f6f-823a-4360d37c7a77"
FillArrays = "1a297f60-69ca-5386-bcde-b61e274b549b"
GradedArrays = "bc96ca6e-b7c8-4bb6-888e-c93f838762c2"
ITensors = "9136182c-28ba-11e9-034c-db9fb085ebd5"
IsApprox = "28f27b66-4bd8-47e7-9110-e2746eb8bed7"
KrylovKit = "0b1a1467-8014-51b9-945f-bf0ae24f4b77"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
NDTensors = "23ae76d9-e61a-49c4-8f12-3f1a16adf9cf"
NamedDimsArrays = "60cbd0c0-df58-4cb7-918c-6f5607b73fde"
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
QuantumOperatorAlgebra = "c7a6d0f7-daa6-4368-ba67-89ed64127c3b"
QuantumOperatorDefinitions = "826dd319-6fd5-459a-a990-3a4f214664bf"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
SerializedElementArrays = "d3ce8812-9567-47e9-a7b5-65a6d70a3065"
SparseArraysBase = "0d5efcca-f356-4864-8770-e1ed8d78f208"
TensorAlgebra = "68bd88dc-f39d-4e12-b2ca-f046b68fcc6a"
TupleTools = "9d95972d-f1c8-5527-a6e0-b4b365fa01f6"
TypeParameterAccessors = "7e5a90cf-f82e-492e-a09b-e3e26432c138"
VectorInterface = "409d34a3-91d5-4945-b6ec-7529ddf182d8"

[weakdeps]
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
Expand All @@ -31,22 +41,32 @@ ITensorMPSPackageCompilerExt = "PackageCompiler"
ITensorMPSZygoteRulesExt = ["ChainRulesCore", "ZygoteRules"]

[compat]
Adapt = "4.1.0"
Adapt = "4.1"
BackendSelection = "0.1"
ChainRulesCore = "1.10"
Compat = "4.16.0"
DiagonalArrays = "0.3"
FillArrays = "1.13"
GradedArrays = "0.3.1"
HDF5 = "0.14, 0.15, 0.16, 0.17"
ITensors = "0.8, 0.9"
IsApprox = "2.0.0"
ITensors = "0.9"
IsApprox = "2.0"
KrylovKit = "0.8.1, 0.9"
LinearAlgebra = "1.10"
NDTensors = "0.4"
NamedDimsArrays = "0.7"
Observers = "0.2"
PackageCompiler = "1, 2"
Printf = "1.10"
QuantumOperatorAlgebra = "0.1"
QuantumOperatorDefinitions = "0.2"
Random = "1.10"
SerializedElementArrays = "0.1.0"
SerializedElementArrays = "0.1"
SparseArraysBase = "0.5"
TensorAlgebra = "0.3"
Test = "1.10"
TupleTools = "1.5.0"
TupleTools = "1.5"
TypeParameterAccessors = "0.3"
VectorInterface = "0.5"
ZygoteRules = "0.2.2"
julia = "1.10"

Expand Down
73 changes: 49 additions & 24 deletions examples/dmrg/1d_heisenberg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,62 @@ using ITensors, ITensorMPS
using Printf
using Random

Random.seed!(1234)
using Adapt: adapt
using JLArrays: JLArray
using Metal: MtlArray
using SerializedArrays: SerializedArray

let
N = 100
dev = adapt(SerializedArray)

# Create N spin-one degrees of freedom
sites = siteinds("S=1", N)
# Alternatively can make spin-half sites instead
#sites = siteinds("S=1/2", N)
using ConstructionBase: constructorof
using GPUArraysCore: AbstractGPUArray
using TensorAlgebra: TensorAlgebra, factorize
function TensorAlgebra.factorize(
a::AbstractGPUArray, labels, codomain_labels, domain_labels; kwargs...
)
x, y = factorize(Array(a), labels, codomain_labels, domain_labels; kwargs...)
return constructorof(typeof(a)).((x, y))
end

# Input operator terms which define a Hamiltonian
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
# Convert these terms to an MPO tensor network
H = MPO(os, sites)

# Create an initial random matrix product state
psi0 = random_mps(sites; linkdims=10)

# Plan to do 5 DMRG sweeps:
nsweeps = 5
# Set maximum MPS bond dimensions for each sweep
maxdim = [10, 20, 100, 100, 200]
# Set maximum truncation error allowed when adapting bond dimensions
cutoff = [1E-11]

# Run the DMRG algorithm, returning energy and optimized MPS
energy, psi = dmrg(H, psi0; nsweeps, maxdim, cutoff)
@printf("Final energy = %.12f\n", energy)
return os
end

Random.seed!(1234)

N = 10

# Create N spin-one degrees of freedom
sites = siteinds("S=1", N)
# Alternatively can make spin-half sites instead
# sites = siteinds("S=1/2", N)

os = heisenberg(N)

# Input operator terms which define a Hamiltonian
# Convert these terms to an MPO tensor network
H = dev(MPO(os, sites))

# Create an initial random matrix product state
psi0 = dev(random_mps(sites; maxdim=10))
# psi0 = random_mps(j -> isodd(j) ? "↑" : "↓", sites; maxdim=10)
# psi0 = MPS(j -> isodd(j) ? "↑" : "↓", sites)

# Plan to do 5 DMRG sweeps:
nsweeps = 5
# Set maximum MPS bond dimensions for each sweep
maxdim = [10]
# Set maximum truncation error allowed when adapting bond dimensions
cutoff = [1E-11]

# Run the DMRG algorithm, returning energy and optimized MPS
energy, psi = dmrg(H, psi0; nsweeps, maxdim, cutoff)
@show inner(psi', H, psi)
@show inner(psi, psi)
@printf("Final energy = %.12f\n", energy)
57 changes: 31 additions & 26 deletions examples/dmrg/1d_heisenberg_conserve_spin.jl
Original file line number Diff line number Diff line change
@@ -1,39 +1,44 @@
using BlockSparseArrays
using ITensors, ITensorMPS
using LinearAlgebra
using Printf
using Random
using Strided

Random.seed!(1234)
BLAS.set_num_threads(1)
Strided.set_num_threads(1)
ITensors.enable_threaded_blocksparse()
#ITensors.disable_threaded_blocksparse()

let
N = 100

sites = siteinds("S=1", N; conserve_qns=true)
using SymmetrySectors

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

Random.seed!(1234)

state = [isodd(n) ? "Up" : "Dn" for n in 1:N]
psi0 = random_mps(sites, state; linkdims=10)
N = 10

# Plan to do 5 DMRG sweeps:
nsweeps = 5
# Set maximum MPS bond dimensions for each sweep
maxdim = [10, 20, 100, 100, 200]
# Set maximum truncation error allowed when adapting bond dimensions
cutoff = [1E-11]
s = siteinds("S=1/2", N; gradings=("Sz",))

# Run the DMRG algorithm, returning energy and optimized MPS
energy, psi = dmrg(H, psi0; nsweeps, maxdim, cutoff)
@printf("Final energy = %.12f\n", energy)
end
os = heisenberg(N)

# Create an initial random matrix product state
psi0 = random_mps(j -> isodd(j) ? "↑" : "↓", s; maxdim=10)
# psi0 = MPS(j -> isodd(j) ? "↑" : "↓", s)

# Input operator terms which define a Hamiltonian
# Convert these terms to an MPO tensor network
H = MPO(os, s)

# Plan to do 5 DMRG sweeps:
nsweeps = 5
# Set maximum MPS bond dimensions for each sweep
maxdim = [10]
# Set maximum truncation error allowed when adapting bond dimensions
cutoff = [1E-11]

# Run the DMRG algorithm, returning energy and optimized MPS
energy, psi = dmrg(H, psi0; nsweeps, maxdim, cutoff)
@show inner(psi', H, psi)
@show inner(psi, psi)
@printf("Final energy = %.12f\n", energy)
8 changes: 8 additions & 0 deletions examples/dmrg/Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
[deps]
ConstructionBase = "187b0558-2788-49d3-abe0-74a17ed4e7c9"
GPUArraysCore = "46192b85-c4d5-4398-a991-12ede77f4527"
ITensorBase = "4795dd04-0d67-49bb-8f44-b89c448a1dc7"
ITensorMPS = "0d1a4710-d33b-49a5-8f18-73bdf49b47e2"
ITensors = "9136182c-28ba-11e9-034c-db9fb085ebd5"
JLArrays = "27aeb0d3-9eb9-45fb-866b-73c2ecf80fcb"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
MatrixAlgebraKit = "6c742aac-3347-4629-af66-fc926824e5e4"
Metal = "dde4c033-4e86-420c-a63e-0dd931031962"
NamedDimsArrays = "60cbd0c0-df58-4cb7-918c-6f5607b73fde"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
SerializedArrays = "621c0da3-e96e-4f80-bd06-5ae31cdfcb39"
Strided = "5e0ebb24-38b0-5f93-81fe-25c709ecae67"
2 changes: 1 addition & 1 deletion ext/ITensorMPSChainRulesCoreExt/abstractmps.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ using ChainRulesCore: ChainRulesCore, HasReverseMode, NoTangent, RuleConfig, rru
using ITensors:
ITensors, ITensor, dag, hassameinds, inds, itensor, mapprime, replaceprime, swapprime
using ITensorMPS: ITensorMPS, MPO, MPS, apply, inner, siteinds
using NDTensors: datatype
## using NDTensors: datatype

function ChainRulesCore.rrule(
::Type{T}, x::Vector{<:ITensor}; kwargs...
Expand Down
2 changes: 1 addition & 1 deletion ext/ITensorMPSPackageCompilerExt/compile.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using NDTensors: @Algorithm_str
using BackendSelection: @Algorithm_str
using ITensors: ITensors
using PackageCompiler: PackageCompiler

Expand Down
2 changes: 1 addition & 1 deletion src/ITensorMPS.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module ITensorMPS
using ITensors
include("imports.jl")
include("exports.jl")
include("siteinds.jl")
include("abstractmps.jl")
include("mps.jl")
include("mpo.jl")
Expand All @@ -20,7 +21,6 @@ include("opsum_to_mpo/qnmatelem.jl")
include("opsum_to_mpo/opsum_to_mpo_generic.jl")
include("opsum_to_mpo/opsum_to_mpo.jl")
include("opsum_to_mpo/opsum_to_mpo_qn.jl")
include("deprecated.jl")
include("defaults.jl")
include("update_observer.jl")
include("lattices/lattices.jl")
Expand Down
Loading
Loading