Apply MPO to MPS

How do I use this algorithm? What does that parameter do?
Post Reply
Posts: 2
Joined: 08 May 2020, 20:07

Apply MPO to MPS

Post by rgbmrc20 »


I was wondering, is there some built-in functionality to apply an MPO to an MPS?
In the meantime I tried to come up with something but I am afraid it messes with the form and normalization of the MPS.
In a very simple scenario of an MPO with virtual bond dimension [1, 2, 2, ..., 1] and and no conserved charges would something like

Code: Select all

def contract_at_site(i, mpo, mps):
    w, b = mpo.get_W(i), mps.get_B(i, form='B')
    cntr = npc.tensordot(w, b, axes=('p*', 'p'))
    cntr = cntr.combine_legs([['vL', 'wL'], ['vR', 'wR']], qconj=[1, -1])
    cntr.ireplace_labels(['(vL.wL)', '(vR.wR)'], ['vL', 'vR'])
    mps.set_B(i, cntr, form='B')
    if i > 0: 
        s = mps.get_SL(i)
        mps.set_SL(i, np.tile(s, 2))

for i in range(mps.L): 
    contract_at_site(i, mpo, mps)
go in the right direction?
(I am not interested in performance, I am mostly trying to learn about tensor networks for the moment.)

Best regards,

User avatar
Site Admin
Posts: 179
Joined: 21 Jul 2018, 12:52
Location: UC Berkeley

Re: Apply MPO to MPS

Post by Johannes »

Yes, that's almost right.
We're working on something like this in the exp_MPO branch on github. It's not quite ready for use, and we will adjust the interface to better match the other evolution algorithms, but it basically works as a preliminary version, and you can look at it to see how it works.
Right now, this branch contains the file tenpy/algorithms/, where we have very similar code as your example in the function apply_MPO.

You can see that we have slightly different guesses for the singular values.
In fact, since applying the MPO destroys the canonical form, you should just recalculate them (The only guess really uses is at bond 0 for infinite MPS).
Moreovaer, as applying the MPO increases the bond dimension, it is important to compress the state again afterwards.
This can be done in the same step as bringing it back in canonical form.

Posts: 2
Joined: 08 May 2020, 20:07

Re: Apply MPO to MPS

Post by rgbmrc20 »

Thanks for pointing me to this apply_MPO code, I think it is now clear to me what I should correct.

Regarding the canonical form and compression, I should have mentioned that my MPO/MPS are finite and I was calling canonical_form_finite() with a cutoff parameter after the above. A comment in mps_compress() suggests this should be fine, I now realize it also makes my SV guess useless.

Also, many thanks for your work, TenPy is proving very precious for my master thesis and I will remember to cite it!

Post Reply