Skip to content
This repository was archived by the owner on Nov 7, 2024. It is now read-only.
This repository was archived by the owner on Nov 7, 2024. It is now read-only.

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

@SUSYUSTC

Description

@SUSYUSTC

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions