-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DMRG algorithm left/right block implementation
- Loading branch information
1 parent
477f28b
commit 1773473
Showing
10 changed files
with
185 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
from syngular.tensor.matrix_product_state import MatrixProductState | ||
from syngular.tensor.matrix_product_operator import MatrixProductOperator | ||
from syngular.tensor.matrix_product_density_operator import MatrixProductDensityOperator | ||
from syngular.tensor.differential_matrix_product_operator import DifferentialMatrixProductOperator | ||
from syngular.tensor.differential_matrix_product_operator import DifferentialMatrixProductOperator | ||
from syngular.tensor.generalized_site import GeneralizedSite, Index |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from __future__ import annotations | ||
from typing import Tuple, List, Union | ||
|
||
import numpy as np | ||
from scipy import linalg | ||
|
||
from opt_einsum import contract | ||
|
||
class Index: | ||
name: str | ||
dim: int | ||
|
||
GeneralizedSite = dict[str, list[Index]] | ||
|
||
# class GeneralizedSite: | ||
|
||
# def __init__(self, groups: Group) -> None: | ||
# self.groups = groups | ||
|
||
# def __getitem__(self, index: str): | ||
# return self.groups[] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
from __future__ import annotations | ||
from typing import Tuple, List, Union | ||
|
||
import numpy as np | ||
from pandas import array | ||
from scipy import linalg | ||
|
||
from opt_einsum import contract | ||
|
||
class PEPState: | ||
|
||
""" | ||
Example: a 3x3 PEPS | ||
| | | | ||
---O---O---O--- | ||
/ | / | / | | ||
---O---O---O--- | ||
/ | / | / | | ||
---O---O---O--- | ||
/ | / | / | | ||
Convention: | ||
| (t) | ||
(l) ---O--- (r) ==> (l, t, i, b, r) | ||
(i) / | (b) | ||
""" | ||
|
||
def __init__(self, tensor, bond_matrix: List[List[int]]) -> None: | ||
self.parameters_number = 0 | ||
self.real_parameters_number = 0 | ||
|
||
if tensor is not None: | ||
self.tensor_shape = tensor.shape | ||
self.bond_matrix = np.array(bond_matrix) | ||
|
||
self.width = bond_matrix.shape[0] | ||
self.height = bond_matrix.shape[1] | ||
|
||
self.order = len(self.tensor_shape) | ||
self.real_parameters_number = np.prod(self.tensor_shape) | ||
|
||
self.sites_number = len(self.bond_shape)+1 | ||
self.sites = [None] * self.sites_number | ||
|
||
if self.bond_matrix != (): | ||
self.shape = [] | ||
for w in self.width: | ||
for h in self.height: | ||
shp = (0,0,0,0) | ||
if w == 0: | ||
shp[0] = 1 | ||
elif w == self.width-1: | ||
shp[3] = 1 | ||
|
||
@staticmethod | ||
def ground(width: int, height: int) -> PEPState: | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from numpy import outer | ||
from syngular.variational import DMRG | ||
from syngular.tensor import MatrixProductOperator | ||
|
||
if __name__ == "__main__": | ||
|
||
input_shape = (3,3,3,3,3,3) | ||
output_shape = (3,3,3,3,3,3) | ||
bond_shape = (2,2,2,2,2) | ||
|
||
mpo = MatrixProductOperator.random(input_shape=input_shape, output_shape=output_shape, bond_shape=bond_shape) | ||
|
||
DMRG.solve(mpo) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from syngular.tensor import GeneralizedSite, Index | ||
|
||
site_1: GeneralizedSite = { | ||
"input": { | ||
'i1': 10, | ||
'i2': 5 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from syngular.variational.dmrg import DMRG | ||
from syngular.variational.lanczos import Lanczos |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
from syngular.tensor import MatrixProductOperator, MatrixProductState | ||
|
||
from opt_einsum import contract | ||
|
||
class DMRG: | ||
|
||
|
||
# Does not work with operator with input_shape != output_shape! | ||
# To remedy use rho = AA^t the d ensity matrix of the operator | ||
|
||
def solve(operator: MatrixProductOperator): | ||
|
||
n = operator.sites_number | ||
input_shape = operator.input_shape | ||
bond_shape = operator.bond_shape | ||
|
||
state = MatrixProductState.random(input_shape=input_shape, bond_shape=bond_shape) | ||
state.right_orthonormalization() | ||
|
||
print('[DMRG] Initialization') | ||
|
||
left_blocks = DMRG.__left_blocks(operator=operator, state=state) | ||
right_blocks = DMRG.__right_blocks(operator=operator, state=state) | ||
|
||
print([r.shape for r in right_blocks]) | ||
print([r.shape for r in left_blocks]) | ||
|
||
|
||
def __right_blocks(operator: MatrixProductOperator, state: MatrixProductState): | ||
right_blocks = [] | ||
n = operator.sites_number | ||
|
||
print('[DMRG] Right blocks') | ||
|
||
for k in range(n-1,1,-1): | ||
|
||
state_site = state.sites[k] | ||
op_site = operator.sites[k] | ||
|
||
struct = [ | ||
state_site, [1,3,2], | ||
op_site, [4,6,3,5], | ||
state_site, [7, 6, 8] | ||
] | ||
if k != n-1: struct += [right_blocks[n-k-2], [2,5,8]] | ||
struct += [[1, 4, 7]] | ||
|
||
block = contract(*struct) | ||
right_blocks.append(block) | ||
|
||
return right_blocks | ||
|
||
|
||
def __left_blocks(operator: MatrixProductOperator, state: MatrixProductState): | ||
left_blocks = [] | ||
n = operator.sites_number | ||
|
||
print('[DMRG] Left blocks') | ||
|
||
for k in range(n-2): | ||
|
||
state_site = state.sites[k] | ||
op_site = operator.sites[k] | ||
|
||
struct = [ | ||
state_site, [1,3,2], | ||
op_site, [4,6,3,5], | ||
state_site, [7, 6, 8] | ||
] | ||
if k != 0: struct += [left_blocks[k-1], [1, 4, 7]] | ||
struct += [[2, 5, 8]] | ||
|
||
block = contract(*struct) | ||
left_blocks.append(block) | ||
|
||
return left_blocks |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
|
||
class Lanczos: | ||
pass |