@@ -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 ])
9999end
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+
113101function expectation_value(ψ:: FiniteMPS , H:: FiniteMPOHamiltonian ,
114- envs:: Cache = environments(ψ, H))
102+ envs:: AbstractMPSEnvironments = environments(ψ, H))
115103 return dot(ψ, H, ψ, envs) / dot(ψ, ψ)
116104end
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+
134106function 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
141113end
142114
143- # no definition for WindowMPS -> not well defined
144-
145115# DenseMPO
146116# --------
147117function 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))
186156end
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
210159function expectation_value(ψ, H:: LinearCombination , envs:: LazyLincoCache = environments(ψ, H))
211160 return sum(((c, op, env),) -> c * expectation_value(ψ, op, env),
215164# ProjectionOperator
216165# ------------------
217166function 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)
0 commit comments