Page 1 of 1

Converting to state vector gives wrong energy

Posted: 15 Mar 2025, 20:52
by glazedonuts
Hi,

I am new to TenPy so need a bit of help. I am running DMRG on a TFIM and when I get the final energy it is -10.5. I also obtained the exact energy by exact diagonalization (since I have a small system size) and that is also very close to the DMRG energy. All good.

However, when I try to extract the state and then calculate the energy, I get a number that is very different (around +3.7). So I am confused whether I am extracting the state incorrectly. Basically, I want to extract (a) the final MPS from the DMRG calculations and (b) the final state resulting from this MPS.

Python: Select all

psi_mps_state = psi.get_theta(0, psi.L).to_ndarray()
print("PSI MPS Energy: ", (psi_mps_state.conj().reshape(1, -1) @ H_sp @ psi_mps_state.reshape(-1, 1)).real.item())

Thank you :)

Re: Converting to state vector gives wrong energy

Posted: 19 Mar 2025, 09:56
by Jakob
tenpy, with charge conservation has a basis order that might be surprising.
See e.g. the warning in Site

So I assume that you are writing down H_sp in an incompatible basis (probably you use {|up>, |down>}, and if you use charge conservation, tenpy will use {|down>, |up>}).

Have a look at

Python: Select all

model.lat.unit_cell[0].Sz.to_ndarray()
and check if it matches your convention for the basis.

Re: Converting to state vector gives wrong energy

Posted: 20 Mar 2025, 15:08
by Jakob
See https://github.com/tenpy/tenpy/pull/495 for functions that export tenpy objects (MPS or Hamitlonians from a model) to full matrix representations.