"Excitations with DMRG and segment boundary conditions" notebook questions

How do I use this algorithm? What does that parameter do?
Post Reply
kieran_c
Posts: 1
Joined: 09 Apr 2024, 15:07

"Excitations with DMRG and segment boundary conditions" notebook questions

Post by kieran_c »

I'm working through the "Excitations with DMRG and segment boundary conditions" notebook (https://tenpy.readthedocs.io/en/latest/ ... inite.html) and encountering a few issues. Ultimately I'm trying to implement segment boundary conditions to evaluate the expectation value of an MPO acting on a finite number of sites of a translationally invariant MPS.

Issues:

1) When running all cells of the notebook without alterations, I encounter the following error when runnnig

Python: Select all

E1_s, _ = eng.run()

Python: Select all

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[26], line 2
      1 eng = dmrg.TwoSiteDMRGEngine(psi1_s, M_s, dmrg_params, resume_data=resume_psi1_s)
----> 2 E1_s, _ = eng.run()

File ~/Desktop/numerical_spt_classification/code/venv/lib/python3.11/site-packages/tenpy/algorithms/dmrg.py:459, in DMRGEngine.run(self)
    448 def run(self):
    449     """Run the DMRG simulation to find the ground state.
    450 
    451     Returns
   (...)
    457         i.e. just a reference to :attr:`psi`.
    458     """
--> 459     return super().run()

File ~/Desktop/numerical_spt_classification/code/venv/lib/python3.11/site-packages/tenpy/algorithms/mps_common.py:779, in IterativeSweeps.run(self)
    777 if not is_first_sweep:
    778     self.checkpoint.emit(self)
--> 779 result = self.run_iteration()
    780 self.status_update(iteration_start_time=iteration_start_time)
    781 is_first_sweep = False

File ~/Desktop/numerical_spt_classification/code/venv/lib/python3.11/site-packages/tenpy/algorithms/dmrg.py:307, in DMRGEngine.run_iteration(self)
    305 logger.info('Running sweep with optimization')
    306 for i in range(self.N_sweeps_check - 1):
--> 307     self.sweep(meas_E_trunc=False)
    308 max_trunc_err = self.sweep(meas_E_trunc=True)
    309 max_E_trunc = np.max(self.E_trunc_list)

File ~/Desktop/numerical_spt_classification/code/venv/lib/python3.11/site-packages/tenpy/algorithms/dmrg.py:544, in DMRGEngine.sweep(self, optimize, meas_E_trunc)
    538 """One 'sweep' of the algorithm.
    539 
    540 Thin wrapper around :meth:`tenpy.algorithms.mps_common.Sweep.sweep` with one additional
    541 parameter `meas_E_trunc` specifying whether to measure truncation energies.
    542 """
    543 self._meas_E_trunc = meas_E_trunc
--> 544 return super().sweep(optimize)

File ~/Desktop/numerical_spt_classification/code/venv/lib/python3.11/site-packages/tenpy/algorithms/mps_common.py:381, in Sweep.sweep(self, optimize)
    379     update_data = self.update_local(theta, optimize=optimize)
    380     self.update_env(**update_data)
--> 381     self.post_update_local(**update_data)
    382     self.free_no_longer_needed_envs()
    384 if optimize:  # count optimization sweeps

File ~/Desktop/numerical_spt_classification/code/venv/lib/python3.11/site-packages/tenpy/algorithms/dmrg.py:632, in DMRGEngine.post_update_local(self, E0, age, N, ov_change, err, **update_data)
    629 self.E_trunc_list.append(E_trunc)
    631 if self.psi.bc == 'segment':
--> 632     self.update_segment_boundaries()

File ~/Desktop/numerical_spt_classification/code/venv/lib/python3.11/site-packages/tenpy/algorithms/dmrg.py:656, in DMRGEngine.update_segment_boundaries(self)
    653 psi.set_B(j, A_new, form='A')
    655 old_UL, old_VR = psi.segment_boundaries
--> 656 new_UL = npc.tensordot(old_UL, U, axes=['vR', 'vL'])
    657 psi.segment_boundaries = (new_UL, old_VR)
    659 for env in self._all_envs:

File ~/Desktop/numerical_spt_classification/code/venv/lib/python3.11/site-packages/tenpy/linalg/np_conserved.py:3476, in tensordot(a, b, axes)
   3448 """Similar as ``np.tensordot`` but for :class:`Array`.
   3449 
   3450 Builds the tensor product of `a` and `b` and sums over the specified axes.
   (...)
   3473     Returns a scalar in case of a full contraction.
   3474 """
   3475 # for details on the implementation, see _tensordot_worker.
-> 3476 a, b, axes = _tensordot_transpose_axes(a, b, axes)
   3478 # optimize/check for special cases
   3479 no_block = (a.stored_blocks == 0 or b.stored_blocks == 0)  # result is zero

File ~/Desktop/numerical_spt_classification/code/venv/lib/python3.11/site-packages/tenpy/linalg/_npc_helper.pyx:1261, in tenpy.linalg._npc_helper._tensordot_transpose_axes()

AttributeError: 'NoneType' object has no attribute 'rank'
2) I have tried reproducing the work of this notebook for a different model:

Python: Select all

class TransverseCluster(CouplingModel):
    def __init__(self, model_params):
        # Read out/set default parameters
        name = "Cluster Ising model"
        L = model_params.get('L', 2)
        B = model_params.get('B', 0)
        bc_MPS = model_params.get('bc_MPS', 'infinite')
        
        # sites
        site = SpinHalfSite(conserve=None)

        # lattice
        bc = 'periodic'
        lat = Chain(L, site, bc=bc, bc_MPS=bc_MPS)

        # initialize CouplingModel
        CouplingModel.__init__(self, lat)

        # add terms of the Hamiltonian
        self.add_onsite(-B, 0, 'Sigmax')
        self.add_multi_coupling(
            -1,
            [
                ('Sigmaz', -1, 0),
                ('Sigmax', 0, 0),
                ('Sigmaz', 1, 0),
            ]
        )

        # initialize H_MPO
        MPOModel.__init__(self, lat, self.calc_H_MPO())
However when proceeding through the same steps as in the notebook, I encounter the following error when initializing the DMRGEngine with the additional initialization environment data:

Python: Select all

File ~/Desktop/numerical_spt_classification/code/venv/lib/python3.11/site-packages/tenpy/networks/mpo.py:2192, in MPOEnvironment.test_sanity(self)
   2190 def test_sanity(self):
   2191     """Sanity check, raises ValueErrors, if something is wrong."""
-> 2192     assert (self.bra.finite == self.ket.finite == self.H.finite == self.finite)
   2193     # check that the physical legs are contractable
   2194     for b_s, H_s, k_s in zip(self.bra.sites, self.H.sites, self.ket.sites):

AssertionError: 
Tracing back through the errors, this seems to be because for an instance of m of TransverseCluster, m.H_MPO.finite is False whereas it is true for the TFIChain model used in the notebook. I'm not sure how to proceed.

Thanks in advance for any help provided!
dperkovic
Posts: 1
Joined: 23 Oct 2024, 19:34

Re: "Excitations with DMRG and segment boundary conditions" notebook questions

Post by dperkovic »

I am having the same problem. Have you managed to resolve this?
Post Reply