MPS.expectation_value_term() not working for iDMRG

How do I use this algorithm? What does that parameter do?
Post Reply
yixuan
Posts: 4
Joined: 20 May 2021, 00:31

MPS.expectation_value_term() not working for iDMRG

Post by yixuan »

Hi all,

I found that the segment_boundaries in the MPS class is only defined for finite DMRG, and I run into this error for iDMRG when calling expectation_value() or its relatives expectation_value_term(), expectation_value_terms_sum() like this:

File "iDMRG.py", line 716, in order
order += psi.expectation_value_terms_sum(list_sum)[
File "/TeNPy/tenpy/networks/mps.py", line 2200, in expectation_value_terms_sum
terms_sum = mpo_.expectation_value(self, max_range=ct.max_range())
File "/TeNPy/tenpy/networks/mpo.py", line 666, in expectation_value
env = MPOEnvironment(psi, self, psi, start_env_sites=0)
File "/TeNPy/tenpy/networks/mpo.py", line 1780, in __init__
super().__init__(bra, ket, cache, **init_env_data)
File "/TeNPy/tenpy/networks/mps.py", line 4072, in __init__
self.init_first_LP_last_RP(**init_env_data)
File "/TeNPy/tenpy/networks/mpo.py", line 1828, in init_first_LP_last_RP
super().init_first_LP_last_RP(init_LP, init_RP, age_LP, age_RP, start_env_sites)
File "/tenpy/networks/mps.py", line 4097, in init_first_LP_last_RP
ket_U, ket_V = self.ket.segment_boundaries
AttributeError: 'MPS' object has no attribute 'segment_boundaries'

The correlation_function() works fine, but I need to calculate many terms so the MPO conversion in the function above may be more efficient. How can I define the segment boundaries for MPS class in iDMRG? (I use v0.8.4)

Best regards,

Yixuan
User avatar
Johannes
Site Admin
Posts: 413
Joined: 21 Jul 2018, 12:52
Location: TU Munich

Re: MPS.expectation_value_term() not working for iDMRG

Post by Johannes »

I'm not sure if I understand what you're doing with which boundary conditions.
Indeed, "segment" boundary conditions yield a finite DMRG, because the "segment" is a finite region extracted from an infinite MPS, and you only optimize that region keeping the environments fixed. The idea is to find the ground state with iDMRG, then extract a finite segment and rerun *finite* DMRG inside the segment to find excitations.

Expectation values of operators inside this segment should work as expected; but expectation values and correlation functions going outside of the segment will not yield correct values; I think they should raise an error (?).

Or are you just trying to run some infinite DMRG?
The MPS.segment_boundaries have only been added recently. Any new MPS will set them to (None, None) by default, but if you load a pickled MPS saved with a previous TeNPy version, it might not get added. If this is the issue, you can set them explicitly:

Code: Select all

with open('my_data.pkl', 'rb') as f:
    data = pickle.load(f)
psi = data['psi']  # or wherever the MPS is you use...
psi.segment_boundaries = (None, None)
# continue to call iDMRG and expectation values
Post Reply