Extracting matrix elements of exp(-dt*H_bond)

How do I use this algorithm? What does that parameter do?
Post Reply
gerd
Posts: 7
Joined: 15 Oct 2018, 23:23

Extracting matrix elements of exp(-dt*H_bond)

Post by gerd »

Say, I'd like to 'see' the matrix elements tenpy obtains for exp(-dt*H_bond), in order to compare them with a side-calculation of the same matrix elements without tenpy. What I did was

Code: Select all

parm = {'L':2, '...model parms....': ...., 'bc_MPS': 'infinite'}
w = MyMod(parm) # some model I have
psi = MPS.from_product_state(w.lat.mps_sites(), [...some local state...]*parm['L'],parm['bc_MPS'])

# don't care about parameters, except maybe (???) for 'oder' and 'delta_tau_list' (as a side remark, not related to this
post, I cannot find proper docu of 'delta_tau_list'.)
tebd_param = {'order': 1,'delta_tau_list': [1.],'max_error_E': 1.,'trunc_params': {'chi_max':10, 'sdv_min': 1.e-10}}

# set tebd machine and eval U for some crazy dt
eng = tebd.Engine(psi,w,tebd_param)
dt = 1.
eng.calc_U(1,dt,type_evo='imag')

# extract matrix elements of U
m=eng._U[0][0]._data[0]
My question is, if m on the last line is indeed exp(-dt*H_bond) and if not, from where / how I can get it.

Thx.
User avatar
Johannes
Site Admin
Posts: 413
Joined: 21 Jul 2018, 12:52
Location: TU Munich

Re: Extracting matrix elements of exp(-dt*H_bond)

Post by Johannes »

You can just directly read out the coefficients of an np_conserved Array A in the same way as for a numpy Array, for example A[0, 1] will give you a float, if A is a matrix with 2 indices. Even slices are supported, e.g. for A[:, 2] the result will be a np_conserved Array of dimension 1.
If you prefer to have the full array in numpy, you can convert a np_conserved Array with A.to_ndarray(). I would advice against accessing the Array._data directly. (The underscore in the beginning of the name indicates "private" functionality, which might change in any future version. This is python, so private is a pure convention and you can still access it, but it's not recommended...)

For finite boundary conditions, eng._U[0][0] is probably None, so you might want to look at eng._U[0][1], which lives on the bond between sites 0 and 1 (second index 1). For your paramter choice, it seems to be \(U[0][1] = \exp(-1. \cdot H_{0,1})\)
(Again, _U is "private", mostly because I didn't expect someone to look into it, and it's irrelevant to people who just want to run the code.
But it's great to see someone digging into the code *Thumbsup* ;) )

When you inspect the elements and turn on charge conservation in your model, you might not find what you expected:
Depending on the Site which you use, it might sort and bunch by charges, which induces a permutation of the local basis states.
This permutation should be saved in the Site.perm.
gerd
Posts: 7
Joined: 15 Oct 2018, 23:23

Re: Extracting matrix elements of exp(-dt*H_bond)

Post by gerd »

I'm sorry, my question was probably stated misleadingly. Let me try differently. Say, I have set up a 'model' - not within tenpy - but certainly with various operators which are meant to act on an mps, encoded within a given local basis. One of the operators I have at hand is exp(-dt*H_bond), where H_bond is exactly the Hamiltonian acting on a bond (as needed eg. for tebd). I think there should be no ambiguity in this operator? Right? Now I switch to tenpy and encode my model within the same local basis. For this exercise, I completely skip symmetries in both implementations, i.e. for tenpy I use leg = npc.LegCharge.from_trivial(d) as you suggested to me in a previous post.

My question is: is there a "magic" ;) command, I can use to get all matrix elements of the aforementioned exp(-dt*H_bond) from tenpy, and if so, what would it be?


(PS.: Regarding the 'dogmatics' of do/don't for class access, I'm more than aware that going for protected attributes like m=eng._U[0][0]._data[0] indicates a user totaly lost and not understanding how to use a library, rather than being a geeky pythonista. Anyway, for me it looked like the 'i' in m=eng._U[0][i]._data[0] was accessing the site, and also that for my parameter set the matrices on all 'i' where identical, which made sense. (Cmon guys Munich is sooo rich. Frank Pollmann can hire many people to help you on expanding the doc to tenpy ;) I can post 10 feature requests like that in this forum if it helps...))
User avatar
Johannes
Site Admin
Posts: 413
Joined: 21 Jul 2018, 12:52
Location: TU Munich

Re: Extracting matrix elements of exp(-dt*H_bond)

Post by Johannes »

Yes, I understood that, so probably I wasn't clear enough. Let me try again by writing code:

Code: Select all

U_bond = eng._U[0][i] # this is the np_conserved Array representing exp(-dt* H_bond) on bond (i-1, i)
U_bond[0, 0, 0, 0]  # the entry corresponding to spin up on each site
U_bond_np = U_bond.to_ndarray()  # converstion of the np_conserved Array to numpy - this is probably what you want?
print(U_bond_np)  # print it, or do what ever you want to do with it (e.g. compare with your own non-tenpy implementation)
Does that answer your question?

What I rally wanted to say is that you don't need to use the A._data, which will only give you some blocks of the full array...
gerd
Posts: 7
Joined: 15 Oct 2018, 23:23

Re: Extracting matrix elements of exp(-dt*H_bond)

Post by gerd »

Johannes wrote: 25 Oct 2018, 19:45Does that answer your question?
I'll get back if it doesn't.

While I'm at it, and since I side-mentioned it already in the original post, and since I hope there is no need to open a new thread on it:
1) I cannot find complete info on the parameter list 'delta_tau_list'. For me, the doc file https://tenpy.github.io/reference/tenpy ... .tebd.html contains only an unfinished sentence w.r.t. that.
(When I poke around in the code there seems to be a loop over its entries and maybe it is required for oder>1 trotter-suzuki? ...)

2) Is it valid usage of tenpy to do 'poor man's' tebd with only plain 1st-order trotter-suzuki (so that the error would be 2nd order. I'm not sure about a politically correct usage of the 'order' word.)? I did not find doc for that, and when stupidly experimenting with several attributes from the tebd engine, some of them complained that such 1st order would 'not be implemented''?
User avatar
Johannes
Site Admin
Posts: 413
Joined: 21 Jul 2018, 12:52
Location: TU Munich

Re: Extracting matrix elements of exp(-dt*H_bond)

Post by Johannes »

Sorry for not getting back directly...

1) The idea is to gradually decrease the time step to reach convergence as quickly as possible.
Thanks for pointing out the missing documentation, I've just updated it.

There's a subtle thing that even when using a second or fourth order Trotter decomposition in the ususal even-odd fashion, the error with imaginary time evolution is first order in dt. That's why it's important to gradually lower the time step to reach larger accuracy.
The update_imag tries to overcome this by using a different Trotter scheme (more like a sweep in DMRG), but this works only for finite systems and has an error growing with system size, so that's not much better.
The solution is just to use DMRG when looking for the ground state ;)

2) At least for real time evolution, you can definitively set order=1 and everything should work.
It's just that second order comes almost at the same computational cost as first order (at least if you don't measure after each time step), so that's why 2 is the default.
Fourth order requires significant more calculation per time step, but often allows to chose a larger dt such that less steps are required.
Whether this helps or not depends on the exact choice of parameters and model, but in large scale simulation I would recommend to at least check if it helps ;)
Post Reply