How to define a new model in VUMPS?

Hi Matt,

I’m trying to define my own model in VUMPS by following heisenberg and vumps. In particular, I used the following in vumps code (I only changed the name from “heisenberg” to “mymodel” with everything else untouched)

function unit_cell_terms(::Model"mymodel")
  opsum = OpSum()
  opsum += 0.5, "S+", 1, "S-", 2
  opsum += 0.5, "S-", 1, "S+", 2
  opsum += "Sz", 1, "Sz", 2
  return opsum
end
model = Model("mymodel")		

However, I got “LoadError: MethodError: no method matching unit_cell_terms(::Model{:mymodel})”. I feel I misunderstood how this works, but I don’t know where the key issue is.

Thank you for your help.
-Meng

1 Like

I’m also trying to define a new model in VUMPS and ran into the same issue. Inserting the new unt_cell_terms function into ITensorInfiniteMPS solved it for me.

1 Like

Hi Vladimir,

Thanks for your response!
I actually did the same thing: (everything is copy-paste except that I changed the name “heisenberg” to “mymodel”)

using ITensors
using ITensorInfiniteMPS

include(
  joinpath(
    pkgdir(ITensorInfiniteMPS), "examples", "vumps", "src", "vumps_subspace_expansion.jl"
  ),
)

#########################################################################
# VUMPS parameters

maxdim = 10 # Maximum bond dimension
cutoff = 1e-8 # Singular value cutoff when increasing the bond dimension
max_vumps_iters = 100 # Maximum number of iterations of the VUMPS algorithm at each bond dimension
vumps_tol = 1e-5
conserve_qns = true
outer_iters = 6 # Number of times to increase the bond dimension

##############################################################################
# CODE BELOW HERE DOES NOT NEED TO BE MODIFIED

N = 2 # Number of sites in the unit cell
initstate(n) = isodd(n) ? "↑" : "↓"
s = infsiteinds("S=1/2", N; conserve_qns, initstate)
println("s ",s)
ψ = InfMPS(s, initstate)

#########################################################
function unit_cell_terms(::Model"mymodel")
  opsum = OpSum()
  opsum += 0.5, "S+", 1, "S-", 2
  opsum += 0.5, "S-", 1, "S+", 2
  opsum += "Sz", 1, "Sz", 2
  return opsum
end
#########################################################
model = Model("mymodel")													
H = InfiniteSum{MPO}(model, s)	

I’m wondering how you did it differently that made it work.
Thank you for your time.
-Meng

Hi Meng,

I meant I put unit_cell_terms directly into the ITensorInfiniteMPS.jl file; it seems like it has to be defined before ITensorInfiniteMPS is precompiled.

2 Likes

Hi Vladimir,

Following your hint, I added mymodel.jl in the same directory as the other models and added the line

include("models/mymodel.jl")

in the ITensorInfiniteMPS.jl file in my directory “.julia/packages/ITensorInfiniteMPS/Ogcvb/src/” and now it works!!!

Thank you so much for your help, I’ve been stuck on this for more than a week.

Best,
-Meng

1 Like

You shouldn’t need to add the file for your model to the package directly, instead you can overload the function unit_cell_terms as follows, which can be defined anywhere:

function ITensorInfiniteMPS.unit_cell_terms(::Model"mymodel")
  opsum = OpSum()
  opsum += 0.5, "S+", 1, "S-", 2
  opsum += 0.5, "S-", 1, "S+", 2
  opsum += "Sz", 1, "Sz", 2
  return opsum
end

or alternatively you can import the function with import ITensorInfiniteMPS: unit_cell_terms before defining your own overload. This extends the unit_cell_terms for your own Model type.

3 Likes

Thanks Matt, this is a much easier solution.

I’m not sure if it is implemented right now, but ideally a user could just pass the OpSum directly:

function mymodel_opsum()
  opsum = OpSum()
  opsum += 0.5, "S+", 1, "S-", 2
  opsum += 0.5, "S-", 1, "S+", 2
  opsum += "Sz", 1, "Sz", 2
  return opsum
end
H = InfiniteSum{MPO}(mymodel_opsum(), s)	

The Model type may be superfluous at this point since I made some simplifications to the InfiniteSum and related constructors.

If you have time please try that out, and if it doesn’t work it would be easy to add support for that.

1 Like

Hi Matt, I tried this and got the error message “LoadError: MethodError: reducing over an empty collection is not allowed; consider supplying init to the reducer”

Ok thanks, I’ll have to investigate that since it would be nice if that worked. Unfortunately I haven’t had much time to work on the VUMPS code recently.

2 Likes

Hi Matt,

I’m assuming the answer is that this has been delayed to the TensorNetworks.jl release, but I’m wondering if you’ve gotten a chance to take a look at this?

Is there a particular issue you are having? I believe everything should work if you define a model, the only thing that seems to not work is directly passing an OpSum which just has terms in a minimal unit cell that is smaller than the specified number of sites, but that shouldn’t block you from doing anything (it would just provide a slightly simpler interface).

@mtfishman I was just curious if this simplified interface will make its way to the new release with TensorNetworks.jl ?

ITensorNetworks.jl supports conversion of OpSum to finite tree tensor networks (TTN), which naturally includes finite MPS. We plan to support conversion of OpSum to infinite tensor networks like infinite MPS but that will require more work.

Hello,

I would also like to ask how can the energy density of a newly defined model be extracted; is it just the energy of the considered Cell over the number of sites making up said cell? Or is different?

I am asking as the Extended Hubbard example in the Github contains the line:

energy_exact = reference(model, Observable("energy"); U=model_params.U / model_params.t)

which I understand can only be used for the models defined in the repository - or I am misusing it.

Can you start a new post?