# IDMRG for 1-D spin chain

**URL:** <https://itensor.discourse.group/t/idmrg-for-1-d-spin-chain/2599>\
**Category:** ITensor Julia Questions\
**Tags:** julia, dmrg\
**Created:** [March 24, 2026, 11:43pm UTC](https://itensor.discourse.group/t/idmrg-for-1-d-spin-chain/2599 "2026-03-24T23:43:29Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lee](https://avatars.discourse-cdn.com/v4/letter/l/bc8723/32.png) [@Lee](https://itensor.discourse.group/u/Lee)\
**Post date:** [March 24, 2026, 11:43pm UTC](https://itensor.discourse.group/t/idmrg-for-1-d-spin-chain/2599/1 "2026-03-24T23:43:29Z")

</div>

**Hello,**  
**I am not very familiar with directly implementing the iDMRG method. Just for the simplest Heisenberg chain,** H = J \sum\_i \vec{S}\_i \cdot \vec{S}\_{i+1} **,would it be possible for you to provide a sample Julia script for iDMRG?**  
**Thank you very much.**

---

<div class="post-metadata">

**Author:** ![Lee](https://avatars.discourse-cdn.com/v4/letter/l/bc8723/32.png) [@Lee](https://itensor.discourse.group/u/Lee)\
**Post date:** [March 26, 2026, 12:00am UTC](https://itensor.discourse.group/t/idmrg-for-1-d-spin-chain/2599/2 "2026-03-26T00:00:09Z")

</div>

**Or I’d like to ask: what exactly is wrong with this iDMRG code I tried to write?**

**using ITensors  
using ITensorMPS  
using ITensorInfiniteMPS  
function main()  
initstate(n) = isodd(n) ? “Up” : “Dn”  
s = infsiteinds(“S=1/2”, 2; initstate=initstate, conserve\_qns=false)  
ampo = OpSum()  
for j in 1:2  
ampo += 0.5, “S+”, j, “S-”, j + 1  
ampo += 0.5, “S-”, j, “S+”, j + 1  
ampo += 1.0, “Sz”, j, “Sz”, j + 1  
end  
H = MPO(ampo, s)  
psi0 = InfMPS(s, [“Up”, “Dn”])  
nsweeps = 20  
maxdim = [10, 20, 50, 100, 200, 400]  
cutoff = 1e-10  
energy, psi = idmrg(H, psi0; nsweeps=nsweeps, maxdim=maxdim, cutoff=cutoff)  
println(“energy = $energy”)  
end  
if abspath(PROGRAM\_FILE) == @FILE  
main()  
println(“Done”)  
end**

---

<div class="post-metadata">

**Author:** ![corbett5](https://yyz2.discourse-cdn.com/free1/user_avatar/itensor.discourse.group/corbett5/32/886_2.png) [@corbett5](https://itensor.discourse.group/u/corbett5)\
**Post date:** [March 26, 2026, 5:38pm UTC](https://itensor.discourse.group/t/idmrg-for-1-d-spin-chain/2599/3 "2026-03-26T17:38:17Z")

</div>

I am not familiar with `ITensorInfiniteMPS` or MPS algorithms which work in the thermodynamic limit more generally. However, my intuition is that you should modify the Heisenberg example found here: [https://github.com/ITensor/ITensorInfiniteMPS.jl/blob/main/examples/vumps/vumps\_heisenberg.jl](https://github.com/ITensor/ITensorInfiniteMPS.jl/blob/main/examples/vumps/vumps_heisenberg.jl)

There are a number of differences between that example and your code, most prominently there does not appear to be an implementation of infinite-DMRG in `ITensorInfiniteMPS`, but if VUMPS is acceptable then you’re in luck. See this thread for a discussion: [https://itensor.discourse.group/t/implementing-idrmg/168](https://itensor.discourse.group/t/implementing-idrmg/168)

---

<div class="post-metadata">

**Author:** ![Lee](https://avatars.discourse-cdn.com/v4/letter/l/bc8723/32.png) [@Lee](https://itensor.discourse.group/u/Lee)\
**Post date:** [March 31, 2026, 12:27am UTC](https://itensor.discourse.group/t/idmrg-for-1-d-spin-chain/2599/4 "2026-03-31T00:27:47Z")

</div>

**Thank you for the helpful pointers. This solved my problem.**

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/free1/uploads/itensor/original/1X/d3072b13e047cd06df7f3981547c0917d940dfa4.png) [@system](https://itensor.discourse.group/u/system)\
**Post date:** [April 10, 2026, 12:28am UTC](https://itensor.discourse.group/t/idmrg-for-1-d-spin-chain/2599/5 "2026-04-10T00:28:05Z")

</div>

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.
