Fermionic operators

Hi,

I am just starting out with ITensor. I was looking to write a code with some multiple site fermionic operators and wrote this for starters:

using ITensors

N_c=1 #number of unit cells

N=2*N_c

sites = siteinds("Fermion",N)

state0=["0","0"]

psi0 = productMPS(sites,state0)

state1=["1","1"]

psi1 = productMPS(sites,state1)

ampo = OpSum()

ampo+= ("A",1,"F",1,"A",2)

ampo+= ("A",1,"F",1,"A",2)

H= MPO(sites, ampo)

print(inner(psi0, H, psi1))

But this code is giving errors related to the line with MPO. Am I missing something?

Sorry, if this has already been answered elsewhere. I could not figure out where this was wrong.

Glad you are checking out ITensor. Could you please paste below what error message you got from Julia, including the full stack trace?

ERROR: LoadError: MethodError: Cannot convert an object of type Type{Float64} to an object of type Vector{ITensor}

Closest candidates are:

convert(::Type{T}, ::LinearAlgebra.Factorization) where T<:AbstractArray at /Applications/Julia-1.8.app/Contents/Resources/julia/share/julia/stdlib/v1.8/LinearAlgebra/src/factorization.jl:58

convert(::Type{T}, ::Strided.AbstractStridedView) where T<:Array at ~/.julia/packages/Strided/pDrSx/src/abstractstridedview.jl:31

convert(::Type{Array{T, N}}, ::StaticArraysCore.SizedArray{S, T, N, N, Array{T, N}}) where {S, T, N} at ~/.julia/packages/StaticArrays/4uslg/src/SizedArray.jl:88

Stacktrace:

[1] MPO(data::Type, llim::Vector{Index{Int64}}, rlim::Sum{Scaled{ComplexF64, Prod{Op}}})

@ ITensors ~/.julia/packages/ITensors/nablm/src/mps/mpo.jl:9

[2] MPO(sites::Vector{Index{Int64}}, ops::Sum{Scaled{ComplexF64, Prod{Op}}})

@ ITensors ~/.julia/packages/ITensors/nablm/src/mps/mpo.jl:93

[3] top-level scope

@ ~/Documents/states_in_occ_number_basis.jl:25

Also, thank you for the quick response!

It’s working now. I went through some other FAQs and understand how to do it now.

using ITensors


N_c=1 #number of unit cells


N=2*N_c


sites = siteinds("Fermion", N);


state0=["0","0"];


psi0 = productMPS(sites,state0);


state1=["1","1"];


psi1 = productMPS(sites,state1);


ampo = AutoMPO();


#ampo += (1, "c†", 1, "c†", 2);


ampo += (1, "c", 1, "c", 2);


H= MPO( ampo, sites);


psi1=Apply(H,psi1);


print(inner(psi0,psi1))

Thank you!

Good to know. What did you do differently that fixed the issue for you?

The other issue with the code above that was causing the error message is that you should call the MPO constructor as:

H = MPO(ampo,sites)

so with the arguments in the other order.

A possible “action item” for the ITensor team here would be to provide a clearer error message, hopefully. The original error message above is very unclear unfortunately!

Thank you!

Yes, that was one error. Also, I am using c’s and c^{\dagger}'s instead of the earlier version. Using “A” and “F” was giving me some error.
I have a few more questions:

Also, I have another code now that looks like this for creating two states with occupation numbers on multiple sites:

sites = siteinds("Fermion", num_of_occupation_numbers);

and then

  for i in 1:number_of_basis_states

    for j in 1:i

        #state0=Array{Char,1}(num_of_occupation_numbers);

        num1=i
        num2=j

        for l in 1:num_of_occupation_numbers
            
            if num1%2==0
                state1[l]="0"

            else
                state1[l]="1"

            end
            
            num1=num1÷(2)


        end

        for l in 1:num_of_occupation_numbers
            
            if num2%2==0
                state2[l]="0"

            else
                state2[l]="1"

            end
            
            num2=num2÷(2)


        end

        psi1 = productMPS(sites,state1);

        psi2 = productMPS(sites,state2);

        
        


        psi2=Apply(op1_mpo,psi2);

        

        #print(inner(psi1,psi2));

        sigma_1_z_matrix[i,j]=(inner(psi1, psi2))*im;

        sigma_1_z_matrix[j,i]=-(conj(inner(psi1, psi2)))*im;

        #show("done")

    end

end

I am now getting the eigenvalues and eigenvectors of sigma_1_z_matrix. Is there a way I can just define the operator corresponding to this matrix and get its eigenvalues and eigenvectors in the occupation number basis?
Similarly, once I get the eigenvectors, can I form linear combinations of states as shown here

Physics (SiteType) System Examples · ITensors.jl

of these multiple site states?

I want to compute inner products involving these linear combinations.

But I am unable to use inner(psi1+psi2, psi3+psi4) like this for instance.

Does inner allow linear combinations to be formed? How would you suggest I use linear combinations of the basis states that I form using the occupation numbers (which can be 0 or 1) and use “apply” and “inner” on these linear combinations?

Thanks a lot for your help again.

Above you are asking many different questions. Could you please post the most important one or two of these questions as new posts to the forum? Then we will try to answer them for you, thanks!