# VUMPS for multi-site unit cells

**URL:** <https://itensor.discourse.group/t/vumps-for-multi-site-unit-cells/460>\
**Category:** ITensor Julia Questions\
**Tags:** dmrg, mpo\
**Created:** [October 11, 2022, 7:50pm UTC](https://itensor.discourse.group/t/vumps-for-multi-site-unit-cells/460 "2022-10-11T19:50:23Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Meng-Zeng](https://yyz2.discourse-cdn.com/free1/user_avatar/itensor.discourse.group/meng-zeng/32/83_2.png) [@Meng-Zeng](https://itensor.discourse.group/u/Meng-Zeng)\
**Post date:** [October 11, 2022, 7:50pm UTC](https://itensor.discourse.group/t/vumps-for-multi-site-unit-cells/460/1 "2022-10-11T19:50:23Z")

</div>

Hello Miles and Matt,

I’ve been trying to under the [VUMPS](https://github.com/ITensor/ITensorInfiniteMPS.jl/blob/main/examples/vumps/vumps_heisenberg.jl) code for the [Heisenberg model](https://github.com/ITensor/ITensorInfiniteMPS.jl/blob/main/src/models/heisenberg.jl) and then apply to my own multi-site unit cell model.

My first question is concerned with defining the Model using

```julia
function unit_cell_terms(::Model"MyModel")
    opsum = OpSum()
    opsum += ....
end

```

Assuming we have a unit cell consisting of 4 sites, and the interaction term O\_1O\_2O\_3 spans 3 neighboring sites, then if I follow the Heisenberg model definition, I would put

```julia
opsum += O, 1, O, 2, O, 3
opsum += O, 2, O, 3, O, 4

```

Would ITensor automatically include the inter-cell terms like O\_3O\_4O\_5 and O\_4O\_5O\_6? It seems that it would from the given Heisenberg example, but I just want to double check.

My second question is about the following part for the Heisenberg VUMPS:

```julia
function expect_two_site(ψ::InfiniteCanonicalMPS, h::ITensor, n1n2)  
  n1, n2 = n1n2
  ϕ = ψ.AL[n1] * ψ.AL[n2] * ψ.C[n2]
  return inner(ϕ, apply(h, ϕ))				
end

function expect_two_site(ψ::InfiniteCanonicalMPS, h::MPO, n1n2)
  return expect_two_site(ψ, contract(h), n1n2)             
end

bs = [(1, 2), (2, 3)]
energy_infinite = map(b -> expect_two_site(ψ, H[b], b), bs) 

```

It seems to me that the defined function expect\_two\_site() only works for systems with two-site unit cell. If it’s my 4-site unit cell system, then would it be modified like the following?

```julia
function expect_four_site(ψ::InfiniteCanonicalMPS, h::ITensor, n1n2n3n4)  
  n1, n2, n3, n4 = n1n2n3n4 ## n1n2n3n4 is a four-element array
  ϕ = ψ.AL[n1] * ψ.AL[n2]* ψ.C[n2] * ψ.AL[n3]* ψ.C[n3]* ψ.AL[n4]* ψ.C[n4]
  return inner(ϕ, apply(h, ϕ))				
end

function expect_four_site(ψ::InfiniteCanonicalMPS, h::MPO, n1n2n3n4)
  return expect_four_site(ψ, contract(h), n1n2n3n4)             
end

bs = [(1, 2, 3, 4), (2, 3, 4, 5), (3, 4, 5, 6), (4, 5, 6, 7)]
energy_infinite = map(b -> expect_four_site(ψ, H[b], b), bs) 

```

Thanks a lot for your time and I apologize for the long question.  
-Meng

---

<div class="post-metadata">

**Author:** ![mtfishman](https://yyz2.discourse-cdn.com/free1/user_avatar/itensor.discourse.group/mtfishman/32/11_2.png) [@mtfishman](https://itensor.discourse.group/u/mtfishman)\
**Post date:** [October 11, 2022, 9:25pm UTC](https://itensor.discourse.group/t/vumps-for-multi-site-unit-cells/460/2 "2022-10-11T21:25:30Z")

</div>

You should include all unique terms that connect to the first unit cell, so O\_1 O\_2 O\_3, O\_2 O\_3 O\_4, O\_3 O\_4 O\_5, and O\_4 O\_5 O\_6.

The expectation value function would depend on the support of your Hamiltonian, it looks like your Hamiltonian has support on 3 sites so you should use a 3-site wavefunction. Also, you are using too many `ψ.C` terms (only one is required to get the wavefunction), the expectation value would be:

```auto
function expect_three_site(ψ::InfiniteCanonicalMPS, h::ITensor, n1n2n3)  
  n1, n2, n3 = n1n2n3
  ϕ = ψ.AL[n1] * ψ.AL[n2]* ψ.AL[n3] * ψ.C[n3]
  return inner(ϕ, apply(h, ϕ))				
end

```

---

<div class="post-metadata">

**Author:** ![Meng-Zeng](https://yyz2.discourse-cdn.com/free1/user_avatar/itensor.discourse.group/meng-zeng/32/83_2.png) [@Meng-Zeng](https://itensor.discourse.group/u/Meng-Zeng)\
**Post date:** [October 11, 2022, 10:42pm UTC](https://itensor.discourse.group/t/vumps-for-multi-site-unit-cells/460/3 "2022-10-11T22:42:43Z")

</div>

Thank you Matt. Then how come for the Heisenberg model the inter-unit-cell terms are not included?

```julia
  opsum += 0.5, "S+", 1, "S-", 2
  opsum += 0.5, "S-", 1, "S+", 2
  opsum += "Sz", 1, "Sz", 2

```

---

<div class="post-metadata">

**Author:** ![mtfishman](https://yyz2.discourse-cdn.com/free1/user_avatar/itensor.discourse.group/mtfishman/32/11_2.png) [@mtfishman](https://itensor.discourse.group/u/mtfishman)\
**Post date:** [October 20, 2022, 9:08pm UTC](https://itensor.discourse.group/t/vumps-for-multi-site-unit-cells/460/4 "2022-10-20T21:08:13Z")

</div>

That is probably for a single-site unit cell. If I remember correctly, the package internally will take the definition for a single site unit cell and repeat it if you use a multisite unit cell, so you don’t have to make a new definition for all unit cell lengths. Of course the unit cell that you choose should be commensurate with the “primitive” unit cell defined implicitly by the function `unit_cell_terms`.

---

<div class="post-metadata">

**Author:** ![Meng-Zeng](https://yyz2.discourse-cdn.com/free1/user_avatar/itensor.discourse.group/meng-zeng/32/83_2.png) [@Meng-Zeng](https://itensor.discourse.group/u/Meng-Zeng)\
**Post date:** [October 26, 2022, 10:15pm UTC](https://itensor.discourse.group/t/vumps-for-multi-site-unit-cells/460/5 "2022-10-26T22:15:36Z")

</div>

Hi Matt, I tried out different ways of defining the interactions. It seems that including all the O\_1O\_2O\_3,O\_2O\_3O\_4,O\_3O\_4O\_5,O\_4O\_5O\_6 would give me the error “MethodError: no method matching translatecell(::ITensorInfiniteMPS.var”#\_shift\_cell#149"{Int64}, ::Scaled{ComplexF64, Prod{Op}}, ::Int64)  
". If I only include O\_1O\_2O\_3, then the code runs fine. More specifically, I tried with the three-site density-density interaction in the Hubbard model:

```julia
opsum += "Ntot", 1, "Ntot", 2, "Ntot", 3

```

---

<div class="post-metadata">

**Author:** ![andrewkhardy](https://yyz2.discourse-cdn.com/free1/user_avatar/itensor.discourse.group/andrewkhardy/32/439_2.png) [@andrewkhardy](https://itensor.discourse.group/u/andrewkhardy)\
**Post date:** [January 18, 2024, 9:45pm UTC](https://itensor.discourse.group/t/vumps-for-multi-site-unit-cells/460/6 "2024-01-18T21:45:33Z")

</div>

Hi Matt,

I realize your attention is probably focused on the new TensorNetworks.jl, but could you point to where this repetition is occurring? I’ve been having the exact same question about whether or not to include inter-cell terms.

---

<div class="post-metadata">

**Author:** ![mtfishman](https://yyz2.discourse-cdn.com/free1/user_avatar/itensor.discourse.group/mtfishman/32/11_2.png) [@mtfishman](https://itensor.discourse.group/u/mtfishman)\
**Post date:** [January 19, 2024, 3:37pm UTC](https://itensor.discourse.group/t/vumps-for-multi-site-unit-cells/460/7 "2024-01-19T15:37:53Z")

</div>

The function being used internally is `ITensorInfiniteMPS.opsum_infinite`, for example:

```julia
using ITensors
using ITensorInfiniteMPS

ITensorInfiniteMPS.opsum_infinite(Model("heisenberg"), 3)

```

outputs:

```julia
sum(
  0.5 S+(1,) S-(2,)
  0.5 S-(1,) S+(2,)
  1.0 Sz(1,) Sz(2,)
  0.5 S+(2,) S-(3,)
  0.5 S-(2,) S+(3,)
  1.0 Sz(2,) Sz(3,)
  0.5 S+(3,) S-(4,)
  0.5 S-(3,) S+(4,)
  1.0 Sz(3,) Sz(4,)
)

```

That’s being used here: [ITensorInfiniteMPS.jl/src/models/models.jl at 27fd437b38acc5331900d4e857a054adf5a6d864 · ITensor/ITensorInfiniteMPS.jl · GitHub](https://github.com/ITensor/ITensorInfiniteMPS.jl/blob/27fd437b38acc5331900d4e857a054adf5a6d864/src/models/models.jl#L24-L26)

I’ve lost track of this issue, if someone could post a minimal runnable example of something that isn’t working, I may be able to investigate it or point someone towards how it might be fixed.

---

<div class="post-metadata">

**Author:** ![mtfishman](https://yyz2.discourse-cdn.com/free1/user_avatar/itensor.discourse.group/mtfishman/32/11_2.png) [@mtfishman](https://itensor.discourse.group/u/mtfishman)\
**Post date:** [January 19, 2024, 3:40pm UTC](https://itensor.discourse.group/t/vumps-for-multi-site-unit-cells/460/8 "2024-01-19T15:40:09Z")

</div>

In terms of needing to include inter-cell terms, you should include inter-cell terms crossing one boundary of the minimal unit cell of your model, and you can see that `ITensorInfiniteMPS.opsum_infinite` will then repeat that minimal unit cell for whatever number of sites you specify when you go to build the infinite MPO.

---

<div class="post-metadata">

**Author:** ![andrewkhardy](https://yyz2.discourse-cdn.com/free1/user_avatar/itensor.discourse.group/andrewkhardy/32/439_2.png) [@andrewkhardy](https://itensor.discourse.group/u/andrewkhardy)\
**Post date:** [February 6, 2024, 3:57pm UTC](https://itensor.discourse.group/t/vumps-for-multi-site-unit-cells/460/9 "2024-02-06T15:57:12Z")

</div>

@mtfishman Apologies for the delayed response, I didn’t see a notification. The issue was that the example had `N=2` so it was unclear the boundary was included. The `call_length` in the link you provided explains how the repetition works. Thanks!
