Skip to content

Commit 0ad721d

Browse files
committed
Rename environments/files and cleanup unused code
1 parent ceefc7d commit 0ad721d

File tree

19 files changed

+464
-744
lines changed

19 files changed

+464
-744
lines changed

docs/src/lib/lib.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,12 @@ MPOHamiltonian
1818

1919
## Environments
2020
```@docs
21-
MPSKit.AbstractInfEnv
21+
MPSKit.AbstractMPSEnvironments
22+
MPSKit.AbstractInfiniteEnvironments
2223
MPSKit.InfiniteMPOEnvironments
23-
MPSKit.MPOHamInfEnv
24-
MPSKit.FinEnv
25-
MPSKit.IDMRGEnvs
24+
MPSKit.InfiniteMPOHamiltonianEnvironments
25+
MPSKit.FiniteEnvironments
26+
MPSKit.IDMRGEnvironments
2627
```
2728

2829
## Generic actions

src/MPSKit.jl

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ export entanglementplot, transferplot
3333
export braille
3434

3535
# hamiltonian things
36-
export Cache
3736
export AbstractMPO
3837
export MPO, FiniteMPO, InfiniteMPO
3938
export MPOHamiltonian, FiniteMPOHamiltonian, InfiniteMPOHamiltonian, HMPO
@@ -69,7 +68,6 @@ export transfer_left, transfer_right
6968

7069
# Abstract type defs
7170
abstract type Algorithm end
72-
abstract type Cache end # cache "manages" environments
7371

7472
# submodules
7573
include("utility/dynamictols.jl")
@@ -112,14 +110,13 @@ include("operators/lazysum.jl")
112110
include("transfermatrix/transfermatrix.jl")
113111
include("transfermatrix/transfer.jl")
114112

115-
include("environments/abstractenvironments.jl")
116-
include("environments/FinEnv.jl")
117-
include("environments/abstractinfenv.jl")
118-
include("environments/infinitempoenv.jl")
119-
include("environments/mpohaminfenv.jl")
120-
include("environments/qpenv.jl")
121-
include("environments/multipleenv.jl")
122-
include("environments/idmrgenv.jl")
113+
include("environments/abstract_envs.jl")
114+
include("environments/finite_envs.jl")
115+
include("environments/infinitempo_envs.jl")
116+
include("environments/infinitempohamiltonian_envs.jl")
117+
include("environments/qp_envs.jl")
118+
include("environments/idmrg_envs.jl")
119+
include("environments/multiple_envs.jl")
123120
include("environments/lazylincocache.jl")
124121

125122
include("algorithms/fixedpoint.jl")

