jcmgray / quimb

A python library for quantum information and many-body calculations including tensor networks.
http://quimb.readthedocs.io
Other
455 stars 107 forks source link

1D TEBD leaves out the last sweep #149

Closed snsunx closed 1 year ago

snsunx commented 1 year ago

What is your issue?

I was trying to run a simple 1D TEBD algorithm on an MPS with the following code (using Quimb v1.4.0):

import quimb as qu
import quimb.tensor as qtn

n_sites = 6
bond_dim = 3
t = 1.0

mps = qtn.MPS_rand_state(n_sites, bond_dim=bond_dim)
ham = qtn.LocalHam1D(n_sites, qu.pauli('x') & qu.pauli('x'))

tebd = qtn.TEBD(mps, ham)
tebd.update_to(t, dt=t, order=2)

Here I set dt to t so that it is a single-step TEBD, which consists of a right sweep with time t/2, a left sweep with time t, and a right sweep with time t/2. However, when I ran the code, the update_to function only ran the first right sweep and the left sweep, and stopped there without running the last right sweep. When I set dt to a fraction of t (more than just a single time step), the last sweep was also left out as was in the single-step case.

I understand that the last sweep is supposed to be queued and run together with the right sweep in the next time step. But at the end of the update_to function call, the last sweep should be run, which was not run in the code I tried.

jcmgray commented 1 year ago

Hey @snsunx, I can't reproduce this locally but would guess its something to do with these two conditions being out of step due to floating point error here: https://github.com/jcmgray/quimb/blob/6c312f64bae50303691a5527c752d21686b13edc/quimb/tensor/tensor_1d_tebd.py#L385-L396 I.e. the second line is not initially met but after one sweep the first is, this should be changed to be more robust.

jcmgray commented 1 year ago

This should be fixed by https://github.com/jcmgray/quimb/commit/dcd8cbc96bc6c3ce01f24dfc6ec6fe9e8e10586b, let me know if not..

snsunx commented 1 year ago

It works for me now. Thanks. I need some features from the released version v1.4.0, so I'll have to apply these changes locally. I'll close this issue.

jcmgray commented 1 year ago

It works for me now. Thanks. I need some features from the released version v1.4.0, so I'll have to apply these changes locally. I'll close this issue.

Glad to hear it. If there is some regression in functionality (as opposed to just api change) from 1.4 do open a separate issue/let me know.