Skip to content

Commit be16cd5

Browse files
authored
Merge pull request #15 from tensor4all/support_ITensors0.7
Support ITensors 0.7.x
2 parents ee8803e + 421bd94 commit be16cd5

File tree

8 files changed

+79
-16
lines changed

8 files changed

+79
-16
lines changed

Project.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,23 @@ authors = ["Hiroshi Shinaoka <[email protected]> and contributors"]
44
version = "0.2.5"
55

66
[deps]
7-
ITensorTDVP = "25707e16-a4db-4a07-99d9-4d67b7af0342"
7+
ITensorMPS = "0d1a4710-d33b-49a5-8f18-73bdf49b47e2"
88
ITensors = "9136182c-28ba-11e9-034c-db9fb085ebd5"
99
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
1010
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
1111

1212
[compat]
13-
ITensorTDVP = "^0.4"
14-
ITensors = "^0.3.62, 0.6"
13+
ITensorMPS = "0.3.1"
14+
ITensors = "0.7"
1515
StaticArrays = "1"
1616
julia = "1"
1717

1818
[extras]
1919
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
2020
JET = "c3a54625-cd67-489e-a8e7-0a5a0ff4e31b"
2121
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
22-
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
2322
StableRNGs = "860ef19b-820b-49d6-a774-d7a799459cd3"
23+
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
2424

2525
[targets]
2626
test = ["Test", "Random", "Aqua", "JET", "StableRNGs"]

src/FastMPOContractions.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ module FastMPOContractions
33
using StaticArrays
44

55
using ITensors
6-
import ITensors.ITensorMPS:
6+
import ITensorMPS:
77
AbstractMPS, sim!, setleftlim!, setrightlim!, check_hascommoninds
88

9-
using ITensorTDVP
9+
using ITensorMPS
1010

1111
include("densitymatrix.jl")
1212
include("fitalgorithm.jl")

src/fitalgorithm.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Only temporary, until the performance issune in ITensorNetworks.jl is fixed.
2-
import ITensors.ITensorMPS: AbstractProjMPO, makeL!, makeR!, set_nsite!, OneITensor
2+
import ITensorMPS: AbstractProjMPO, makeL!, makeR!, set_nsite!, OneITensor
33
import Base: copy
44

55
"""
@@ -56,11 +56,11 @@ function contract_fit(A::MPO, psi0::MPS; init_mps = psi0, nsweeps = 1, kwargs...
5656
end
5757
end
5858

59-
reduced_operator = ITensorTDVP.ReducedContractProblem(psi0, A)
60-
return ITensorTDVP.alternating_update(
59+
reduced_operator = ITensorMPS.ReducedContractProblem(psi0, A)
60+
return ITensorMPS.alternating_update(
6161
reduced_operator,
6262
init_mps;
63-
updater = ITensorTDVP.contract_operator_state_updater,
63+
updater = ITensorMPS.contract_operator_state_updater,
6464
nsweeps = nsweeps,
6565
kwargs...,
6666
)

src/fitalgorithm_sum.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
using ITensors.ITensorMPS: ITensorMPS, AbstractProjMPO, MPO, MPS
2-
using ITensors.ITensorMPS: linkinds, replaceinds
1+
using ITensorMPS: ITensorMPS, AbstractProjMPO, MPO, MPS
2+
using ITensorMPS: linkinds, replaceinds
33
using ITensors: ITensors, OneITensor
4-
import ITensorTDVP: alternating_update, rproj, lproj
4+
import ITensorMPS: alternating_update, rproj, lproj
55

66
"""
77
A ReducedFitProblem represents the projection

src/reducedlinearproblem.jl

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
using ITensors: contract
2+
using ITensors.ITensorMPS: AbstractProjMPO, ProjMPO, makeL!, makeR!, nsite, set_nsite!
3+
4+
mutable struct ReducedLinearProblem <: AbstractProjMPO
5+
reduced_operator::ProjMPO
6+
reduced_constant_terms::Vector{ReducedConstantTerm}
7+
end
8+
9+
# Linear problem updater interface.
10+
operator(reduced_problem::ReducedLinearProblem) = reduced_problem.reduced_operator
11+
function constant_term(reduced_problem::ReducedLinearProblem)
12+
constant_terms = map(reduced_problem.reduced_constant_terms) do reduced_constant_term
13+
return contract(reduced_constant_term)
14+
end
15+
return dag(only(constant_terms))
16+
end
17+
18+
function ReducedLinearProblem(operator::MPO, constant_term::MPS)
19+
return ReducedLinearProblem(ProjMPO(operator), [ReducedConstantTerm(constant_term)])
20+
end
21+
22+
function ReducedLinearProblem(operator::MPO, constant_terms::Vector{MPS})
23+
return ReducedLinearProblem(ProjMPO(operator), ReducedConstantTerm.(constant_terms))
24+
end
25+
26+
function Base.copy(reduced_problem::ReducedLinearProblem)
27+
return ReducedLinearProblem(
28+
copy(reduced_problem.reduced_operator), copy(reduced_problem.reduced_constant_terms)
29+
)
30+
end
31+
32+
function ITensorMPS.nsite(reduced_problem::ReducedLinearProblem)
33+
return nsite(reduced_problem.reduced_operator)
34+
end
35+
36+
function ITensorMPS.set_nsite!(reduced_problem::ReducedLinearProblem, nsite)
37+
set_nsite!(reduced_problem.reduced_operator, nsite)
38+
for m in reduced_problem.reduced_constant_terms
39+
set_nsite!(m, nsite)
40+
end
41+
return reduced_problem
42+
end
43+
44+
function ITensorMPS.makeL!(reduced_problem::ReducedLinearProblem, state::MPS, position::Int)
45+
makeL!(reduced_problem.reduced_operator, state, position)
46+
for reduced_constant_term in reduced_problem.reduced_constant_terms
47+
makeL!(reduced_constant_term, state, position)
48+
end
49+
return reduced_problem
50+
end
51+
52+
function ITensorMPS.makeR!(reduced_problem::ReducedLinearProblem, state::MPS, position::Int)
53+
makeR!(reduced_problem.reduced_operator, state, position)
54+
for reduced_constant_term in reduced_problem.reduced_constant_terms
55+
makeR!(reduced_constant_term, state, position)
56+
end
57+
return reduced_problem
58+
end
59+
60+
function ITensors.contract(reduced_problem::ReducedLinearProblem, v::ITensor)
61+
return contract(reduced_problem.reduced_operator, v)
62+
end

test/_util.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using ITensors
2+
using ITensorMPS
23
using Random
34

45
function _random_mpo(sites::Vector{Vector{Index{T}}}; linkdims = 1) where {T}

test/fitalgorithm.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using Test
22
import FastMPOContractions as FMPOC
33
using ITensors
4-
using ITensorTDVP
4+
using ITensorMPS
55
using Random
66

77
@testset "fitalgorithm.jl" begin

test/fitalgorithm_sum.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import FastMPOContractions as FMPOC
22
using ITensors
3-
using ITensorTDVP
4-
using ITensors: random_itensor, Algorithm, random_mps
3+
using ITensorMPS
4+
using ITensors: random_itensor, Algorithm
55
using Random
66
using StableRNGs
77

0 commit comments

Comments
 (0)