src/algorithms/approximate/idmrg.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ function approximate(ost::MPSMultiline, toapprox::Tuple{<:MPOMultiline,<:MPSMult
22
alg::IDMRG1, oenvs=environments(ost, toapprox))
33
ψ = copy(ost)
44
mpo, above = toapprox
5-
envs = IDMRGEnv(ost, oenvs)
5+
envs = IDMRGEnvironments(ost, oenvs)
66
log = IterLog("IDMRG")
77
ϵ::Float64 = 2 * alg.tol
88

@@ -62,7 +62,7 @@ function approximate(ost::MPSMultiline, toapprox::Tuple{<:MPOMultiline,<:MPSMult
6262
length(ost) < 2 && throw(ArgumentError("unit cell should be >= 2"))
6363
mpo, above = toapprox
6464
ψ = copy(ost)
65-
envs = IDMRGEnv(ost, oenvs)
65+
envs = IDMRGEnvironments(ost, oenvs)
6666
ϵ::Float64 = 2 * alg.tol
6767
log = IterLog("IDMRG2")
6868

src/algorithms/derivatives.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ function ∂C(x::Vector, leftenv, rightenv)
199199
end
200200

201201
#downproject for approximate
202-
function c_proj(pos, below, envs::FinEnv)
202+
function c_proj(pos, below, envs::FiniteEnvironments)
203203
return ∂C(envs.above.CR[pos], leftenv(envs, pos + 1, below), rightenv(envs, pos, below))
204204
end
205205

src/algorithms/expval.jl

Lines changed: 6 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ acts, while the operator is either a `AbstractTensorMap` or a `FiniteMPO`.
1515
* `ψ::AbstractMPS` : the state on which to compute the expectation value
1616
* `O::Union{AbstractMPO,Pair}` : the operator to compute the expectation value of.
1717
This can either be an `AbstractMPO`, or a pair of indices and local operator..
18-
* `environments::Cache` : the environments to use for the calculation. If not given, they will be calculated.
18+
* `environments::AbstractMPSEnvironments` : the environments to use for the calculation. If not given, they will be calculated.
1919
2020
# Examples
2121
```jldoctest
@@ -97,51 +97,21 @@ function contract_mpo_expval(AC::MPSTensor, GL::MPSTensor, O::MPOTensor, GR::MPS
9797
return @plansor GL[1 2; 3] * AC[3 7; 5] * GR[5 8; 6] *
9898
O[2 4; 7 8] * conj(ACbar[1 4; 6])
9999
end
100-
# function expectation_value(ψ::FiniteMPS, H::MPOHamiltonian,
101-
# envs::Cache=environments(ψ, H))
102-
# L = length(ψ) ÷ 2
103-
# GL = leftenv(envs, L, ψ)
104-
# GR = rightenv(envs, L, ψ)
105-
# AC = ψ.AC[L]
106-
# E = sum(keys(H[L])) do (j, k)
107-
# return contract_mpo_expval(AC, GL[j], H[L][j, k], GR[k], AC)
108-
# # return @plansor GL[j][1 2; 3] * AC[3 7; 5] * GR[k][5 8; 6] * conj(AC[1 4; 6]) *
109-
# # H[L][j, k][2 4; 7 8]
110-
# end
111-
# return E / norm(ψ)^2
112-
# end
100+
113101
function expectation_value(ψ::FiniteMPS, H::FiniteMPOHamiltonian,
114-
envs::Cache=environments(ψ, H))
102+
envs::AbstractMPSEnvironments=environments(ψ, H))
115103
return dot(ψ, H, ψ, envs) / dot(ψ, ψ)
116104
end
117-
# function expectation_value(ψ::FiniteQP, H::MPOHamiltonian)
118-
# return expectation_value(convert(FiniteMPS, ψ), H)
119-
# end
120-
# function expectation_value(ψ::InfiniteMPS, H::MPOHamiltonian,
121-
# envs::Cache=environments(ψ, H))
122-
# # TODO: this presumably could be done more efficiently
123-
# return sum(1:length(ψ)) do i
124-
# return sum((H.odim):-1:1) do j
125-
# ρ_LL = r_LL(ψ, i)
126-
# util = fill_data!(similar(ψ.AL[1], space(envs.lw[H.odim, i + 1], 2)), one)
127-
# GL = leftenv(envs, i, ψ)
128-
# return @plansor (GL[j] * TransferMatrix(ψ.AL[i], H[i][j, H.odim], ψ.AL[i]))[1 2;
129-
# 3] *
130-
# ρ_LL[3; 1] * conj(util[2])
131-
# end
132-
# end
133-
# end
105+
134106
function expectation_value(ψ::InfiniteMPS, H::InfiniteMPOHamiltonian,
135-
envs::Cache=environments(ψ, H))
107+
envs::AbstractMPSEnvironments=environments(ψ, H))
136108
return sum(1:length(ψ)) do i
137109
util = fill_data!(similar(ψ.AL[1], right_virtualspace(H, i)[end]), one)
138110
@plansor GR[-1 -2; -3] := r_LL(ψ, i)[-1; -3] * conj(util[-2])
139111
return contract_mpo_expval(ψ.AL[i], leftenv(envs, i, ψ), H[i][:, 1, 1, end], GR)
140112
end
141113
end
142114

143-
# no definition for WindowMPS -> not well defined
144-
145115
# DenseMPO
146116
# --------
147117
function expectation_value(ψ::FiniteMPS, mpo::FiniteMPO)
@@ -185,27 +155,6 @@ function expectation_value(ψ, ops::LazySum, envs::MultipleEnvironments)
185155
return sum(((op, env),) -> expectation_value(ψ, op, env), zip(ops.ops, envs))
186156
end
187157

188-
# Transfer matrices
189-
# -----------------
190-
# function expectation_value(ψ::InfiniteMPS, mpo::DenseMPO)
191-
# return expectation_value(convert(MPSMultiline, ψ), convert(MPOMultiline, mpo))
192-
# end
193-
# function expectation_value(ψ::MPSMultiline, mpo::MPOMultiline)
194-
# return expectation_value(ψ, environments(ψ, mpo))
195-
# end
196-
# function expectation_value(ψ::InfiniteMPS, ca::PerMPOInfEnv)
197-
# return expectation_value(convert(MPSMultiline, ψ), ca)
198-
# end
199-
# function expectation_value(ψ::MPSMultiline, O::MPOMultiline, ca::PerMPOInfEnv)
200-
# retval = PeriodicMatrix{scalartype(ψ)}(undef, size(ψ, 1), size(ψ, 2))
201-
# for (i, j) in product(1:size(ψ, 1), 1:size(ψ, 2))
202-
# retval[i, j] = @plansor leftenv(ca, i, j, ψ)[1 2; 3] * O[i, j][2 4; 6 5] *
203-
# ψ.AC[i, j][3 6; 7] * rightenv(ca, i, j, ψ)[7 5; 8] *
204-
# conj(ψ.AC[i + 1, j][1 4; 8])
205-
# end
206-
# return retval
207-
# end
208-
209158
# for now we also have LinearCombination
210159
function expectation_value(ψ, H::LinearCombination, envs::LazyLincoCache=environments(ψ, H))
211160
return sum(((c, op, env),) -> c * expectation_value(ψ, op, env),
@@ -215,7 +164,7 @@ end
215164
# ProjectionOperator
216165
# ------------------
217166
function expectation_value(ψ::FiniteMPS, O::ProjectionOperator,
218-
envs::FinEnv=environments(ψ, O))
167+
envs::FiniteEnvironments=environments(ψ, O))
219168
ens = zeros(scalartype(ψ), length(ψ))
220169
for i in 1:length(ψ)
221170
operator = ∂∂AC(i, ψ, O, envs)

src/algorithms/groundstate/find_groundstate.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ optimization algorithm will be attempted based on the supplied keywords.
1616
- `maxiter::Int`: maximum amount of iterations
1717
- `verbosity::Int`: display progress information
1818
"""
19-
function find_groundstate(ψ::AbstractMPS, H, envs::Cache=environments(ψ, H);
19+
function find_groundstate(ψ::AbstractMPS, H,
20+
envs::AbstractMPSEnvironments=environments(ψ, H);
2021
tol=Defaults.tol, maxiter=Defaults.maxiter,
2122
verbosity=Defaults.verbosity, trscheme=nothing)
2223
if isa(ψ, InfiniteMPS)

src/algorithms/groundstate/idmrg.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ end
2626
function find_groundstate(ost::InfiniteMPS, H, alg::IDMRG1, oenvs=environments(ost, H))
2727
ϵ::Float64 = calc_galerkin(ost, oenvs)
2828
ψ = copy(ost)
29-
envs = IDMRGEnv(ost, oenvs)
29+
envs = IDMRGEnvironments(ost, oenvs)
3030
log = IterLog("IDMRG")
3131

3232
LoggingExtras.withlevel(; alg.verbosity) do
@@ -106,7 +106,7 @@ function find_groundstate(ost::InfiniteMPS, H, alg::IDMRG2, oenvs=environments(o
106106
ϵ::Float64 = calc_galerkin(ost, oenvs)
107107

108108
ψ = copy(ost)
109-
envs = IDMRGEnv(ost, oenvs)
109+
envs = IDMRGEnvironments(ost, oenvs)
110110
log = IterLog("IDMRG2")
111111

112112
LoggingExtras.withlevel(; alg.verbosity) do

src/algorithms/timestep/tdvp.jl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ algorithm for time evolution.
1919
end
2020

2121
function timestep(ψ::InfiniteMPS, H, t::Number, dt::Number, alg::TDVP,
22-
envs::Union{Cache,MultipleEnvironments}=environments(ψ, H);
22+
envs::AbstractMPSEnvironments=environments(ψ, H);
2323
leftorthflag=true)
2424
temp_ACs = similar(ψ.AC)
2525
temp_CRs = similar(ψ.CR)
@@ -59,7 +59,7 @@ function timestep(ψ::InfiniteMPS, H, t::Number, dt::Number, alg::TDVP,
5959
end
6060

6161
function timestep!(ψ::AbstractFiniteMPS, H, t::Number, dt::Number, alg::TDVP,
62-
envs::Union{Cache,MultipleEnvironments}=environments(ψ, H))
62+
envs::AbstractMPSEnvironments=environments(ψ, H))
6363

6464
# sweep left to right
6565
for i in 1:(length(ψ) - 1)
@@ -113,7 +113,7 @@ algorithm for time evolution.
113113
end
114114

115115
function timestep!(ψ::AbstractFiniteMPS, H, t::Number, dt::Number, alg::TDVP2,
116-
envs=environments(ψ, H))
116+
envs::AbstractMPSEnvironments=environments(ψ, H))
117117

118118
# sweep left to right
119119
for i in 1:(length(ψ) - 1)
@@ -152,6 +152,7 @@ end
152152

153153
#copying version
154154
function timestep(ψ::AbstractFiniteMPS, H, time::Number, timestep::Number,
155-
alg::Union{TDVP,TDVP2}, envs=environments(ψ, H); kwargs...)
155+
alg::Union{TDVP,TDVP2}, envs::AbstractMPSEnvironments=environments(ψ, H);
156+
kwargs...)
156157
return timestep!(copy(ψ), H, time, timestep, alg, envs; kwargs...)
157158
end

0 commit comments

Comments
 (0)