If you copy the code from that file, then change the name of the class from TEvolObserver to something else (say CustomObserver) then you can make your custom observer:
auto obs = CustomObserver(...); // pass any constructor arguments you define
If you want to have access to the wavefunction inside the observer while the time evolution is happening, just pass a reference to your MPS to the constructor of your observer and save that reference as a data field in the class. Then the measure method of your observer will have access to the wavefunction that way and you can perform any measurements you want.
The named arguments (“args”) passed to the measure method by the gateTEvol function are:
“TimeStepNum” (int) - which step of the time evolution was just performed
“Time” (Real) - the time evolved so far
“TotalTime” (Real) - the final, total time requested for the evolution (always equals the value ttotal passed to gateTEvol)
Thank you very much!
Unfortunately, I don’t think I really understand it.
Do you mean I should fill observable operators in “CustomObserver(…)” like “op(sites,“N”,i)” or something else?
Or should I modify TEvolObser.h like " Making a Custom DMRG Observer ITensor"
and do measurements in the head file?
And if it is the second one, how could I get the MPS after every time-step
Is that by auto& psi = gateTEvol::psi
like auto& psi = DMRGObserver::psi()in" Making a Custom DMRG Observer"
Yes, I would say more of your second guess: if you follow the “Making a Custom DMRG Observer” code formula then you can use that CustomObserver type also in the gateTEvol function. The only difference is that the named arguments passed to the measure function are different for time evolution, and have the values I described above.
Also to get the wavefunction, just also do
auto& psi = DMRGObserver::psi()
if you make your CustomObserver to be a sub-class of the DMRGObserver type. If you don’t make it inherit from that type, then you’d have to pass the wavefunction a different way.
So it should be sufficient to include the header (.h) file where CustomObserver is defined into just the same code file where your main function is defined. You should not need to modify tevol.h or any ITensor library code.
If you are getting the error that CustomObserver was not declared, it most likely means that the compiler cannot see the code for CustomObserver or that you have not done using namespace itensor; at the beginning of your code. Is the location of the file correct? It looks like you’re saying #include/mps/CustomObserver.h but that’s not standard C++ notation for an include… Do you mean something like #include "path/to/CustomObserver.h" where path/to is the path on your system where the CustomObserver.h file is located?
Well, it is excatly my carelessness.
So, if I want to do measurements in the header file, how can I pass sites information to CustomObserver or TEvolObserver so that I can call op(sites,"N",i) in the file ?