def generate_parameters_dmrg(lattice='chain'): # ======================================================= # No further changes are needed for these codes model = ['chain', 'square', 'arbitrary', 'jigsaw', 'full', 'longRange'] if lattice is 'chain': para = parameter_dmrg_chain() elif lattice is 'square': para = parameter_dmrg_square() elif lattice is 'arbitrary': para = parameter_dmrg_arbitrary() elif lattice is 'jigsaw': para = parameter_dmrg_jigsaw() elif lattice is 'full': para = parameter_dmrg_full() elif lattice is 'longRange': para = parameter_dmrg_long_range() else: para = dict() print_error('Wrong input of lattice!') print_options(model, welcome='Set lattice as one of the following:\t', quote='\'') para1 = common_parameters_dmrg() para = dict(para, **para1) # combine with the common parameters para = make_consistent_parameter_dmrg(para) return para
def check_consistency(self): if self.n_tensor != len(self.indexes): print_error('ErrorNCON: the number of tensors and number of index tuples are not consistent', False) if self.bond_open[0] != -1: print_error('NumberingError: the starting number of open bonds should be -1', False) if self.bond_open.__len__() != (-self.bond_open[-1]): print_error('NumberingError: all integers in [-1, -(number of open bonds)] should appear in the ' 'numbering. Please check.') if self.bond_ark[0] != 1: print_error('NumberingError: the starting number of open bonds should be 1', False) if self.bond_ark.__len__() != self.bond_ark[-1]: print_error('NumberingError: all integers in [-1, -(number of ark bonds)] should appear in the ' 'numbering. Please check.')
def check_continuity_pos_h2(pos_h2): p0 = np.min(pos_h2) if p0 != 0: exit('The numbering of sites should start with 0, not %d. Please revise the numbering.' % p0) p1 = np.max(pos_h2) missing_number = list() for n in range(p0+1, p1): if n not in pos_h2: missing_number.append(n) if missing_number.__len__() > 0: print_error('The pos_h2 is expected to contain all numbers from 0 to %d. The following numbers are missing:' % p1) print(str(missing_number)) exit('Please check and revise you numbering')
def absorb_matrices2tensor(tensor, mats, bonds=np.zeros(0), mat_bond=-1): """ Absorb matrices to tensors on certain bonds :param tensor: a tensor :param mats: matrices :param bonds: which bonds of tensor to absorb matrices, default by from 0 to n :param mat_bond: which bond of matrices to contract to tensor, default as 0 bond :return: tensor absorbed matrices Example: >>>T = np.array([[[1, 1], [1, 1]],[[1, 1], [1, 1]]]) >>>M = [np.array([[1, 2], [2, 3]]), np.array([[2, 3], [3, 4]])] >>>print(absorb_matrices2tensor(T, M)) [[[15 15] [21 21]] [[25 25] [35 35]]] """ # default: contract the 1st bond of mat with tensor nm = len(mats) # number of matrices to be contracted if is_debug: if nm != tensor.ndim: print_error( 'InputError: the number of matrices should be equal to the number of indexes of tensor' ) if type(bonds) is list or tuple: bonds = np.array(bonds) if bonds.size == 0: # set default of bonds: contract all matrices in order, starting from the 0th bond bonds = np.arange(0, nm) if mat_bond < 0: # set default of mat_bond: contract the 1st bond of each matrix mat_bond = np.zeros((nm, 1)) for i in range( 0, nm): # permute if the second bond of a matrix is to be contracted if mat_bond[i, 0] == 1: mats[i] = mats[i].T # check if full_fast function can be used if np.array_equiv(np.sort(bonds), np.arange(0, tensor.ndim)): order = np.argsort(bonds) mats = sort_list(mats, order) # this full_fast function can be used when each bond has a matrix which are arranged in the correct order tensor = absorb_matrices2tensor_full_fast(tensor, mats) else: # can be optimized for i in range(0, nm): tensor = absorb_matrix2tensor(tensor, mats[i], bonds[i]) return tensor
def generate_parameters_dmrg(): lattice = 'arbitrary' # ======================================================= # No further changes are needed for these codes model = ['chain', 'square', 'arbitrary'] if lattice is 'chain': para = parameter_dmrg_chain() elif lattice is 'square': para = parameter_dmrg_square() elif lattice is 'arbitrary': para = parameter_dmrg_arbitrary() else: para = None print_error('Wrong input of lattice!') print_options(model, welcome='Set lattice as one of the following:\t', quote='\'') para['nh'] = para['index2'].shape[0] # number of two-body interactions return para