+1 vote
asked by (250 points)

I am using the sample code provided in ITensor for calculating excited states using DMRG. I am using Hubbard model, but the ConserveQN has been set to "true". I get the following error:

randomMPS(SiteSet) with QN conservation is ambiguous, use randomMPS(InitState) instead.

I have the following code:

#include "itensor/all.h"
#include "itensor/util/print_macro.h"

using namespace itensor;

int main(int argc, char* argv[])
{
 //Parse the input file
if(argc != 2) { printfln("Usage: %s inputfile_exthubbard",argv[0]); return 0; }
auto input = InputGroup(argv[1],"input");

auto N = input.getInt("N");
auto Npart = input.getInt("Npart",N); //number of particles, default is N (half filling)

auto nsweeps = input.getInt("nsweeps");
auto t1 = input.getReal("t1",1);
auto t2 = input.getReal("t2",0);
auto U = input.getReal("U",0);
auto V1 = input.getReal("V1",0);
auto quiet = input.getYesNo("quiet",false);

auto table = InputGroup(input,"sweeps");
auto sweeps = Sweeps(nsweeps,table);
println(sweeps);

//
// Initialize the site degrees of freedom.
//
auto sites = Electron(N,{"ConserveQNs=",true});

//
// Create the Hamiltonian using AutoMPO
//
auto ampo = AutoMPO(sites);
for(int i = 1; i <= N; ++i) 
    {
    ampo += U,"Nupdn",i;
    }
for(int b = 1; b < N; ++b)
    {
    ampo += -t1,"Cdagup",b,"Cup",b+1;
    ampo += -t1,"Cdagup",b+1,"Cup",b;
    ampo += -t1,"Cdagdn",b,"Cdn",b+1;
    ampo += -t1,"Cdagdn",b+1,"Cdn",b;
    ampo += V1,"Ntot",b,"Ntot",b+1;
    }

for(int b = 1; b < N-1; ++b)
    {
    ampo += -t2,"Cdagup",b,"Cup",b+2;
    ampo += -t2,"Cdagup",b+2,"Cup",b;
    ampo += -t2,"Cdagdn",b,"Cdn",b+2;
    ampo += -t2,"Cdagdn",b+2,"Cdn",b;
    }
auto H = toMPO(ampo);
//
// Begin the DMRG calculation
//
    auto [en0,psi0] = dmrg(H,randomMPS(sites),sweeps,{"Quiet=",true});

    println("\n----------------------\n");

    //
    // Make a vector of previous wavefunctions;
    // code will penalize future wavefunctions
    // for having any overlap with these
    //
    auto wfs = std::vector<MPS>(1);
    wfs.at(0) = psi0;
    //
    // Here the Weight option sets the energy penalty for
    // psi1 having any overlap with psi0
    //
    auto [en1,psi1] = dmrg(H,wfs,randomMPS(sites),sweeps,{"Quiet=",true,"Weight=",20.0});

    //
    // Print the final energies reported by DMRG
    //
    printfln("\nGround State Energy = %.10f",en0);
    printfln("\nExcited State Energy = %.10f",en1);


return 0;
}

I have gone through the answers to all the previous questions in Itensor Support regarding this issue, and seems like doing "git pull" is solving the issue. In stead of doing that, I installed the latest version of ITensor again, but I get the same error.

Is "git pull" the necessary way to solve this? Or is there something else wrong with the code?

1 Answer

0 votes
answered by (70.1k points)

Hi, thanks for the question.

So this is not a bug in ITensor, but just a message telling you about incorrect usage of the code for the case you are doing. Therefore a git pull would not fix the problem; rather you need to use the code differently for your case.

The error message is saying that for the case of a quantum number (QN) conserving calculation, such as the one you are doing, it is not enough to initialize an MPS by just giving the site indices. Additionally, you have to provide a specific product state that you want the MPS to be initialized to, which has a well-defined total QN.

Here are some example codes where QN conservation is used, and you will see that the MPS is always initialized with an InitState object passed to the MPS constructor (psi = MPS(state);).

https://github.com/ITensor/ITensor/blob/v3/sample/exthubbard.cc
http://itensor.org/docs.cgi?vers=cppv3&page=formulas/ladder

Please let me know if that doens't answer your question or if you have more questions -

Miles

commented by (250 points)
Thank you very much, this works now perfectly!
 Apologizing for late reply as there was no email notification this time. I will post if I have some more issues.
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.

Categories

...