Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug of setting center_position in apply_two_site_gate when there's no truncation #954

Open
SUSYUSTC opened this issue Nov 21, 2021 · 0 comments

Comments

@SUSYUSTC
Copy link

SUSYUSTC commented Nov 21, 2021

In source file matrixproductstates/base_mps.py
function apply_two_site_gate
line 583-592:

      if center_position == site2:
        R, Q = self.backend.rq(tensor, pivot_axis=2)
        left_tensor = R
        right_tensor = Q
        set_center_position(site2)
      else:
        Q, R = self.backend.qr(tensor, pivot_axis=2)
        left_tensor = Q
        right_tensor = R
        set_center_position(site1)

This code block corresponds to the case that no truncation is performed when applying a two site gate.
Since site1 is left to site2, and that all nodes except the center one should be unitary after the operations, one should use rq if center_position == site1 and qr if center_position == site2.

So the right one should be

      if center_position == site1:
        R, Q = self.backend.rq(tensor, pivot_axis=2)
        left_tensor = R
        right_tensor = Q
        set_center_position(site1)
      else:
        Q, R = self.backend.qr(tensor, pivot_axis=2)
        left_tensor = Q
        right_tensor = R
        set_center_position(site2)

A simple example to illustrate this issue is:

import tensornetwork as tn
import numpy as np
I = np.eye(4, dtype=np.complex64).reshape((2, 2, 2, 2))

mps = tn.FiniteMPS.random([2, 2, 2, 2], [4, 4, 4], dtype=np.complex64, canonicalize=True)
mps.position(2)
mps.apply_two_site_gate(I, 1, 2, center_position=1)
print(mps.bond_dimensions)
print(mps.check_canonical())

mps = tn.FiniteMPS.random([2, 2, 2, 2], [4, 4, 4], dtype=np.complex64, canonicalize=True)
mps.position(2)
mps.apply_two_site_gate(I, 1, 2, center_position=1, max_singular_values=100)
print(mps.bond_dimensions)
print(mps.check_canonical())

where I got

[1, 2, 4, 2, 1] 
(1.6877086162567145+0j)     # not canonical because of wrong center position
[1, 2, 4, 2, 1]
(8.9081379319908e-08+0j)    # canonical
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant