How to set the magnetic field in Fermi Hubbard model

Dear all,

I am trying to calculate excited states of spinful fermi hubbard model by using DMRG. I need to add magnetic field \sum{}h_{i}(n_{i,\uparrow} - n_{i,\downarrow})/2. The values of magnetic field should be random at each site. Any idea how to implement this?

Thank you for your time.

Our OpSum system allows you to add terms such as h n_{i \uparrow} by doing:

os = OpSum()
...
os .+= h,"Nup",i

You can put this kind of summation into a for loop over i to sum over different sites. Then if you want the h values to be random, I would suggest making the random values inside an array named h then accessing them as h[i].

For example of making an OpSum for the Hamiltonian of the Hubbard model, you can see this code example:
ITensors.jl/examples/dmrg/1d_hubbard_extended.jl at main · ITensor/ITensors.jl · GitHub>
Note the part where the onsite interaction U is added:

 for i in 1:N
    os += U, "Nupdn", i
  end

You can write a similar part to add fields.

Thank you for your reply! It was useful.
Is it possible to do this with AutoMPO() ? For example:

ampo = AutoMPO()
...
    for i = 1:N
        ampo .+= h, "Nup", i
    end
    for i = 1:N
        ampo .+= -h, "Ndn", i
    end

Is this a same with which was written above? But I am afraid it does not work. How to add term -Ndn?
For some reason I can not use OpSum(). Getting following error:
UndefVarError: OpSum not defined in Main. What can be reason for this error?

Yes, so OpSum is the new name for AutoMPO. We have updated all of the code examples and documentation to use OpSum but I suppose there are still examples on the forum using the older name.

I’m not sure the reason for that error, unfortunately. Are you putting using ITensors in your code? That should bring OpSum into your set of imported type names. If the error persists, could you show a minimal example to reproduce that error?