# Error in excited states code

Hello,

I am starting to use iTensor and I am trying to run the following example (as is):

http://itensor.org/docs.cgi?page=formulas/excited_dmrg

But I get the following errors when compiling

dmrg.cc: In function ‘int main()’:
dmrg.cc:41:12: error: ‘class itensor::Sweeps’ has no member named ‘maxdim’
sweeps.maxdim() = 10,20,100,100,200;
^
dmrg.cc:51:10: error: expected unqualified-id before ‘[’ token
auto [en0,psi0] = dmrg(H,randomMPS(sites),sweeps,{"Quiet=",true});
^
dmrg.cc:51:69: error: expected primary-expression before ‘)’ token
auto [en0,psi0] = dmrg(H,randomMPS(sites),sweeps,{"Quiet=",true});
^
dmrg.cc:61:17: error: ‘psi0’ was not declared in this scope
wfs.at(0) = psi0;
^
dmrg.cc:67:10: error: expected unqualified-id before ‘[’ token
auto [en1,psi1] = dmrg(H,wfs,randomMPS(sites),sweeps,{"Quiet=",true,"Weight=",20.0});
^
dmrg.cc:67:88: error: expected primary-expression before ‘)’ token
auto [en1,psi1] = dmrg(H,wfs,randomMPS(sites),sweeps,{"Quiet=",true,"Weight=",20.0});
^
dmrg.cc:72:46: error: ‘en0’ was not declared in this scope
printfln("\nGround State Energy = %.10f",en0);
^
dmrg.cc:73:47: error: ‘en1’ was not declared in this scope
printfln("\nExcited State Energy = %.10f",en1);
^
dmrg.cc:87:56: error: ‘psi1’ was not declared in this scope
printfln("\nOverlap <psi0|psi1> = %.2E",inner(psi0,psi1));
^
dmrg.cc:87:60: error: ‘inner’ was not declared in this scope
printfln("\nOverlap <psi0|psi1> = %.2E",inner(psi0,psi1));

The sample codes provided with the source material seem to work well, though.

Best regards,

Rafael

Hi Rafael,
This is a compilation issue, as you probably know, so it could be due to a few things. To begin with:
2. what Makefile are you using to compile? Or what compilation flags / instructions?

Best regards,
Miles

commented by (270 points)
Hi Miles,

2. I am using the same Makefile given in the sample folder, changing only

build: dmrg iqdmrg dmrg_table dmrgj1j2 exthubbard idmrg mag excited_states

debug: dmrg-g iqdmrg-g dmrg_table-g dmrgj1j2-g exthubbard-g idmrg-g mag-g excited_states-g

excited_states: excited_states.o $(ITENSOR_LIBS)$(TENSOR_HEADERS)
$(CCCOM)$(CCFLAGS) excited_states.o -o excited_states $(LIBFLAGS) excited_states-g: mkdebugdir .debug_objs/excited_states.o$(ITENSOR_GLIBS) $(TENSOR_HEADERS)$(CCCOM) $(CCGFLAGS) .debug_objs/excited_states.o -o excited_states-g$(LIBGFLAGS)

to account for the excited_states.cc code I am running.

However, I just tried to run it again and it seems to work now for some reason. I don't think I changed anything in the meantime. Anyway, let me know if anything is wrong with the procedure above.

On another note, when compiling I get a few warning messages of the kind

warning: ignoring return value of ‘int system(const char*)’, declared with attribute warn_unused_result [-Wunused-result]

Is this expected or there is something I should do to avoid it?

Best wishes,

Rafael
commented by (46.8k points)
Hi Rafael,
One thing I would recommend is not using the Makefile in the sample folder, which is rather complicated, but instead using the Makefile in the tutorial/project_template folder, which is intended as a sample code you can use to start building a project. We should publicize this folder even better on the website.

Warnings are pretty common when compiling C++ and should not be a concern, especially for warnings such as an ignored return value. That one is especially annoying, because if you do 'catch' the return value but then don't use it, you get a new warning about "unused variable". So I would recommend just adding -Wno-unused-result to your compliler flags to turn that one off (because I think an unused variable is actually a more useful warning than an unused return value).

Best,
Miles
commented by (270 points)
Hi Miles,

Thanks for the reply. That helps a lot!

Best wishes,

Rafael

Hello Miles,

I have the same issue when running the code in https://www.itensor.org/docs.cgi?vers=cppv3&page=formulas/excited_dmrg

The error : From line 1604, file itensor.cc

div(ITensor) not defined for non QN conserving ITensor

div(ITensor) not defined for non QN conserving ITensor
make: *** [Makefile:33: build] Aborted

I use itensor v3 and run 'make' in the folder '..\itensor\My_programs'

The error occur when I add line auto [en1,psi1] = dmrg(H,wfs,randomMPS(sites),sweeps,{"Quiet=",true,"Weight=",20.0});