ITensor / ITensors.jl

A Julia library for efficient tensor computations and tensor network calculations
https://itensor.org
Apache License 2.0
521 stars 121 forks source link

[ITensors] [BUG] Itensors refuses "weight" argument to DMRG #1521

Open marcio053 opened 1 month ago

marcio053 commented 1 month ago

Below I'm leaving a snippet of my code that gives an error when placing the "weight" argument in the DMRG. This code works in previous versions of Itensors, but in recent versions it does not work

H=Set_Hamiltonian(sites,N,t,t1,U,e,J,K,Gamma,t0,J1,mu,dashedon)
    ############  preparing DMRM ###########
    state=InitialState(M,"Neel")
    #psi0 = productMPS(sites,state)
    psi0 = randomMPS(sites,state,linkdims = 20)

    sweeps = Sweeps(Nsweeps)

    #maxdim!(sweeps,10,20,100,200,200,200,300)
    maxdim!(sweeps,50,100,100,300)
    mindim!(sweeps,50)
    noise!(sweeps,1E-4,1E-6,1E-8,1E-8,1E-9)
    cutoff!(sweeps,1E-8)
    println("Starting DMRG")

    weight=20.0
    etol=1E-8
    obs = DemoObserver(etol)

    ############ TDVP ############    
    H1=Set_Hamiltonian(sites,N,1,1,1,1,1,1,1,1,1,0.1,true)
    maxdim=20
    println("Starting TDVP")
    tdvp!(psi0,H,0.01,0.02,maxdim=maxdim)
    println("End.")
    #########################
    #energy,psi = dmrg(H,psi0,sweeps,outputlevel=1; observer=obs, weight)

    energy,psi = dmrg(H,psi0,sweeps,eigsolve_krylovdim=Sweep_Niter,ishermitian=true;outputlevel
                      =output_level, weight)
  ERROR: LoadError: MethodError: no method matching dmrg(::ProjMPO, ::MPS, ::Sweeps; eigsolve_krylovdim::Int64, ishermitian::Bool, outputlevel::Int64, weight::Float64)

Closest candidates are: dmrg(::Any, ::MPS, ::Sweeps; which_decomp, svd_alg, observer, outputlevel, write_when_maxdim_exceeds, write_path, eigsolve_tol, eigsolve_krylovdim, eigsolve_maxiter, eigsolve_verbosity, eigsolve_which_eigenvalue, ishermitian) got unsupported keyword argument "weight" @ ITensors ~/.julia/packages/ITensors/oOwvi/src/lib/ITensorMPS/src/dmrg.jl:158 dmrg(!Matched::MPO, ::MPS, ::Sweeps; kwargs...) @ ITensors ~/.julia/packages/ITensors/oOwvi/src/lib/ITensorMPS/src/dmrg.jl:21 dmrg(!Matched::Vector{MPO}, ::MPS, ::Sweeps; kwargs...) @ ITensors ~/.julia/packages/ITensors/oOwvi/src/lib/ITensorMPS/src/dmrg.jl:31

emstoudenmire commented 1 month ago

Thanks. Could you please post a minimal example that reproduces the bug? The example above includes some functions like Set_Hamiltonian and things which I don't have so I'm not able to run it.

Also, it may or may not be unrelated to the bug, but it could help to make your code in a more up-to-date style, following the code example here: https://itensor.github.io/ITensors.jl/dev/examples/DMRG.html#Compute-excited-states-with-DMRG Specifically note how it's preferred to no longer use the Sweeps type and instead just pass parameters like nsweeps, maxdim, etc as keyword arguments.

mtfishman commented 1 month ago

Also, the preferred style is using MPS instead of productMPS and random_mps instead of randomMPS, though that's unrelated to your issue.