def compress(self, norm=False, verbose=False): self.psi.right_normalize() if verbose is True: pbar = ProgressBar() for n in pbar(range(0, self.length - 1)): self.psi.node[n].tensor, self.psi.node[ n + 1].tensor = svd_node_pair.left(self.psi.node[n], self.psi.node[n + 1], D_cap=self.D) else: for n in range(0, self.length - 1): self.psi.node[n].tensor, self.psi.node[ n + 1].tensor = svd_node_pair.left(self.psi.node[n], self.psi.node[n + 1], D_cap=self.D) cross_network = rail_network(self.psi_orig.conj(), self.psi) cross_network.contract() cross_term = cross_network.contraction self.error = np.abs(self.orig_norm - cross_term + np.conj(cross_term) + self.psi.dot(self.psi))**2 if verbose is True: print("SVD Compression error=" + str(self.error)) return self.psi
def right_sweep(self): #first site if type(self.psi) is periodic_MPS: # self.psi_trial.node[0].tensor = np.einsum('ijk,akbc->iabc',self.psi.node[0].tensor,self.R[1].tensor) self.psi_trial.node[0].tensor = np.einsum('ijk,akbj->iba', self.psi.node[0].tensor, self.R[1].tensor) else: self.psi_trial.node[0].tensor = np.conj( np.einsum('ab,cb->ac', self.network.bot_row.node[0].tensor, self.R[1].tensor)) #Shift norm with svd + generate left blocks self.psi_trial.node[0].tensor, self.psi_trial.node[ 1].tensor = svd_node_pair.left(self.psi_trial.node[0], self.psi_trial.node[1], D_cap=self.D, rescale=True) self.L[0] = collapsed_layer.factory(layer(self.network, 0)) self.overlap_L[0] = collapsed_layer.factory( layer(self.overlap_network, 0)) # if self.verbose is True: # pbar=ProgressBar(widgets=[str(self.error)+':',Bar()]) for n in range(1, self.length - 1): if type(self.psi) is periodic_MPS: self.psi_trial.node[n].tensor = np.einsum( 'ikja,bac,dcik->bjd', self.L[n - 1].tensor, self.psi.node[n].tensor, self.R[n + 1].tensor) else: self.psi_trial.node[n].tensor = np.conj( np.einsum('ab,cbe,de->cad', self.L[n - 1].tensor, self.network.bot_row.node[n].tensor, self.R[n + 1].tensor)) #shift norm + grow left block self.psi_trial.node[n].tensor, self.psi_trial.node[ n + 1].tensor = svd_node_pair.left(self.psi_trial.node[n], self.psi_trial.node[n + 1], D_cap=self.D, rescale=True) clayer = collapsed_layer.factory(layer(self.network, n)) self.L[n] = combine_collapsed_layers.new_collapsed_layer( self.L[n - 1], clayer) clayer = collapsed_layer.factory(layer(self.overlap_network, n)) self.overlap_L[n] = combine_collapsed_layers.new_collapsed_layer( self.overlap_L[n - 1], clayer) psi_trial_norm = np.einsum( 'ab,ab', np.conj(self.psi_trial.node[self.length - 1].tensor), self.psi_trial.node[self.length - 1].tensor) # psi_trial_norm = np.abs(self.psi_trial.dot(self.psi_trial)) self.error = np.abs(self.psi_norm - psi_trial_norm)**2 self.distance = np.append(self.distance, self.error)
def right_sweep(self): #first site if type(self.psi) is periodic_MPS: # self.psi_trial.node[0].tensor = np.einsum('ijk,akbc->iabc',self.psi.node[0].tensor,self.R[1].tensor) self.psi_trial.node[0].tensor = np.einsum('ijk,akbj->iba', self.psi.node[0].tensor, self.R[1].tensor) else: self.psi_trial.node[0].tensor = np.einsum('ij,kj->ik', self.psi.node[0].tensor, self.R[1].tensor) #Shift norm with svd + generate left blocks self.psi_trial.node[0].tensor, self.psi_trial.node[ 1].tensor = svd_node_pair.left(self.psi_trial.node[0], self.psi_trial.node[1]) self.L[0] = collapsed_layer.factory(layer(self.network, 0)) self.overlap_L[0] = collapsed_layer.factory(layer(self.cross_term1, 0)) # if self.verbose is True: # pbar=ProgressBar(widgets=[str(self.error)+':',Bar()]) for n in range(1, self.length - 1): if type(self.psi) is periodic_MPS: self.psi_trial.node[n].tensor = np.einsum( 'ikja,bac,dcik->bjd', self.L[n - 1].tensor, self.psi.node[n].tensor, self.R[n + 1].tensor) else: self.psi_trial.node[n].tensor = np.einsum( 'ij,ajk,bk->aib', self.L[n - 1].tensor, self.psi.node[n].tensor, self.R[n + 1].tensor) #shift norm + grow left block self.psi_trial.node[n].tensor, self.psi_trial.node[ n + 1].tensor = svd_node_pair.left(self.psi_trial.node[n], self.psi_trial.node[n + 1]) clayer = collapsed_layer.factory(layer(self.network, n)) self.L[n] = combine_collapsed_layers.new_collapsed_layer( self.L[n - 1], clayer) clayer = collapsed_layer.factory(layer(self.cross_term1, n)) self.overlap_L[n] = combine_collapsed_layers.new_collapsed_layer( self.overlap_L[n - 1], clayer) cross_overlap = np.einsum('ab,ca,cb', self.overlap_L[self.length - 2].tensor, self.psi.node[self.length - 1].tensor, self.psi_trial.node[self.length - 1].tensor) psi_trial_norm = np.einsum('ca,ca', self.psi_trial.node[self.length - 1].tensor, self.psi_trial.node[self.length - 1].tensor) self.error = np.abs(self.psi_norm - cross_overlap + np.conj(cross_overlap) + psi_trial_norm)**2 self.distance = np.append(self.distance, self.error)
def left_normalize(self, norm=False, verbose=False): if verbose is True: print("Left normalizing MPS") pbar = ProgressBar() for n in pbar(range(0, self.length - 1)): self.node[n].tensor, self.node[n + 1].tensor = svd_node_pair.left( self.node[n], self.node[n + 1]) else: for n in range(0, self.length - 1): self.node[n].tensor, self.node[n + 1].tensor = svd_node_pair.left( self.node[n], self.node[n + 1]) if norm is True: self.node[self.length - 1].tensor = svd_norm_node.left( self.node[self.length - 1])
def compress(self, norm=False, verbose=False): if verbose is True: pbar = ProgressBar() for n in pbar(range(0, self.length - 1)): self.psi.node[n].tensor, self.psi.node[ n + 1].tensor = svd_node_pair.left(self.psi.node[n], self.psi.node[n + 1], D_cap=self.D, rescale=True) else: for n in range(0, self.length - 1): self.psi.node[n].tensor, self.psi.node[ n + 1].tensor = svd_node_pair.left(self.psi.node[n], self.psi.node[n + 1], D_cap=self.D, rescale=True) new_norm = np.abs( np.einsum('ab,ab', self.psi.node[self.length - 1].tensor, np.conj(self.psi.node[self.length - 1].tensor))) # new_norm = np.abs(self.psi.dot(self.psi)) # print(new_norm,np.abs(self.psi.dot(self.psi))) if norm == False: self.psi.node[ self.length - 1].tensor = self.psi.node[self.length - 1].tensor * np.power( self.orig_norm / new_norm, 0.5) else: self.psi.node[self.length - 1].tensor = self.psi.node[self.length - 1].tensor / np.power( new_norm, 0.5) # cross_network = rail_network(self.psi_orig.conj(),self.psi) # cross_network.contract() # cross_term = cross_network.contraction # self.error = np.abs(self.orig_norm - cross_term + np.conj(cross_term) + self.psi.dot(self.psi))**2 self.error = np.abs(self.orig_norm - new_norm)**2 if verbose is True: print("SVD Compression error=" + str(self.error)) return self.psi
def __init__(self, H_4site, phys_dim, D): self.D = D print(self.D) method = dmrg(H_4site, self.D) self.psi = method.run() print(np.shape(self.psi.node[1].tensor)) self.psi_grown = copy.deepcopy(self.psi) self.H_4site = H_4site self.H_grown = copy.deepcopy(self.H_4site) self.phys_dim = phys_dim self.length = self.psi.length #fix norm AASBB self.psi.node[0].tensor, self.psi.node[1].tensor = svd_node_pair.left( self.psi.node[0], self.psi.node[1], D_cap=self.D) self.psi.node[2].tensor, self.psi.node[3].tensor = svd_node_pair.right( self.psi.node[2], self.psi.node[3], D_cap=self.D) T = np.einsum('ijk,ukv->ijuv', self.psi.node[1].tensor, self.psi.node[2].tensor) shape0 = np.shape(T) T = T.reshape((np.array( (shape0[0] * shape0[1], shape0[2] * shape0[3])))) U, S, Vh = np.linalg.svd(T, full_matrices=False) U = U[:, 0:self.D] S = S[0:self.D] Vh = Vh[0:self.D, :] U = np.dot(U, np.power(np.diag(S), 0.5)) Vh = np.dot(np.power(np.diag(S), 0.5), Vh) A = U.reshape(np.array((shape0[0], shape0[1], np.size(S)))) Vh = Vh.reshape(np.array((np.size(S), shape0[2], shape0[3]))) B = np.einsum('ijk->jik', Vh) shape = np.shape(B) B = B.reshape(np.array((shape[0], shape[1], shape[2]))) self.psi.node[1].tensor = A self.psi.node[2].tensor = B #form L=AA, R=BB blocks for efficient H construction self.network = rail_network(self.psi_grown, self.psi_grown, self.H_4site) clayer0 = collapsed_layer.factory(layer(self.network, 0)) clayer1 = collapsed_layer.factory(layer(self.network, 1)) self.L = combine_collapsed_layers.new_collapsed_layer(clayer0, clayer1) clayer2 = collapsed_layer.factory(layer(self.network, 2)) clayer3 = collapsed_layer.factory(layer(self.network, 3)) self.R = combine_collapsed_layers.new_collapsed_layer(clayer2, clayer3)
def mixed_normalize(self, site): print("Mixed normalizing MPS") print("Left norm:") pbar = ProgressBar() for n in pbar(range(0, self.length - 1)): self.node[n].tensor, self.node[n + 1].tensor = svd_node_pair.left( self.node[n], self.node[n + 1]) # self.node[self.length-1].tensor = svd_norm_node.left(self.node[self.length-1]) print("Right norm:") pbar = ProgressBar() for n in pbar(range(self.length - 1, site, -1)): self.node[n - 1].tensor, self.node[n].tensor = svd_node_pair.right( self.node[n - 1], self.node[n])
def right_sweep(self): #first site #form eigenvalue equation site_H_mpo = combine_mpoNode_clayers.factory( self.network.mid_row.node[0], self.R[1]) e, u = sp.linalg.eigh(site_H_mpo) M = u[:, 0] M = M.reshape(np.shape(self.network.top_row.node[0].tensor)) #update site and svd to shift norm self.psi.node[0].tensor = M self.psi.node[0].tensor, self.psi.node[1].tensor = svd_node_pair.left( self.psi.node[0], self.psi.node[1], D_cap=self.D) self.L[0] = collapsed_layer.factory(layer(self.network, 0)) self.var_L[0] = collapsed_layer.factory(layer(self.var_network, 0)) pbar = ProgressBar(widgets=[ 'E0=' + str(self.energy) + ',Var=' + str(self.variance) + ':', Bar(marker=RotatingMarker()) ]) for n in pbar(range(1, self.length - 1)): site_H_mpo = combine_mpoNode_clayers.factory( self.network.mid_row.node[n], self.L[n - 1], self.R[n + 1]) # e,u = sp.sparse.linalg.eigsh(site_H_mpo,k=1) e, u = np.linalg.eigh(site_H_mpo) M = u[:, 0] shape_A = np.shape(self.network.top_row.node[n].tensor) new_phys_dim = int(np.size(M) / (shape_A[1] * shape_A[2])) M = M.reshape(np.array((new_phys_dim, shape_A[1], shape_A[2]))) #update site self.psi.node[n].tensor = M #update errors clayer = combine_clayer_layer.new_collapsed_layer( self.L[n - 1], layer(self.network, n)) self.energy = combine_collapsed_layers.scalar( clayer, self.R[n + 1]) self.energy_vals = np.append(self.energy_vals, self.energy) clayer = combine_clayer_layer.new_collapsed_layer( self.var_L[n - 1], layer(self.var_network, n)) self.variance = combine_collapsed_layers.scalar( clayer, self.var_R[n + 1]) - self.energy**2 self.variance_vals = np.append(self.variance_vals, self.variance) #shift norm self.psi.node[n].tensor, self.psi.node[ n + 1].tensor = svd_node_pair.left(self.psi.node[n], self.psi.node[n + 1], D_cap=self.D) #form new L blocks self.L[n] = combine_clayer_layer.new_collapsed_layer( self.L[n - 1], layer(self.network, n)) self.var_L[n] = combine_clayer_layer.new_collapsed_layer( self.var_L[n - 1], layer(self.var_network, n)) self.psi.node[self.length - 1].tensor = svd_norm_node.left( self.psi.node[self.length - 1]) self.energy = combine_clayer_layer.scalar( self.L[self.length - 2], layer(self.network, self.length - 1)) self.energy_vals = np.append(self.energy_vals, self.energy) self.variance = combine_clayer_layer.scalar( self.var_L[self.length - 2], layer(self.var_network, self.length - 1)) - self.energy**2 self.variance_vals = np.append(self.variance_vals, self.variance)