Excited states using tenpy

How do I use this algorithm? What does that parameter do?
Post Reply
amankumar
Posts: 29
Joined: 17 Apr 2020, 11:14

Excited states using tenpy

Post by amankumar »

Hi
I am interested in to know the excited states of Kiteav's Toric code model. I was going through the documentation to understand how to use it. Can you briefly explain more how to use tenpy for evaluating excited states for lets say first two excited states only.
Here is my short code, where I am evaluating only ground state of topic code model.

Code: Select all

from tenpy.algorithms import dmrg
from toric_code import ToricCode
import numpy as np
from mps import MPS
def example_run_TC():
    model_params = dict(Lx=4, Ly=3, Jv=1, Jp=1,
                        verbose= 1)
    M = ToricCode(model_params)
    product_state=[0]*M.lat.N_sites
    psi = MPS.from_product_state(M.lat.mps_sites(), product_state, bc =M.lat.bc_MPS)
    dmrg_params = {
        'mixer': True,  # setting this to True helps to escape local minima
        'trunc_params': {
            'chi_max': 8,
            'svd_min': 1.e-10,
        },
        'max_E_err': 1.e-10,
        'verbose': 1,
        'max_sweeps':20,
    }
    results = dmrg.run(psi, M, dmrg_params)
    print("Energy per site: ", results['E'])

if __name__ == "__main__":
    example_run_TC()
Thanks
User avatar
Johannes
Site Admin
Posts: 413
Joined: 21 Jul 2018, 12:52
Location: TU Munich

Re: Excited states using tenpy

Post by Johannes »

you need to make a loop and run DMRG multiple times, each time orthogonalizing against the previous state:

Code: Select all

psi0 = MPS.from_product_state(...)
states = dmrg_params['orthogonal_to'] = []
for i in range(3):
    psi = psi0.copy()
    results = dmrg.run(psi, M, dmrg_params)
    states.append(psi)  # this also adds them to dmrg_params['orthogonal_to']
# now states contains the ground state and first two excited states.
Note that using orthogonal_to replaces \( H \rightarrow H' = (1 - \sum_i |\psi_i\rangle\langle\psi_i|) H (1 - \sum_i |\psi_i\rangle\langle\psi_i|) \) and then runs ordinary DMRG with \(H'\). This will fail to give you another excited state of H if you only have eigenstates with energy > 0.
amankumar
Posts: 29
Joined: 17 Apr 2020, 11:14

Re: Excited states using tenpy

Post by amankumar »

Thanks Johannes

1.) I guess the code line

Code: Select all

psi = psi0.copy()

should be before the for loop, otherwise it will keep using the initial matrix product state(that is psi0 copy).
2.) Also it give me an error saying:

Code: Select all

File "/home/aman/tenpy-master2/tenpy-master/examples/tenpy/algorithms/mps_sweeps.py", line 219, in init_env
raise ValueError("Can't orthogonalize for infinite MPS: overlap not well defined.")
ValueError: Can't orthogonalize for infinite MPS: overlap not well defined.
/home/aman/tenpy-master2/tenpy-master/examples/tenpy/tools/params.py:225: UserWarning: unused options for config DMRG:
['E_tol_to_trunc', 'N_sweeps_check', 'P_tol_max', 'P_tol_min', 'P_tol_to_trunc', 'chi_list', 'diag_method', 'max_E_err', 'max_N_for_ED', 'max_S_err', 'max_hours', 'max_sweeps', 'min_sweeps', 'mixer', 'mixer_params', 'norm_tol', 'norm_tol_iter', 'start_env', 'sweep_0', 'update_env']
 warnings.warn(msg.format(keys=sorted(unused), name=self.name))
 
User avatar
Johannes
Site Admin
Posts: 413
Joined: 21 Jul 2018, 12:52
Location: TU Munich

Re: Excited states using tenpy

Post by Johannes »

1) That was intentional, you need a new copy each time in the loop! After all, you want to have a list of 3 different states in the end.
You might at most argue that it's a bad idea to "restart" the whole DMRG from scratch for the excited states, if we already found a ground state.
But then you need to know an operator connecting the ground state with the excited state, which requires some a priori knowledge.

2) This error is raised if you try it for infinite MPS. The concept of "first excited state" is not well defined in the thermodynamic limit. More practically, any two different states have formally overlap 0 in the thermodynamic limit, so the trick of orthogonalization used by TeNPy no longer works.

amankumar
Posts: 29
Joined: 17 Apr 2020, 11:14

Re: Excited states using tenpy

Post by amankumar »

I still did not get the code, can you explain bit more.

Code: Select all

psi0 = MPS.from_product_state(...)
states = dmrg_params['orthogonal_to'] = []

So, here we create an initial MPS and then in next line I am confused, does it just add another parameter or routine orthogonal_to in dict dmrg_params.

Code: Select all

for i in range(3):
    psi = psi0.copy()
    results = dmrg.run(psi, M, dmrg_params)
    states.append(psi)  # this also adds them to dmrg_params['orthogonal_to']
    

Then in for loop, copy of initial state is there, and we run Dmrg, it gives ground state as psi. Then I don't understand the next line state.append(psi), so it take psi ground state, and what operation is done on it and what it will return after this operation?

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

Re: Excited states using tenpy

Post by Johannes »

the line states = dmrg_params['orthogonal_to'] = [] creates a new list and assigns it to both the variable name states and dmrg_params['orthogonal_to']. Remember, in Python everything is an "object", and your variables really are just references to objects.

Inside the loop, you first create a copy of psi0, which gets modified by the dmrg.run to the given ground state.
At the end of the loop, you append to states, which also modifies the dmrg_params['orthogonal_to'] (because both point to the same list object). So in the next dmrg run, it can read out the orthogonal_to list to contain the previously found MPS and orthogonalizes against them, hopefully finding the next excited state.

amankumar
Posts: 29
Joined: 17 Apr 2020, 11:14

Re: Excited states using tenpy

Post by amankumar »

Thanks a lot!
I have another basic question related to model interaction strength. Is there a way to put different interaction strength at each vertex in topic code model, like can I provide a array of strength parameter instead of just Jv.

Code: Select all

self.add_multi_coupling(-Jv, [('Sigmax', [0, 0], 1), ('Sigmax', [0, 0], 0),
                                      ('Sigmax', [-1, 0], 1), ('Sigmax', [0, -1], 0)])

Or is there something like manually one can put model interaction and strength at each bond and site?

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

Re: Excited states using tenpy

Post by Johannes »

Yes, any strength given to add_onsite, add_coupling, or add_multi_coupling can be an array, as documented in these functions.
Thus also Jv, is allowed to be a numpy array. The shape it needs to have depend on the boundary conditions and shape of your lattice.

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

Re: Excited states using tenpy

Post by Johannes »

I've update the model userguide to inclue a new section on this.

amankumar
Posts: 29
Joined: 17 Apr 2020, 11:14

Re: Excited states using tenpy

Post by amankumar »

Thanks for the update, I got it. Does add_onsite also support this array data type for strength?
May be, Now I am asking an offset question of this thread, actually I was interested in to provide the different types of boundary condition in y direction for a cylinder. I want a spiral winding of chain over cylinder kind of boundary condition(may be I am after bc_shift routine but I don't know how to use it). Not like multiple circular rings attached on cylinder. If you don't get my question let me know?

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

Re: Excited states using tenpy

Post by Johannes »

Sounds like you're after the bc_shift. With bc_shift=['open', -1] for finite MPS or bc_shift=['periodic', -1] for infinite MPS, couplings in "y-direction" of the lattice wind like a helix around the cylinder.
More details in this userguide section.
It might also be useful to look at the figure of tenpy.models.lattice.HelicalLattice for a vizualization.
Ash_Mad
Posts: 6
Joined: 09 Apr 2021, 06:06

Re: Excited states using tenpy

Post by Ash_Mad »

If the energies of the eigenstates are greater than 0, how do we then find the excited states and their corresponding energies?
Qottmann
Posts: 18
Joined: 27 Mar 2019, 09:11
Location: Barcelona

Re: Excited states using tenpy

Post by Qottmann »

Ash_Mad wrote: 14 Apr 2021, 18:35 If the energies of the eigenstates are greater than 0, how do we then find the excited states and their corresponding energies?
same question here!
Is there an easy way to change shift the Energy of the Hamiltonian by some constant or change the sign of the extra term from the orthogonal_to part?

edit: quick and dirty fix is to use a large chemical potential (in case that is available in your model and you fix the filling)
User avatar
Johannes
Site Admin
Posts: 413
Joined: 21 Jul 2018, 12:52
Location: TU Munich

Re: Excited states using tenpy

Post by Johannes »

You can use

Code: Select all

algorithm_params:
     diag_method: lanczos
     lanczos_params:
         E_shift: -10  # choose small enough such that E + E_shift < 0  (also for excitations!)
It basically does the same trick as you suggested - it just replaces H -> H + E_shift[inline], but the [inline]E_shift is automatically subtracted again from the energy at the end of lanczos, such that you get the correct energies reported in DMRG.

Also, note the new tenpy.simulations.ground_state_search.OrthogonalExcitations, which is designed to find excited states.
It can also handle infinite ground states by converting to segment boundary condtions.... However, it should see some more development to handle more complicated cases, e.g. non-trivial topological excitations with different environments left/right or the ends of semi-infinite chains. See Issue #142 for that...
Post Reply