[ITensorNetworks] Callable Hamiltonian parameters

Hi,

I am using ITensorNetworks to define Hamiltonians

I am trying to understand why we need to make parameters for the Hamiltonians callable and hence depend on the graph. I want to define three-body terms (actual node, nearest neighbor node, and next nearest neighbor), should I make the parameters depend also on these (below)?

function haldane(g::AbstractGraph; J=1, h₁=0, h₂=0)
    (; J, h₁, h₂) = map(to_callable, (;J, h₁, h₂))
    ℋ = OpSum()
    for e in edges(g)
      for nextnn in next_nearest_neighbors(g, dst(e))
        ℋ -= J(e,nextnn) , "Sz", src(e), "Sx", dst(e),  "Sx", nextnn
      end
      #Other terms go here
    end
  return ℋ
  end

What would be the implications of skipping the callable part as shown below?

function haldane(g::AbstractGraph; J=1, h₁=0, h₂=0)
    ℋ = OpSum()
    for e in edges(g)
      for nextnn in next_nearest_neighbors(g, dst(e))
        ℋ -= J , "Sz", src(e), "Sx", dst(e),  "Sx", nextnn
      end
      #Other terms go here
    end
  return ℋ
  end

The design of that code in ITensorNetworks.jl allows users to either pass numbers which are interpreted as uniform fields/couplings that are independent of the sites and bonds, or pass them as functions of the vertices/edges if they are non-uniform (say if the system is disordered, in which case the fields and/or couplings would be generated from a random distribution, or there are staggered fields that alternate between sites, or “pinning” fields at the edges of the system, or certain boundary conditions like open boundaries or twisted boundary conditions, …).

It’s up to you to decide how you want to design your own Hamiltonian constructor, if you are only going to have uniform couplings/fields you can write it the simpler way just in terms of numbers and not involve callables at all.

Thank you for such a quick response!