Making an MPO given its tensors

How do I use this algorithm? What does that parameter do?
Post Reply
Posts: 4
Joined: 21 Sep 2022, 18:40

Making an MPO given its tensors

Post by nick »

I am hoping to run DMRG on the Hermitian transfer matrices of certain lattice and vertex models, like the 2d Ising model. These models' transfer matrices have the nice property that they can be represented as MPOs with explicit bulk and edge tensors. I believe that to run DMRG in TeNPy to find the extremal eigenvectors, I will first need to generate an MPO.

I know the explicit form of the bulk tensors and edge vectors, \(M_{ij}^{[m_1 m_2]}, \, l_{i}^{[m_1 m_2]}, r_{i}^{[m_1 m_2]}\).
For example, for a bulk tensor, I have a \(\chi\) by \(\chi\) by \(d\) by \(d\) numpy array filled with floats, where \(\chi\) is the bond dimension and \(d\) is the physical dimension.

In reading the documentation for tenpy.networks.mpo, it looks like I can initialize MPOs with tenpy.networks.mpo.MPO, but this appears to require a different format than numpy arrays. How can I turn my numpy arrays into the \(W\) tensors that TeNPy accepts? Thank you for the help!
To make this more concrete, here's an example of a case with \(\chi = d= 2\).

Code: Select all

import numpy as np
import tenpy
import tenpy.linalg.np_conserved as npc
from tenpy.algorithms import dmrg
from tenpy.networks.mps import MPS
from tenpy.networks.mpo import MPO"INFO")
from import SpinSite
from tenpy.models.lattice import Chain
from tenpy.models.model import CouplingModel, NearestNeighborModel, MPOModel

N=6 #number of sites
t = 1/2 #tanh(beta)

t_arr = np.array([t**2,0,0,t, 0,t,t,0, 0,t,t,0, t,0,0,1])
t_arr = t_arr.reshape((2,2,2,2)) #bulk tensor

edge_arr = np.array([0,t,t,0, t,0,0,1])
edge_arr_left = edge_arr.reshape((1,2,2,2)) #left tensor
edge_arr_right = edge_arr.reshape((2,1,2,2)) #right tensor

### need to fix up the above tensors

Ws = [edge_arr_left] + (N-2)*[t_arr] + [edge_arr_right]
spin = SpinSite(conserve='None')

H = MPO([spin] * N, Ws, bc='finite', IdL=0, IdR=-1)
Currently, I get the error "'numpy.ndarray' object has no attribute 'get_leg'" when trying to define H.
Posts: 4
Joined: 21 Sep 2022, 18:40

Re: Making an MPO given its tensors

Post by nick »

After reading the documentation more thoroughly, I see that the intermediate step that was missing was to use "tenpy.linalg.np_conserved.Array.from_ndarray_trivial" to convert my arrays to the appropriate format. This solves my problem, and my classical lattice computations are running smoothly. I'll experiment with including leg charges in the future!
Post Reply