Error when using infsiteinds(...) with custom Hilbert space (ITensorInfiniteMPS)

Hi,

I am trying to initialize a (product state) infinite MPS with a custom Hilbert space called “twospinsite” (defined at the very end). The relevant code block is:

#imports
include("twospinsite.jl")

N = 2 # Unit cell size

initstate(n) = isodd(n) ? "full" : "empty" #Creates a period-2 pattern of full/empty states
s = infsiteinds("twospinsite", N; initstate, conserve_qns)

ψ = InfMPS(s, initstate)

The last line causes an error: **ERROR:** LoadError: ArgumentError: Overload of "val" function not found for Index tags "Site,c=1,n=1,twospinsite". It is further worth noting that the output of println(s) is as follows:

 1: QN("charge",1) => 1
 2: QN("charge",0) => 2
 3: QN("charge",-1) => 1, (dim=4|id=39|"Site,c=1,n=2,twospinsite") <Out>
 1: QN("charge",1) => 1
 2: QN("charge",0) => 2
 3: QN("charge",-1) => 1]

and accordingly I suspect that the index tag putting the name ‘twospinsite’ at the end (instead of before ‘Site’) is the root of the problem. Unfortunately I’m not sure how to rectify that, and digging through the infsiteinds function did not make it clearer. It is worth noting that I am able to generate a finite MPS with this custom site type using the code

Nfinite = 55
sfinite = siteinds("twospinsite", Nfinite; conserve_qns)
ψfinite = random_mps(sfinite, initstate; linkdims=10)

and use it to start a successful finite DMRG run.

It is possible that I’ve misunderstood how to overload the val() functions, but I do suspect that the issue may be rectified by ensuring that the Index tag is generated as “twospinsite,Site,c=?,n=?” instead of the output I’ve obtained.


Here is where I define my custom Hilbert space. (Note that my conserved operator is called “charge” and is diagonal(1,0,0,-1).)

function ITensors.space(::SiteType"twospinsite";
                        conserve_qns=false)
  if conserve_qns
    return [QN("charge",1)=>1,QN("charge",0)=>2,
            QN("charge",-1)=>1]
  end
  return 4
  
end

ITensors.state(::StateName"full", ::SiteType"twospinsite") = [1.0, 0, 0, 0]
ITensors.state(::StateName"dfill", ::SiteType"twospinsite") = [0.0, 1, 0, 0]
ITensors.state(::StateName"cfill", ::SiteType"twospinsite") = [0.0, 0, 1, 0]
ITensors.state(::StateName"empty", ::SiteType"twospinsite") = [0.0, 0, 0, 1]

val(::ValName"full", ::SiteType"twospinsite") = 1
val(::ValName"dfill", ::SiteType"twospinsite") = 2
val(::ValName"cfill", ::SiteType"twospinsite") = 3
val(::ValName"empty", ::SiteType"twospinsite") = 4

#Operator Definitions...

Your code got cut off (and conserve_qns is not defined), but I suspect the solution is to do ITensors.val(..., which seems to make things work for me

Sorry, I’ve edited the original post to show the full code, not including that change val–>ITensors.val which indeed made that particular Error go away. Thank you so much for the fix!

1 Like

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