Skip to content

Commit

Permalink
remove mps_t
Browse files Browse the repository at this point in the history
  • Loading branch information
wistaria committed Nov 16, 2023
1 parent 6e83f15 commit b9c1410
Show file tree
Hide file tree
Showing 14 changed files with 34 additions and 533 deletions.
3 changes: 1 addition & 2 deletions src/qailo/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from . import alg, mps, mps_p, mps_t, operator, state_vector, util
from . import alg, mps, mps_p, operator, state_vector, util
from . import operator as op
from . import state_vector as sv
from ._version import version
Expand All @@ -8,7 +8,6 @@
alg,
mps,
mps_p,
mps_t,
operator,
state_vector,
util,
Expand Down
4 changes: 2 additions & 2 deletions src/qailo/mps_p/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from .mps_p import MPS_P
from .product_state import one, product_state, zero
from .projector import compact_projector
from .projector import projector

__all__ = [
MPS_P,
compact_projector,
projector,
one,
product_state,
zero,
Expand Down
4 changes: 2 additions & 2 deletions src/qailo/mps_p/mps_p.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from ..mps.svd import tensor_svd
from ..mps.type import MPS
from ..operator import type as op
from .projector import compact_projector
from .projector import projector


class MPS_P(MPS):
Expand Down Expand Up @@ -126,6 +126,6 @@ def _apply_two(self, p, s, maxdim=None, reverse=False):
t1 = np.einsum(t1, [0, 4, 3], p0, [2, 4, 1])
tt0 = np.einsum(self.env[s], [0, 4], t0, [4, 1, 2, 3])
tt1 = np.einsum(t1, [0, 1, 2, 4], self.env[s + 2], [4, 3])
_, WLh, WR = compact_projector(tt0, [0, 1, 4, 5], tt1, [5, 4, 2, 3], maxdim)
_, WLh, WR = projector(tt0, [0, 1, 4, 5], tt1, [5, 4, 2, 3], maxdim)
self.tensors[s] = np.einsum(t0, [0, 1, 3, 4], WR, [3, 4, 2])
self.tensors[s + 1] = np.einsum(WLh, [3, 4, 0], t1, [4, 3, 1, 2])
50 changes: 1 addition & 49 deletions src/qailo/mps_p/projector.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def collect_legs(ss0, ss1):
return legs0L, legs0R, legs1L, legs1R


def compact_projector(T0, ss0_in, T1, ss1_in, nkeep=None, tol=1e-12):
def projector(T0, ss0_in, T1, ss1_in, nkeep=None, tol=1e-12):
ss0, ss1 = normalize_ss(ss0_in, ss1_in)
legs0L, legs0R, legs1L, legs1R = collect_legs(ss0, ss1)
dim0L = np.prod([T0.shape[i] for i in legs0L])
Expand All @@ -70,51 +70,3 @@ def compact_projector(T0, ss0_in, T1, ss1_in, nkeep=None, tol=1e-12):
WL = np.einsum(TT0.conj(), [0] + ss_sum, U, [0, max(ss_sum) + 1])
WR = np.einsum(TT1, [0] + ss_sum, V, [0, max(ss_sum) + 1])
return S, WL.conj(), WR


def _biorth(VL, VR):
assert len(VL.shape) == 2 and VL.shape == VR.shape and VL.shape[0] >= VL.shape[1]
r = VL.shape[1]
for i in range(r):
for j in range(i):
VL[:, i] = VL[:, i] - (VR[:, j].conj().T @ VL[:, i]) * VL[:, j]
VR[:, i] = VR[:, i] - (VL[:, j].conj().T @ VR[:, i]) * VR[:, j]
norm = VL[:, i].conj().T @ VR[:, i]
VL[:, i] = VL[:, i] / (norm.conj() / np.sqrt(np.abs(norm)))
VR[:, i] = VR[:, i] / np.sqrt(np.abs(norm))
return VL, VR


def _full_projector(T0, ss0_in, T1, ss1_in, tol=1e-12):
"""
Return:
S: singular values
d: number of non-zero singular values
WL, WR: full projector WL* @ WR = I
"""
S, WLdh, WRd = compact_projector(T0, ss0_in, T1, ss1_in, tol=tol)
WLd = WLdh.conj()
d = S.shape[0]
assert d == WLd.shape[-1] and d == WRd.shape[-1]
dimsWL0 = WLd.shape[:-1]
dimsWR0 = WRd.shape[:-1]
m = np.prod(dimsWL0)
assert m == np.prod(dimsWR0)
if d < m:
WLd = WLd.reshape((m, d))
WRd = WRd.reshape((m, d))
P = np.identity(m) - WRd @ WLd.conj().T
VL = np.random.rand(m, m - d)
VR = np.random.rand(m, m - d)
VL = P.conj().T @ VL
VR = P @ VR
VL, VR = _biorth(VL, VR)
S = np.block([S, np.zeros(m - d)])
WL = np.block([WLd, VL])
WR = np.block([WRd, VR])
assert S.shape == (m,) and WL.shape == (m, m) and WR.shape == (m, m)
WL = WL.reshape(dimsWL0 + (m,))
WR = WR.reshape(dimsWR0 + (m,))
return S, d, WL.conj(), WR
else:
return S, d, WLd.conj(), WRd
9 changes: 0 additions & 9 deletions src/qailo/mps_t/__init__.py

This file was deleted.

138 changes: 0 additions & 138 deletions src/qailo/mps_t/mps_t.py

This file was deleted.

19 changes: 0 additions & 19 deletions src/qailo/mps_t/product_state.py

This file was deleted.

119 changes: 0 additions & 119 deletions src/qailo/mps_t/tpool.py

This file was deleted.

Loading

0 comments on commit b9c1410

Please sign in to comment.