+1 vote
asked by (340 points)

Hello ITensors team,

I'm trying to construct an QN custom Hilbert space with spins 3/2 and higher. I follow the tutorial, which points about "overload" the function. I wrote an QN code for higher spins( as before mentioned) but i don't know exactly how to call the function. I try use Include using the external fine in the same folder, but i'm getting an error because the code didn't recognize the flag "S=3/2".

My external file example for S=3/2 :

using ITensors

function ITensors.space(::SiteType"S=3/2"; conserve_qns=false)

if conserve_qns
return [QN("Sz",3)=>1, QN("Sz",1)=>1,
return 4

function ITensors.op!(Op::ITensor,
Op[s'=>1,s=>1] = +3/2
Op[s'=>2,s=>2] = +1/2
Op[s'=>3,s=>3] = -1/2
Op[s'=>4,s=>4] = -3/2

function ITensors.op!(Op::ITensor,
Op[s'=>1,s=>2] = sqrt(3)
Op[s'=>2,s=>3] = 2
Op[s'=>3,s=>4] = sqrt(3)

function ITensors.op!(Op::ITensor,
Op[s'=>2,s=>1] = sqrt(3)
Op[s'=>3,s=>2] = 2
Op[s'=>4,s=>3] = sqrt(3)

Thank you !

2 Answers

0 votes
answered by (340 points)

Working in my example i see another kind of error. I'm using include("S=3/2.jl") in begining of my code and works well.

After defining an sitetype function, the call @show(site) returns an correct array of Index Types "S=1" and "S=3/2". Now i'm getting an error in definition of my initial wavefunction with QN conservation. My codes definition of sitetype and state folows :

    N = 64
    function sites_type(n::Int)
        if iseven(n) == true
            return "S=3/2"
        if iseven(n) == false
            return "S=1"

    sites = siteinds(n->sites_type(n), N; conserve_qns=true)
    J_1 = 1.0 #Same spin couplins
    J_2 = 1.0 # \alpha_c = J_2/J_1  \approx 0.7621
    ampo = AutoMPO()
    # s-s interactions with coupling J_1
    for j=1:4:N-4
        ampo += 0.5*J_1,"S+",j,"S-",j+2
        ampo += 0.5*J_1,"S-",j,"S+",j+2
        ampo += J_1,"Sz",j,"Sz",j+2

    # S-s interations with Coupling J_2
    for j=2:4:N-4
        ampo += 0.5*J_2,"S+",j,"S-",j+1
        ampo += 0.5*J_2,"S-",j,"S+",j+1
        ampo += J_2,"Sz",j,"Sz",j+1
    # S-S interations with coupling J_1
    for j=2:4:N-4
        ampo += 0.5*J_1,"S+",j,"S-",j+2
        ampo += 0.5*J_1,"S-",j,"S+",j+2
        ampo += J_1,"Sz",j,"Sz",j+2
    # S-s interations with coupling J_2
    for j=4:4:N-4
        ampo += 0.5*J_2,"S+",j,"S-",j+1
        ampo += 0.5*J_2,"S-",j,"S+",j+1
        ampo += J_2,"Sz",j,"Sz",j+1
    H = MPO(ampo,sites)
    #Definitions of Sz_tot =0 and Sz_tot=1 wave functions
    state0, state1 = [], []
    for n =1:N/4
        push!(state0, "Z0", "Up", "Z0", "Dn")
    push!(state1, "Up", "Up", "Z0", "Dn")
    for n =2:N/4
        push!(state1, "Z0", "Up", "Z0", "Dn")

    psi0 = productMPS(sites,state0)
    psi1 = productMPS(sites,state1)

I'm getting an Error in psi0 "ArgumentError : Overload of "state" function not found for Index tags "S=3/2,Site,n=2".

+1 vote
answered by (70.1k points)

Hi, glad you made some progress on this. The error you are getting about Overload of "state" function is related to the need to define functions called ITensors.state for your custom site type. We should add this to the code examples.

While overloading ITensors.state isn't required for some parts of ITensor, such as AutoMPO or the op function, it is necessary for the productMPS function.

What the state function does is tell ITensor how map strings like "Up" and "Dn" to index values such as 1 and 2 (for the case of a spin 1/2).

So what you need to do is define something like this:

ITensors.state(::SiteType"S=3/2",::StateName"Up") = 1
ITensors.state(::SiteType"S=3/2",::StateName"Dn") = 4

and similar for the 2 and 3 states which I'm not sure what names to give, but maybe you can come up with good names if you want to define those. But the above code should be sufficient for your example since it looks like you are only setting your S=3/2 sites to "Up" or "Dn" if I'm reading your code correctly.

For a more extensive example of how state is defined for the "S=1" site type, you can see the code for that inside of ITensors.jl here:

Best regards,

commented by (340 points)
Hello Miles,

it works beautifully, thank you ! Next time i'll spend some time reading the github Itensors.jl files before ask something.
commented by (70.1k points)
Glad it worked well for you! Not a problem, as we should document this aspect of the site system better. But agreed that the library code for the sites is worth checking out!
commented by (700 points)
Hi Miles,
I kinda had the same issue, but adding the following doesn't seem to help. (I got this from the "Electron" site type).  Instead, I got another error "@ValName_str not defined".
Also, I have been wondering what this val() function does, because the "S=1" site type doesn't have it. And for the state() function, the "Electron" site type used the following vectors, but the "S=1" site type used integer numbers. What's the difference between the two cases?

Thanks a lot for your time. - Mason

val(::ValName"Emp", ::SiteType"CFermion") = 1
val(::ValName"f3", ::SiteType"CFermion") = 2
val(::ValName"f4", ::SiteType"CFermion") = 3
val(::ValName"f3f4", ::SiteType"CFermion") = 4
state(::StateName"Emp", ::SiteType"CFermion") = [1.0,0,0,0]
state(::StateName"f3", ::SiteType"CFermion") = [0.0,1,0,0]
state(::StateName"f4", ::SiteType"CFermion") = [0.0,0,1,0]
state(::StateName"f3f4", ::SiteType"CFermion") = [0.0,0,0,1]
Welcome to ITensor Support Q&A, where you can ask questions and receive answers from other members of the community.

Formatting Tips:
  • To format code, indent by four spaces
  • To format inline LaTeX, surround it by @@ on both sides
  • To format LaTeX on its own line, surround it by $$ above and below
  • For LaTeX, it may be necessary to backslash-escape underscore characters to obtain proper formatting. So for example writing \sum\_i to represent a sum over i.
If you cannot register due to firewall issues (e.g. you cannot see the capcha box) please email Miles Stoudenmire to ask for an account.

To report ITensor bugs, please use the issue tracker.