Implementing 'new' models

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

Implementing 'new' models

Post by gerd »

q.png
q.png (239.64 KiB) Viewed 9420 times
User avatar
Johannes
Site Admin
Posts: 413
Joined: 21 Jul 2018, 12:52
Location: TU Munich

Re: Implementing 'new' models

Post by Johannes »

This is exactly the place where you're supposed to ask these questions ;-)

I know that the documentation of each function and class is a bit overwhelming in the beginning, and it's hard to get an overview.
Some more introductory notes are in the userguide section of the tenpy documentation, for you of importance is in particular the section Introduction to models. Have you found (and read) this introduction already?
When I wrote it, I was hoping that it would answer your question.

I totally agree that it would be great if we had some more "recipes" in the introduction, but I'm busy writing TeNPy functions and don't really have time left.
If anybody volunteers to write introductions, I would be totally happy to include them in the userguide.
Otherwise, this forum will hopefully contain some examples and explanations, as people like you keep asking and answering questions ;-)

Our new notes (iii) are partially based on the original (i), and the MPS exercises of our tutorials (ii) are based on the simple toycodes in the toycodes folder of the tenpy git repository. Note that these toycodes (and codes from (i),(ii)) are completely separate from the rest of TeNPy, they use just pure python/numpy functionalities, you don't even need to install TeNPy to run them.
TeNPy requires a different format in which the model/hamlitonian is represented; for (infinite) DMRG you need an MPO.

Maybe it's best if I give you time to read the intoduction to models (linked above) first. What you need to do is very similar to the XXZChain example at the bottom of the introduction. Define the necessary operators you need in the Site, and use them later with the "add_onsite" and "add_coupling" methods.
Your model should be derived from the "CouplingModel" and the "MPOModel", but not the "NearestNeigborModel".

If it is still unclear, ask again :)
gerd
Posts: 7
Joined: 15 Oct 2018, 23:23

Re: Implementing 'new' models

Post by gerd »

Thank you for replying swiftly. I really don't want to bother people around here 24/7. So let me pls. ask just one more for starters: one of the reasons I got stuck on https://tenpy.github.io/intro_model.html was that both, right from the start with the local Hilbert spaces, as well as for the xxz's constructor's 1st few lines it was not clear to me if there would be a default way of opting out of tenpy's handling of symmetries, just in order to get used to all of the remaining stuff. Or speaking differently, if I need to go for https://tenpy.github.io/intro_npc.html and all of its ramifications 1st, before even thinking about making Sites.
(PS.: I definitely did not mean to criticize the tremendous amount of info you've put together for tenpy. It's just stupid me that cannot digest it properly.)
User avatar
Johannes
Site Admin
Posts: 413
Joined: 21 Jul 2018, 12:52
Location: TU Munich

Re: Implementing 'new' models

Post by Johannes »

All of tenpy (DMRG etc) uses the np_conserved module for tensors, as this is necessary for implementing symmetries.
The basic idea is that the `Array` defined there has a very similar interface as numpy arrays, instead of numpy.tensordot(...) you can just use np_conserved.tensordot(...) etc.
Our `Array` has some additional features compared to the numpy array (e.g. labeling of the legs, which makes code much more readable), and misses some other features though.
If you don't want to dig into np_conserved, you can start by using "trivial" charges:

Code: Select all

leg = npc.LegCharge.from_trivial(d)
where d is the dimension of the local Hilbert space (i.e. you local operators defined in the Site have dimension d x d.

I hope that helps :)
gerd
Posts: 7
Joined: 15 Oct 2018, 23:23

Re: Implementing 'new' models

Post by gerd »

gerd wrote: 16 Oct 2018, 15:55...don't want to bother people around here 24/7
Ok. so I'm already back, violating my own commitments :(, but I got stuck on your examples for the XXZ and TFI chain in https://tenpy.github.io/intro_model.html. There you set the lattice like so:

Code: Select all

# 4) lattice
bc = 'periodic' if bc_MPS == 'infinite' else 'open'
lat = Chain(L, site, bc=bc, bc_MPS=bc_MPS)
After adapting this example to my case, and creating an instance, Python choked with

Code: Select all

TypeError: __init__() got an unexpected keyword argument 'bc'
Looking at the signature of the source of Chain.__init__ I get

Code: Select all

print(inspect.getsource(Chain.__init__))
    # ...
    def __init__(self, L, site, bc_MPS='finite'):
which does not seem to agree with https://tenpy.github.io/_modules/tenpy/ ... html#Chain. When I simply drop the line

Code: Select all

bc = 'periodic' if bc_MPS == 'infinite' else 'open'
and instantiate via

Code: Select all

lat = Chain(L, site, bc_MPS=bc_MPS)
then, Python seems to be happy but I'm lost as to if this will leave me with a proper model, and if 'bc' is somehow set at a later stage or not needed?
User avatar
Johannes
Site Admin
Posts: 413
Joined: 21 Jul 2018, 12:52
Location: TU Munich

Re: Implementing 'new' models

Post by Johannes »

Oh oh :o
But there's a simple solution: update your TeNPy source to the newest version with a git pull (and if necessary, compile the np_conserved parts again).
Since we are still in the 0.XX version numbers, I allowed myself to do a few backwards incompatible change(s). Moving the "bc" keyword from the Model to the lattice, which was suggested by mrader, is one of them. As it only added a new keyword to the __init__ of tenpy, hoping that nobody would have problems with it (I made it such, that you can still give the bc in the Model, but this raises a depreciation warning).
The full list of changes is given in the changelog. It's time for an official new version...
The intoduction to models (in fact, the whole online documentation) is based on the latest version of the git repository.
gerd
Posts: 7
Joined: 15 Oct 2018, 23:23

Re: Implementing 'new' models

Post by gerd »

Thx. a lot! Now I do have '...some...' class MyMod(CouplingModel, MPOModel) model, anticipated to describe my Eqn. (1). It seemed not to be that hard after all, following your suggestions. I essentially carried over the operators I had used to adapt the iTEBD example from Efficient Numerical Simulations Using Matrix-Product States, by Frank Pollmann frankp@pks.mpg.de into the 'Site' and then added them as 'add_onsite' and 'add_coupling' in hopefully proper ways. I could then instantiate the model, an initial MPS and do 'dmrg.run' on it ... and the results completely disagree with those I got from the simple iTEBD code for the preceding ref. ... for which I have proper comparison to existing results from literature ... oh well ... :) :(

Any suggestions for n00bs, where to start debugging?
User avatar
Johannes
Site Admin
Posts: 413
Joined: 21 Jul 2018, 12:52
Location: TU Munich

Re: Implementing 'new' models

Post by Johannes »

gerd wrote: 17 Oct 2018, 17:31 It seemed not to be that hard after all, following your suggestions.
That's what I hoped :)
gerd wrote: 17 Oct 2018, 17:31 ... and the results completely disagree with those I got from the simple iTEBD code for the preceding ref. ...
And that shouldn't happen :?
Do you need to truncate strongly?
Is there symmetry breaking? Or a ground state degeneracy due to a topological phase? Then it might not be clear what state DMRG converges to.

You can also try to run iTEBD, and see whether you get another state from that.
Post Reply