From 9ae739afd0e4743c7390c5f449fdc7945225b8cc Mon Sep 17 00:00:00 2001 From: hschnait Date: Tue, 8 Mar 2022 11:19:58 +0100 Subject: [PATCH 01/14] Update Docstrings in SK properties --- python/triqs_dft_tools/block_structure.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/python/triqs_dft_tools/block_structure.py b/python/triqs_dft_tools/block_structure.py index d0babdf5..7d37c1bd 100644 --- a/python/triqs_dft_tools/block_structure.py +++ b/python/triqs_dft_tools/block_structure.py @@ -136,13 +136,13 @@ class BlockStructure(object): This is returned as a list (for each shell) of lists (for each block) - of tuples (block_name, block_indices). + of tuples (block_name, block_dimension). That is, ``gf_struct_solver_list[ish][b][0]`` is the name of the block number ``b`` of shell ``ish``, and ``gf_struct_solver_list[ish][b][1]`` - is a list of its indices. + is the dimension of the block ``b``. The list for each shell is sorted alphabetically by block name. """ @@ -159,13 +159,13 @@ class BlockStructure(object): This is returned as a list (for each shell) of lists (for each block) - of tuples (block_name, block_indices) + of tuples (block_name, block_dimension) That is, ``gf_struct_sumk_list[ish][b][0]`` is the name of the block number ``b`` of shell ``ish``, and ``gf_struct_sumk_list[ish][b][1]`` - is a list of its indices. + is the dimension of the block ``b``. """ return self.gf_struct_sumk @@ -179,7 +179,7 @@ class BlockStructure(object): That is, ``gf_struct_solver_dict[ish][bname]`` - is a list of the indices of block ``bname`` of shell ``ish``. + is the dimension of block ``bname`` of shell ``ish``. """ return self.gf_struct_solver @@ -193,7 +193,7 @@ class BlockStructure(object): That is, ``gf_struct_sumk_dict[ish][bname]`` - is a list of the indices of block ``bname`` of shell ``ish``. + is the dimension of block ``bname`` of shell ``ish``. """ if self.gf_struct_sumk is None: return None From a8338819f038682474d51ededf550b370c5391cc Mon Sep 17 00:00:00 2001 From: hschnait Date: Tue, 8 Mar 2022 14:35:01 +0100 Subject: [PATCH 02/14] Update SumkDFT for new gf_struct --- python/triqs_dft_tools/sumk_dft.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/python/triqs_dft_tools/sumk_dft.py b/python/triqs_dft_tools/sumk_dft.py index 18f96da9..9978dd8b 100644 --- a/python/triqs_dft_tools/sumk_dft.py +++ b/python/triqs_dft_tools/sumk_dft.py @@ -138,10 +138,10 @@ class SumkDFT(object): # GF structure used for the local things in the k sums # Most general form allowing for all hybridisation, i.e. largest # blocks possible - self.gf_struct_sumk = [[(sp, list(range(self.corr_shells[icrsh]['dim']))) for sp in self.spin_block_names[self.corr_shells[icrsh]['SO']]] + self.gf_struct_sumk = [[(sp, self.corr_shells[icrsh]['dim']) for sp in self.spin_block_names[self.corr_shells[icrsh]['SO']]] for icrsh in range(self.n_corr_shells)] # First set a standard gf_struct solver: - self.gf_struct_solver = [dict([(sp, list(range(self.corr_shells[self.inequiv_to_corr[ish]]['dim']))) + self.gf_struct_solver = [dict([(sp, self.corr_shells[self.inequiv_to_corr[ish]]['dim']) for sp in self.spin_block_names[self.corr_shells[self.inequiv_to_corr[ish]]['SO']]]) for ish in range(self.n_inequiv_shells)] # Set standard (identity) maps from gf_struct_sumk <-> @@ -151,9 +151,9 @@ class SumkDFT(object): self.solver_to_sumk_block = [{} for ish in range(self.n_inequiv_shells)] for ish in range(self.n_inequiv_shells): - for block, inner_list in self.gf_struct_sumk[self.inequiv_to_corr[ish]]: + for block, inner_dim in self.gf_struct_sumk[self.inequiv_to_corr[ish]]: self.solver_to_sumk_block[ish][block] = block - for inner in inner_list: + for inner in range(inner_dim): self.sumk_to_solver[ish][ (block, inner)] = (block, inner) self.solver_to_sumk[ish][ @@ -743,13 +743,13 @@ class SumkDFT(object): G_loc = [self.Sigma_imp_iw[icrsh].copy() for icrsh in range( self.n_corr_shells)] # this list will be returned beta = G_loc[0].mesh.beta - G_loc_inequiv = [BlockGf(name_block_generator=[(block, GfImFreq(indices=inner, mesh=G_loc[0].mesh)) for block, inner in self.gf_struct_solver[ish].items()], + G_loc_inequiv = [BlockGf(name_block_generator=[(block, GfImFreq(target_shape=(block_dim, block_dim), mesh=G_loc[0].mesh)) for block, block_dim in self.gf_struct_solver[ish].items()], make_copies=False) for ish in range(self.n_inequiv_shells)] elif iw_or_w == "w": G_loc = [self.Sigma_imp_w[icrsh].copy() for icrsh in range( self.n_corr_shells)] # this list will be returned mesh = G_loc[0].mesh - G_loc_inequiv = [BlockGf(name_block_generator=[(block, GfReFreq(indices=inner, mesh=mesh)) for block, inner in self.gf_struct_solver[ish].items()], + G_loc_inequiv = [BlockGf(name_block_generator=[(block, GfReFreq(target_shape=(block_dim, block_dim), mesh=mesh)) for block, block_dim in self.gf_struct_solver[ish].items()], make_copies=False) for ish in range(self.n_inequiv_shells)] for icrsh in range(self.n_corr_shells): @@ -911,7 +911,7 @@ class SumkDFT(object): for i in range(num_blocs): blocs[i].sort() self.gf_struct_solver[ish].update( - [('%s_%s' % (sp, i), list(range(len(blocs[i]))))]) + [('%s_%s' % (sp, i), len(blocs[i]))]) # Construct sumk_to_solver taking (sumk_block, sumk_index) --> (solver_block, solver_inner) # and solver_to_sumk taking (solver_block, solver_inner) --> @@ -930,12 +930,12 @@ class SumkDFT(object): # Now calculate degeneracies of orbitals dm = {} - for block, inner in self.gf_struct_solver[ish].items(): + for block, block_dim in self.gf_struct_solver[ish].items(): # get dm for the blocks: dm[block] = numpy.zeros( - [len(inner), len(inner)], numpy.complex_) - for ind1 in inner: - for ind2 in inner: + [block_dim, block_dim], numpy.complex_) + for ind1 in range(block_dim): + for ind2 in range(block_dim): block_sumk, ind1_sumk = self.solver_to_sumk[ ish][(block, ind1)] block_sumk, ind2_sumk = self.solver_to_sumk[ @@ -1100,7 +1100,7 @@ class SumkDFT(object): for i in range(num_blocs): blocs[i].sort() self.gf_struct_solver[ish].update( - [('%s_%s' % (sp, i), list(range(len(blocs[i]))))]) + [('%s_%s' % (sp, i), len(blocs[i]))]) # Construct sumk_to_solver taking (sumk_block, sumk_index) --> (solver_block, solver_inner) # and solver_to_sumk taking (solver_block, solver_inner) --> @@ -1420,7 +1420,7 @@ class SumkDFT(object): "calculate_diagonalization_matrix: Choices for prop_to_be_diagonal are 'eal' or 'dm'.") return 0 - trans = [{block: numpy.eye(len(indices)) for block, indices in gfs} for gfs in self.gf_struct_sumk] + trans = [{block: numpy.eye(block_dim) for block, block_dim in gfs} for gfs in self.gf_struct_sumk] for ish in shells: trafo = {} From 0a95ffd9d0466d849e915381666da505845951cf Mon Sep 17 00:00:00 2001 From: hschnait Date: Tue, 8 Mar 2022 17:22:48 +0100 Subject: [PATCH 03/14] Modify block_structure for new gf_struct convention. --- python/triqs_dft_tools/block_structure.py | 71 ++++++++++++----------- 1 file changed, 37 insertions(+), 34 deletions(-) diff --git a/python/triqs_dft_tools/block_structure.py b/python/triqs_dft_tools/block_structure.py index 7d37c1bd..d1e9c687 100644 --- a/python/triqs_dft_tools/block_structure.py +++ b/python/triqs_dft_tools/block_structure.py @@ -48,11 +48,11 @@ class BlockStructure(object): Parameters ---------- gf_struct_sumk : list of list of tuple - gf_struct_sumk[ish][idx] = (block_name,list of indices in block) + gf_struct_sumk[ish][idx] = (block_name, dimension of block) for correlated shell ish; idx is just a counter in the list gf_struct_solver : list of dict - gf_struct_solver[ish][block] = list of indices in that block + gf_struct_solver[ish][block] = dimension of that block for *inequivalent* correlated shell ish solver_to_sumk : list of dict @@ -197,7 +197,7 @@ class BlockStructure(object): """ if self.gf_struct_sumk is None: return None - return [{block: indices for block, indices in gfs} + return [{block: block_dim for block, block_dim in gfs} for gfs in self.gf_struct_sumk] @property @@ -249,7 +249,7 @@ class BlockStructure(object): raise Exception('gf_struct_solver not set.') if trans is None: - trans = [{block: np.eye(len(indices)) for block, indices in gfs} + trans = [{block: np.eye(block_dim) for block, block_dim in gfs} for gfs in self.gf_struct_sumk] assert isinstance(trans, list),\ @@ -261,12 +261,12 @@ class BlockStructure(object): for icrsh in list(range(len(trans))): ish = self.corr_to_inequiv[icrsh] if trans[icrsh] is None: - trans[icrsh] = {block: np.eye(len(indices)) - for block, indices in self.gf_struct_sumk[icrsh]} + trans[icrsh] = {block: np.eye(block_dim) + for block, block_dim in self.gf_struct_sumk[icrsh]} if not isinstance(trans[icrsh], dict): trans[icrsh] = {block: copy.deepcopy(trans[icrsh]) - for block, indices in self.gf_struct_sumk[icrsh]} + for block, block_dim in self.gf_struct_sumk[icrsh]} assert list(trans[icrsh].keys()) == list(self.gf_struct_sumk_dict[icrsh].keys()),\ "wrong block names used in transformation (icrsh = {})".format(icrsh) @@ -275,14 +275,18 @@ class BlockStructure(object): assert trans[icrsh][block].shape[0] == trans[icrsh][block].shape[1],\ "Transformation has to be quadratic; throwing away orbitals can be achieved on the level of the mapping. (icrsh = {}, block = {})".format(icrsh, block) - assert trans[icrsh][block].shape[0] == len(self.gf_struct_sumk_dict[icrsh][block]),\ + assert trans[icrsh][block].shape[0] == self.gf_struct_sumk_dict[icrsh][block],\ "Transformation block shape does not match gf_struct_sumk. (icrsh = {}, block = {})".format(icrsh, block) # zero out all the lines of the transformation that are # not included in gf_struct_solver - for iorb, norb in enumerate(self.gf_struct_sumk_dict[icrsh][block]): - if self.sumk_to_solver[ish][(block, norb)][0] is None: + #TODO CHECK THIS! + for iorb in range(self.gf_struct_sumk_dict[icrsh][block]): + if self.sumk_to_solver[ish][(block, iorb)][0] is None: trans[icrsh][block][iorb, :] = 0.0 + # for iorb, norb in enumerate(self.gf_struct_sumk_dict[icrsh][block]): + # if self.sumk_to_solver[ish][(block, norb)][0] is None: + # trans[icrsh][block][iorb, :] = 0.0 return trans @property @@ -321,10 +325,10 @@ class BlockStructure(object): for block in self.gf_struct_solver[ish]: block_sumk = self.solver_to_sumk_block[ish][block] T = eff_trans_sumk[icrsh][block_sumk] - ets[ish][block] = np.zeros((len(self.gf_struct_solver[ish][block]), + ets[ish][block] = np.zeros((self.gf_struct_solver[ish][block], len(T)), dtype=T.dtype) - for i in self.gf_struct_solver[ish][block]: + for i in range(self.gf_struct_solver[ish][block]): i_sumk = self.solver_to_sumk[ish][block, i] assert i_sumk[0] == block_sumk,\ "Wrong block in solver_to_sumk" @@ -343,7 +347,7 @@ class BlockStructure(object): Parameters ---------- gf_struct : list of dict - gf_struct[ish][block] = list of indices in that block + gf_struct[ish][block] = block dimension of that block for (inequivalent) correlated shell ish corr_to_inequiv : list @@ -365,7 +369,7 @@ class BlockStructure(object): gss = [] for block in gf_struct[ish]: so2sublock[block]=block - for ind in gf_struct[ish][block]: + for ind in range(gf_struct[ish][block]): so2su[(block,ind)]=(block,ind) gss.append((block,gf_struct[ish][block])) solver_to_sumk.append(so2su) @@ -409,16 +413,14 @@ class BlockStructure(object): [{'up':[0],'down':[1]}] - Note that the indices will be renamed to be a 0-based - sequence of integers, i.e. the new structure will actually - be [{'up':[0],'down':[0]}]. + Note that as of version 3.1.x, the new structure itself will + actually be stored as [{'up':1,'down':1}]. For dropped indices, sumk_to_solver will map to (None,None). Parameters ---------- new_gf_struct : list of dict - formatted the same as gf_struct_solver: new_gf_struct[ish][block]=list of indices in that block. """ @@ -454,7 +456,8 @@ class BlockStructure(object): # reindexing gf_struct so that it starts with 0 for k in gf_struct: - gf_struct[k]=list(range(len(gf_struct[k]))) + # gf_struct[k]=list(range(len(gf_struct[k]))) + gf_struct[k]=len(gf_struct[k]) self.gf_struct_solver[ish]=gf_struct def adapt_deg_shells(self, gf_struct, ish=0): @@ -468,7 +471,7 @@ class BlockStructure(object): if not key in gf_struct: del degsh[key] continue - if gf_struct[key] != self.gf_struct_solver[ish][key]: + if len(gf_struct[key]) != self.gf_struct_solver[ish][key]: v, C = degsh[key] degsh[key][0] = \ v[gf_struct[key], :][:, gf_struct[key]] @@ -509,7 +512,6 @@ class BlockStructure(object): Parameters ---------- new_gf_struct : list of dict - formatted the same as gf_struct_solver: new_gf_struct[ish][block]=list of indices in that block. @@ -529,16 +531,16 @@ class BlockStructure(object): # one non-zero entry for icrsh in range(len(new_gf_struct)): - for block, indices in self.gf_struct_sumk[icrsh]: + for block, block_dim in self.gf_struct_sumk[icrsh]: if not block in new_gf_struct[icrsh]: #del new_gf_struct_transformed[block] # this MUST be wrong, as new_gf_struct_transformed needs to have a integer index for icrsh... # error when index is not kept at all continue T = eff_trans_sumk[icrsh][block] - for index in indices: + for index in range(block_dim): if not index in new_gf_struct[icrsh][block]: T[:, index] = 0.0 new_indices = [] - for index in indices: + for index in range(block_dim): if np.any(np.abs(T[index, :]) > 1.e-15): new_indices.append(index) new_gf_struct_transformed[icrsh][block] = new_indices @@ -558,6 +560,7 @@ class BlockStructure(object): gfs[icrsh][ind_sol[0]].append(ind_sol[1]) self.pick_gf_struct_solver(gfs) + # TODO! def map_gf_struct_solver(self, mapping): r""" Map the Green function structure from one struct to another. @@ -660,8 +663,8 @@ class BlockStructure(object): which space the structure should correspond to """ - def gf_function(indices): - return np.zeros((len(indices), len(indices)), dtype=dtype) + def gf_function(target_shape): + return np.zeros(target_shape, dtype=dtype) def block_function(name_list, block_list): d = dict() @@ -683,7 +686,7 @@ class BlockStructure(object): names = list(gf_struct[ish].keys()) blocks = [] for n in names: - G = gf_function(indices=gf_struct[ish][n], **kwargs) + G = gf_function(target_shape=(gf_struct[ish][n],gf_struct[ish][n]), **kwargs) blocks.append(G) G = block_function(name_list=names, block_list=blocks) return G @@ -766,7 +769,7 @@ class BlockStructure(object): for block, gf in G: assert block in gf_struct[ish],\ "block " + block + " not in struct (shell {})".format(ish) - assert list(gf.indices) == 2 * [list(map(str, gf_struct[ish][block]))],\ + assert (gf.target_shape) == (gf_struct[ish][block], gf_struct[ish][block]),\ "block " + block + \ " has wrong indices (shell {})".format(ish) else: @@ -776,7 +779,7 @@ class BlockStructure(object): for block, gf in list(G.items()): assert block in gf_struct[ish],\ "block " + block + " not in struct (shell {})".format(ish) - assert list(range(len(gf))) == 2 * [list(map(str, gf_struct[ish][block]))],\ + assert len(gf) == gf_struct[ish][block],\ "block " + block + \ " has wrong indices (shell {})".format(ish) @@ -936,8 +939,8 @@ class BlockStructure(object): block_mapping_from = G_struct.sumk_to_solver_block[ish_from] elif space_from == 'sumk': gf_struct_from = G_struct.gf_struct_sumk_dict[ish_from] - eff_trans_from = {block: np.eye(len(indices)) - for block, indices in G_struct.gf_struct_sumk[ish_from]} + eff_trans_from = {block: np.eye(block_dim) + for block, block_dim in G_struct.gf_struct_sumk[ish_from]} block_mapping_from = {b: [b] for b in gf_struct_from} else: raise Exception( @@ -949,8 +952,8 @@ class BlockStructure(object): block_mapping_to = self.solver_to_sumk_block[ish_to] elif space_to == 'sumk': gf_struct_to = self.gf_struct_sumk_dict[ish_to] - eff_trans_to = {block: np.eye(len(indices)) - for block, indices in self.gf_struct_sumk_list[ish_to]} + eff_trans_to = {block: np.eye(block_dim) + for block, block_dim in self.gf_struct_sumk_list[ish_to]} block_mapping_to = {b: b for b in gf_struct_to} else: raise Exception( @@ -1046,7 +1049,7 @@ class BlockStructure(object): self.solver_to_sumk_block.append({}) for frm,to in list(self.sumk_to_solver[ish].items()): if to[0] is not None: - self.gf_struct_solver[ish][frm[0]+'_'+str(frm[1])]=[0] + self.gf_struct_solver[ish][frm[0]+'_'+str(frm[1])]=1 self.sumk_to_solver[ish][frm]=(frm[0]+'_'+str(frm[1]),0) self.solver_to_sumk[ish][(frm[0]+'_'+str(frm[1]),0)]=frm self.solver_to_sumk_block[ish][frm[0]+'_'+str(frm[1])]=frm[0] From abf70b6ead1f406a2e226ae5aadcb1e4ed6596ea Mon Sep 17 00:00:00 2001 From: hschnait Date: Tue, 8 Mar 2022 17:38:50 +0100 Subject: [PATCH 04/14] Update map_gf_struct_solver function to new gf_struct convention --- python/triqs_dft_tools/block_structure.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/python/triqs_dft_tools/block_structure.py b/python/triqs_dft_tools/block_structure.py index d1e9c687..9b9b7a73 100644 --- a/python/triqs_dft_tools/block_structure.py +++ b/python/triqs_dft_tools/block_structure.py @@ -280,13 +280,9 @@ class BlockStructure(object): # zero out all the lines of the transformation that are # not included in gf_struct_solver - #TODO CHECK THIS! for iorb in range(self.gf_struct_sumk_dict[icrsh][block]): if self.sumk_to_solver[ish][(block, iorb)][0] is None: trans[icrsh][block][iorb, :] = 0.0 - # for iorb, norb in enumerate(self.gf_struct_sumk_dict[icrsh][block]): - # if self.sumk_to_solver[ish][(block, norb)][0] is None: - # trans[icrsh][block][iorb, :] = 0.0 return trans @property @@ -560,7 +556,6 @@ class BlockStructure(object): gfs[icrsh][ind_sol[0]].append(ind_sol[1]) self.pick_gf_struct_solver(gfs) - # TODO! def map_gf_struct_solver(self, mapping): r""" Map the Green function structure from one struct to another. @@ -611,6 +606,11 @@ class BlockStructure(object): for k in list(self.sumk_to_solver[ish].keys()): if not k in su2so: su2so[k] = (None, None) + + for new_block in gf_struct: + assert all(np.sort(gf_struct[new_block]) == list(range(len(gf_struct[new_block])))) ,\ + "New gf_struct does not have valid 0-based indices!" + gf_struct[new_block] = len(gf_struct[new_block]) self.adapt_deg_shells(gf_struct, ish) From cbeb26cc7f52a76c20cd969ed7f71bbf1a72f2a0 Mon Sep 17 00:00:00 2001 From: hschnait Date: Tue, 8 Mar 2022 17:47:36 +0100 Subject: [PATCH 05/14] Update trans_basis for new gf_struct convention. --- python/triqs_dft_tools/trans_basis.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/python/triqs_dft_tools/trans_basis.py b/python/triqs_dft_tools/trans_basis.py index 75dc0bf4..9d14c612 100644 --- a/python/triqs_dft_tools/trans_basis.py +++ b/python/triqs_dft_tools/trans_basis.py @@ -150,14 +150,14 @@ class TransBasis: # build a full GF gfrotated = BlockGf(name_block_generator=[(block, GfImFreq( - indices=inner, mesh=gf_to_rot.mesh)) for block, inner in self.SK.gf_struct_sumk[0]], make_copies=False) + target_shape=(block_dim, block_dim), mesh=gf_to_rot.mesh)) for block, block_dim in self.SK.gf_struct_sumk[0]], make_copies=False) # transform the CTQMC blocks to the full matrix: # ish is the index of the inequivalent shell corresponding to icrsh ish = self.SK.corr_to_inequiv[0] - for block, inner in self.gf_struct_solver[ish].items(): - for ind1 in inner: - for ind2 in inner: + for block, block_dim in self.gf_struct_solver[ish].items(): + for ind1 in range(block_dim): + for ind2 in range(block_dim): gfrotated[self.SK.solver_to_sumk_block[ish][block]][ ind1, ind2] << gf_to_rot[block][ind1, ind2] @@ -168,9 +168,9 @@ class TransBasis: gfreturn = gf_to_rot.copy() # Put back into CTQMC basis: - for block, inner in self.gf_struct_solver[ish].items(): - for ind1 in inner: - for ind2 in inner: + for block, block_dim in self.gf_struct_solver[ish].items(): + for ind1 in range(block_dim): + for ind2 in range(block_dim): gfreturn[block][ind1, ind2] << gfrotated[ self.SK.solver_to_sumk_block[0][block]][ind1, ind2] From 33200f9b8a80f56985b8026829e8d6cdc8f7671c Mon Sep 17 00:00:00 2001 From: hschnait Date: Tue, 8 Mar 2022 18:21:32 +0100 Subject: [PATCH 06/14] Add backwards-compatibility in constructor of block_strucutre --- python/triqs_dft_tools/block_structure.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/python/triqs_dft_tools/block_structure.py b/python/triqs_dft_tools/block_structure.py index 9b9b7a73..d9e42a66 100644 --- a/python/triqs_dft_tools/block_structure.py +++ b/python/triqs_dft_tools/block_structure.py @@ -120,8 +120,22 @@ class BlockStructure(object): deg_shells=None, corr_to_inequiv = None, transformation=None): + + # Ensure backwards-compatibility with pre-3.1.x gf_structs + if gf_struct_sumk != None: + for gf_struct in gf_struct_sumk: + for i, block in enumerate(gf_struct): + if isinstance(block[1], (list, np.ndarray)): + gf_struct[i] = (block[0], len(block[1])) + if gf_struct_solver != None: + for gf_struct in gf_struct_solver: + for block in gf_struct: + if isinstance(gf_struct[block], (list, np.ndarray)): + gf_struct[block] = len(gf_struct[block]) + self.gf_struct_sumk = gf_struct_sumk self.gf_struct_solver = gf_struct_solver + self.solver_to_sumk = solver_to_sumk self.sumk_to_solver = sumk_to_solver self.solver_to_sumk_block = solver_to_sumk_block From 660807fe251d658e632005cb3990b7960b605596 Mon Sep 17 00:00:00 2001 From: hschnait Date: Tue, 8 Mar 2022 18:22:57 +0100 Subject: [PATCH 07/14] Small bugfix in sumkdft --- python/triqs_dft_tools/sumk_dft.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/triqs_dft_tools/sumk_dft.py b/python/triqs_dft_tools/sumk_dft.py index 9978dd8b..263514c5 100644 --- a/python/triqs_dft_tools/sumk_dft.py +++ b/python/triqs_dft_tools/sumk_dft.py @@ -1119,7 +1119,7 @@ class SumkDFT(object): # transform G to the new structure full_structure = BlockStructure.full_structure( - [{sp:list(range(self.corr_shells[self.inequiv_to_corr[ish]]['dim'])) + [{sp:self.corr_shells[self.inequiv_to_corr[ish]]['dim'] for sp in self.spin_block_names[self.corr_shells[self.inequiv_to_corr[ish]]['SO']]} for ish in range(self.n_inequiv_shells)],self.corr_to_inequiv) G_transformed = [ From c8806ddda880c2f112bb115ea761e62e7f415cd9 Mon Sep 17 00:00:00 2001 From: hschnait Date: Tue, 8 Mar 2022 18:49:12 +0100 Subject: [PATCH 08/14] Updatye SumkDFT_Tools to new gf_struct --- python/triqs_dft_tools/sumk_dft_tools.py | 34 ++++++++++++------------ 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/python/triqs_dft_tools/sumk_dft_tools.py b/python/triqs_dft_tools/sumk_dft_tools.py index acf9e1c3..ff159a9d 100644 --- a/python/triqs_dft_tools/sumk_dft_tools.py +++ b/python/triqs_dft_tools/sumk_dft_tools.py @@ -97,8 +97,8 @@ class SumkDFTTools(SumkDFT): G_loc = [] for icrsh in range(self.n_corr_shells): spn = self.spin_block_names[self.corr_shells[icrsh]['SO']] - glist = [GfReFreq(indices=inner, window=(om_min, om_max), n_points=n_om) - for block, inner in self.gf_struct_sumk[icrsh]] + glist = [GfReFreq(target_shape=(block_dim, block_dim), window=(om_min, om_max), n_points=n_om) + for block, block_dim in self.gf_struct_sumk[icrsh]] G_loc.append( BlockGf(name_list=spn, block_list=glist, make_copies=False)) for icrsh in range(self.n_corr_shells): @@ -236,8 +236,8 @@ class SumkDFTTools(SumkDFT): n_local_orbs = self.proj_mat_csc.shape[2] gf_struct_parproj_all = [[(sp, list(range(n_local_orbs))) for sp in spn]] - glist_all = [GfReFreq(indices=inner, window=(om_min, om_max), n_points=n_om) - for block, inner in gf_struct_parproj_all[0]] + glist_all = [GfReFreq(target_shape=(block_dim, block_dim), window=(om_min, om_max), n_points=n_om) + for block, block_dim in gf_struct_parproj_all[0]] G_loc_all = BlockGf(name_list=spn, block_list=glist_all, make_copies=False) DOS = {sp: numpy.zeros([n_om], numpy.float_) @@ -364,11 +364,11 @@ class SumkDFTTools(SumkDFT): G_loc = [] spn = self.spin_block_names[self.SO] - gf_struct_parproj = [[(sp, list(range(self.shells[ish]['dim']))) for sp in spn] + gf_struct_parproj = [[(sp, self.shells[ish]['dim']) for sp in spn] for ish in range(self.n_shells)] for ish in range(self.n_shells): - glist = [GfReFreq(indices=inner, window=(om_min, om_max), n_points=n_om) - for block, inner in gf_struct_parproj[ish]] + glist = [GfReFreq(target_shape=(block_dim, block_dim), window=(om_min, om_max), n_points=n_om) + for block, block_dim in gf_struct_parproj[ish]] G_loc.append( BlockGf(name_list=spn, block_list=glist, make_copies=False)) for ish in range(self.n_shells): @@ -873,9 +873,9 @@ class SumkDFTTools(SumkDFT): if not ishell is None: gf_struct_parproj = [ - (sp, list(range(self.shells[ishell]['dim']))) for sp in spn] - G_loc = BlockGf(name_block_generator=[(block, GfReFreq(indices=inner, mesh=self.Sigma_imp_w[0].mesh)) - for block, inner in gf_struct_parproj], make_copies=False) + (sp, self.shells[ishell]['dim']) for sp in spn] + G_loc = BlockGf(name_block_generator=[(block, GfReFreq(target_shape=(block_dim, block_dim), mesh=self.Sigma_imp_w[0].mesh)) + for block, block_dim in gf_struct_parproj], make_copies=False) G_loc.zero() ikarray = numpy.array(list(range(self.n_k))) @@ -993,16 +993,16 @@ class SumkDFTTools(SumkDFT): for ish in range(self.n_shells)] for isp in range(len(spn))] # Set up G_loc - gf_struct_parproj = [[(sp, list(range(self.shells[ish]['dim']))) for sp in spn] + gf_struct_parproj = [[(sp, self.shells[ish]['dim']) for sp in spn] for ish in range(self.n_shells)] if with_Sigma: - G_loc = [BlockGf(name_block_generator=[(block, GfImFreq(indices=inner, mesh=self.Sigma_imp_iw[0].mesh)) - for block, inner in gf_struct_parproj[ish]], make_copies=False) + G_loc = [BlockGf(name_block_generator=[(block, GfImFreq(target_shape=(block_dim, block_dim), mesh=self.Sigma_imp_iw[0].mesh)) + for block, block_dim in gf_struct_parproj[ish]], make_copies=False) for ish in range(self.n_shells)] beta = self.Sigma_imp_iw[0].mesh.beta else: - G_loc = [BlockGf(name_block_generator=[(block, GfImFreq(indices=inner, beta=beta)) - for block, inner in gf_struct_parproj[ish]], make_copies=False) + G_loc = [BlockGf(name_block_generator=[(block, GfImFreq(target_shape=(block_dim, block_dim), beta=beta)) + for block, block_dim in gf_struct_parproj[ish]], make_copies=False) for ish in range(self.n_shells)] for ish in range(self.n_shells): G_loc[ish].zero() @@ -1227,8 +1227,8 @@ class SumkDFTTools(SumkDFT): for icrsh in range(self.n_corr_shells): Sigma_save = self.Sigma_imp_w[icrsh].copy() spn = self.spin_block_names[self.corr_shells[icrsh]['SO']] - glist = lambda: [GfReFreq(indices=inner, window=(self.omega[ - 0], self.omega[-1]), n_points=n_om) for block, inner in self.gf_struct_sumk[icrsh]] + glist = lambda: [GfReFreq(target_shape=(block_dim, block_dim), window=(self.omega[ + 0], self.omega[-1]), n_points=n_om) for block, block_dim in self.gf_struct_sumk[icrsh]] self.Sigma_imp_w[icrsh] = BlockGf( name_list=spn, block_list=glist(), make_copies=False) for i, g in self.Sigma_imp_w[icrsh]: From c2a53ab8358681677e0926874f01b9d6507ccdd7 Mon Sep 17 00:00:00 2001 From: hschnait Date: Tue, 8 Mar 2022 18:49:40 +0100 Subject: [PATCH 09/14] Update Unit-Tests for new gf_struct --- python/triqs_dft_tools/block_structure.py | 1 + 1 file changed, 1 insertion(+) diff --git a/python/triqs_dft_tools/block_structure.py b/python/triqs_dft_tools/block_structure.py index d9e42a66..858a4d14 100644 --- a/python/triqs_dft_tools/block_structure.py +++ b/python/triqs_dft_tools/block_structure.py @@ -122,6 +122,7 @@ class BlockStructure(object): transformation=None): # Ensure backwards-compatibility with pre-3.1.x gf_structs + # on second thought: would be better with gf_struct_flatten i guess... #TODO! if gf_struct_sumk != None: for gf_struct in gf_struct_sumk: for i, block in enumerate(gf_struct): From 507fe32308422ef9edb0ec29f6cae3ac12ca33da Mon Sep 17 00:00:00 2001 From: hschnait Date: Tue, 8 Mar 2022 18:50:17 +0100 Subject: [PATCH 10/14] Update Unit-Tests to new gfstruct --- test/python/analyse_block_structure_from_gf2.py | 8 ++++---- test/python/basis_transformation.py | 3 ++- test/python/blockstructure.py | 14 ++++++-------- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/test/python/analyse_block_structure_from_gf2.py b/test/python/analyse_block_structure_from_gf2.py index 25806815..c0faeb06 100644 --- a/test/python/analyse_block_structure_from_gf2.py +++ b/test/python/analyse_block_structure_from_gf2.py @@ -54,11 +54,11 @@ SK.symm_deg_gf(G_new_symm, 0) assert_block_gfs_are_close(G_new[0], G_new_symm) -assert SK.gf_struct_sumk == [[('ud', [0, 1, 2, 3, 4, 5, 6, 7, 8, 9])], [('ud', [0, 1, 2, 3, 4, 5, 6, 7, 8, 9])]],\ +assert SK.gf_struct_sumk == [[('ud', 10)], [('ud', 10)]],\ "wrong gf_struct_sumk" for i in range(5): assert 'ud_{}'.format(i) in SK.gf_struct_solver[0], "missing block" - assert SK.gf_struct_solver[0]['ud_{}'.format(i)] == list(range(2)), "wrong block size" + assert SK.gf_struct_solver[0]['ud_{}'.format(i)] == 2, "wrong block size" for i in range(10): assert SK.sumk_to_solver[0]['ud',i] == ('ud_{}'.format(i//2), i%2), "wrong mapping" @@ -98,11 +98,11 @@ G_new_symm = G_new[0].copy() SK.symm_deg_gf(G_new_symm, 0) assert_block_gfs_are_close(G_new[0], G_new_symm) -assert SK.gf_struct_sumk == [[('ud', [0, 1, 2, 3, 4, 5, 6, 7, 8, 9])], [('ud', [0, 1, 2, 3, 4, 5, 6, 7, 8, 9])]],\ +assert SK.gf_struct_sumk == [[('ud', 10)], [('ud', 10)]],\ "wrong gf_struct_sumk" for i in range(5): assert 'ud_{}'.format(i) in SK.gf_struct_solver[0], "missing block" - assert SK.gf_struct_solver[0]['ud_{}'.format(i)] == list(range(2)), "wrong block size" + assert SK.gf_struct_solver[0]['ud_{}'.format(i)] == 2, "wrong block size" for i in range(10): assert SK.sumk_to_solver[0]['ud',i] == ('ud_{}'.format(i//2), i%2), "wrong mapping" diff --git a/test/python/basis_transformation.py b/test/python/basis_transformation.py index 6905cdf5..a180b999 100644 --- a/test/python/basis_transformation.py +++ b/test/python/basis_transformation.py @@ -1,3 +1,4 @@ +from tkinter import W from triqs.utility.comparison_tests import * from triqs_dft_tools.sumk_dft import * import numpy as np @@ -92,7 +93,7 @@ BS.transformation = [{'up':np.array([[1,0,0],[0,1/np.sqrt(2),1/np.sqrt(2)],[0,1/ H3 = BS.convert_operator(h_int_slater(spin_names=['up','down'], orb_names=[0,1,2], U_matrix=U3x3, off_diag=True)) for op in H3: for c_op in op[0]: - assert(BS.gf_struct_solver_dict[0][c_op[1][0]][c_op[1][1]] is not None) # This crashes with a key error if the operator structure is not the solver structure + assert(BS.solver_to_sumk[0][(c_op[1][0], c_op[1][1])] is not None) # This crashes with a key error if the operator structure is not the solver structure U_trafod = transform_U_matrix(U3x3, BS.transformation[0]['up'].conjugate()) # The notorious .conjugate() H4 = h_int_slater(spin_names=['up','down'], orb_names=range(3), U_matrix=U_trafod, map_operator_structure=BS.sumk_to_solver[0]) diff --git a/test/python/blockstructure.py b/test/python/blockstructure.py index ed34bfe3..d902f757 100644 --- a/test/python/blockstructure.py +++ b/test/python/blockstructure.py @@ -174,11 +174,9 @@ cmp(m2, # check full_structure full = BlockStructure.full_structure( - [{'up_0': [0, 1], 'up_1': [0], 'down_1': [0], 'down_0': [0, 1]}], None) + [{'up_0': 2, 'up_1': 1, 'down_1': 1, 'down_0': 2}], None) -print(original_bs.gf_struct_sumk[0]) -print(gf_struct_flatten(original_bs.gf_struct_sumk[0])) -G_sumk = BlockGf(mesh=G1.mesh, gf_struct=gf_struct_flatten(original_bs.gf_struct_sumk[0])) +G_sumk = BlockGf(mesh=G1.mesh, gf_struct=original_bs.gf_struct_sumk[0]) for i in range(3): G_sumk['up'][i, i] << SemiCircular(1 if i < 2 else 2) G_sumk['down'][i, i] << SemiCircular(4 if i < 2 else 3) @@ -204,13 +202,13 @@ G_bT = transformed_bs.convert_gf(G_T, None, space_from='sumk', assert_block_gfs_are_close(G1, G_bT) assert original_bs.gf_struct_sumk_list ==\ - [[('up', [0, 1, 2]), ('down', [0, 1, 2])]] + [[('up', 3), ('down', 3)]] assert original_bs.gf_struct_solver_dict ==\ - [{'up_0': [0, 1], 'up_1': [0], 'down_1': [0], 'down_0': [0, 1]}] + [{'up_0': 2, 'up_1': 1, 'down_1': 1, 'down_0': 2}] assert original_bs.gf_struct_sumk_dict ==\ - [{'down': [0, 1, 2], 'up': [0, 1, 2]}] + [{'down': 3, 'up': 3}] assert original_bs.gf_struct_solver_list ==\ - [[('down_0', [0, 1]), ('down_1', [0]), ('up_0', [0, 1]), ('up_1', [0])]] + [[('down_0', 2), ('down_1', 1), ('up_0', 2), ('up_1', 1)]] # check __eq__ assert full == full, 'equality not correct (equal structures not equal)' From 4c44dbe2af650bfcedcb88f55f3b2ae81ff02c70 Mon Sep 17 00:00:00 2001 From: Hermann Schnait Date: Wed, 9 Mar 2022 10:07:10 +0100 Subject: [PATCH 11/14] Remove tkinter import (don't know how this ended up in the code) --- test/python/basis_transformation.py | 1 - 1 file changed, 1 deletion(-) diff --git a/test/python/basis_transformation.py b/test/python/basis_transformation.py index a180b999..25d93dcf 100644 --- a/test/python/basis_transformation.py +++ b/test/python/basis_transformation.py @@ -1,4 +1,3 @@ -from tkinter import W from triqs.utility.comparison_tests import * from triqs_dft_tools.sumk_dft import * import numpy as np From 23d689f8f7c5a398c0e541dcbcdca37d03b16b72 Mon Sep 17 00:00:00 2001 From: Hermann Schnait Date: Wed, 9 Mar 2022 12:23:26 +0100 Subject: [PATCH 12/14] Issue a Warning when old gf_struct is provided --- python/triqs_dft_tools/block_structure.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/python/triqs_dft_tools/block_structure.py b/python/triqs_dft_tools/block_structure.py index 858a4d14..4b9704d3 100644 --- a/python/triqs_dft_tools/block_structure.py +++ b/python/triqs_dft_tools/block_structure.py @@ -122,18 +122,22 @@ class BlockStructure(object): transformation=None): # Ensure backwards-compatibility with pre-3.1.x gf_structs - # on second thought: would be better with gf_struct_flatten i guess... #TODO! + show_gf_struct_warning = False if gf_struct_sumk != None: for gf_struct in gf_struct_sumk: for i, block in enumerate(gf_struct): if isinstance(block[1], (list, np.ndarray)): gf_struct[i] = (block[0], len(block[1])) + show_gf_struct_warning = True if gf_struct_solver != None: for gf_struct in gf_struct_solver: for block in gf_struct: if isinstance(gf_struct[block], (list, np.ndarray)): gf_struct[block] = len(gf_struct[block]) - + show_gf_struct_warning = True + if show_gf_struct_warning: + warn('Old (pre 3.1.x) form of gf_struct provided! The structure will be updated to the new convention!') + self.gf_struct_sumk = gf_struct_sumk self.gf_struct_solver = gf_struct_solver From d28fe3c1efc98d0dbdf6798e5a93dd5c38f0f17c Mon Sep 17 00:00:00 2001 From: Hermann Schnait Date: Wed, 9 Mar 2022 12:23:54 +0100 Subject: [PATCH 13/14] Update Changelog --- doc/ChangeLog.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/doc/ChangeLog.md b/doc/ChangeLog.md index 2784b12c..b4c2ce17 100644 --- a/doc/ChangeLog.md +++ b/doc/ChangeLog.md @@ -22,6 +22,13 @@ DFTTools Version 3.1.0 is a release that * update documentation of W90 Converter * bugfix: This fix makes the function find_rot_mat() safer to use in case there are errors in finding the correct mapping. The converter will now abort if the agreement in mapping is below a user-definable threshold. +### Change in gf_struct +* In line with TRIQS 3.1.x, the form of the Green's function's structure (`gf_struct`) has been modified +* Instead of `gf_struct = [("up", [0, 1]), ("down", [0, 1])]`, the new convention uses `gf_struct = [("up", 2), ("down", 2)]` +* This modifies the form of `gf_struct_solver` (and `sumk`) in `block_structure` and `SumkDFT` as well. +* Backwards-compatibility with old, stored `block_structure` objects is given, however a warning is issued. +* A helper-function `block_structure.gf_struct_flatten(...)` is provided to manually bring `gf_struct`s to the new form. + ### Documentation * change to read the docs sphinx theme * clean up various doc files From 320b2d2dfd8d85aa23b024c68ec9b172b26d4f67 Mon Sep 17 00:00:00 2001 From: Alexander Hampel Date: Wed, 9 Mar 2022 09:15:10 -0500 Subject: [PATCH 14/14] remove gf_struct_flatten function and replace with triqs version --- doc/ChangeLog.md | 4 +- doc/tutorials/images_scripts/nio.py | 19 +++-- doc/tutorials/images_scripts/nio_csc.py | 87 +++++++++++------------ python/triqs_dft_tools/block_structure.py | 44 +----------- test/python/blockstructure.py | 2 +- 5 files changed, 57 insertions(+), 99 deletions(-) diff --git a/doc/ChangeLog.md b/doc/ChangeLog.md index b4c2ce17..4b3e0a89 100644 --- a/doc/ChangeLog.md +++ b/doc/ChangeLog.md @@ -23,11 +23,11 @@ DFTTools Version 3.1.0 is a release that * bugfix: This fix makes the function find_rot_mat() safer to use in case there are errors in finding the correct mapping. The converter will now abort if the agreement in mapping is below a user-definable threshold. ### Change in gf_struct -* In line with TRIQS 3.1.x, the form of the Green's function's structure (`gf_struct`) has been modified +* In line with TRIQS 3.1.x, the form of the Green's function's structure (`gf_struct`) has been modified (see [triqs changelog](https://triqs.github.io/triqs/latest/ChangeLog.html#change-in-gf-struct-objects) for more information) * Instead of `gf_struct = [("up", [0, 1]), ("down", [0, 1])]`, the new convention uses `gf_struct = [("up", 2), ("down", 2)]` * This modifies the form of `gf_struct_solver` (and `sumk`) in `block_structure` and `SumkDFT` as well. * Backwards-compatibility with old, stored `block_structure` objects is given, however a warning is issued. -* A helper-function `block_structure.gf_struct_flatten(...)` is provided to manually bring `gf_struct`s to the new form. +* A helper-function `triqs.gf.block_gf.fix_gf_struct_type(gf_struct_old)` is provided in triqs to manually bring `gf_struct`s to the new form. ### Documentation * change to read the docs sphinx theme diff --git a/doc/tutorials/images_scripts/nio.py b/doc/tutorials/images_scripts/nio.py index d93d399b..88268fb3 100644 --- a/doc/tutorials/images_scripts/nio.py +++ b/doc/tutorials/images_scripts/nio.py @@ -6,7 +6,6 @@ from triqs.gf import * import sys, triqs.version as triqs_version from triqs_dft_tools.sumk_dft import * from triqs_dft_tools.sumk_dft_tools import * -from triqs_dft_tools.block_structure import gf_struct_flatten from triqs.operators.util.hamiltonians import * from triqs.operators.util.U_matrix import * from triqs_cthyb import * @@ -20,8 +19,8 @@ filename = 'nio' SK = SumkDFT(hdf_file = filename+'.h5', use_dft_blocks = False) -beta = 5.0 - +beta = 5.0 + Sigma = SK.block_structure.create_gf(beta=beta) SK.put_Sigma([Sigma]) G = SK.extract_G_loc() @@ -41,7 +40,7 @@ spin_names = ['up','down'] orb_names = [i for i in range(0,n_orb)] #gf_struct = set_operator_structure(spin_names, orb_names, orb_hyb) -gf_struct = gf_struct_flatten(SK.gf_struct_solver[0]) +gf_struct = SK.gf_struct_solver_list[0] mpi.report('Sumk to Solver: %s'%SK.sumk_to_solver) mpi.report('GF struct sumk: %s'%SK.gf_struct_sumk) mpi.report('GF struct solver: %s'%SK.gf_struct_solver) @@ -49,7 +48,7 @@ mpi.report('GF struct solver: %s'%SK.gf_struct_solver) S = Solver(beta=beta, gf_struct=gf_struct) # Construct the Hamiltonian and save it in Hamiltonian_store.txt -H = Operator() +H = Operator() U = 8.0 J = 1.0 @@ -130,14 +129,14 @@ mpi.report('%s DMFT cycles requested. Starting with iteration %s.'%(n_iterations # The infamous DMFT self consistency cycle for it in range(iteration_offset, iteration_offset + n_iterations): - + mpi.report('Doing iteration: %s'%it) - + # Get G0 S.G0_iw << inverse(S.Sigma_iw + inverse(S.G_iw)) # Solve the impurity problem S.solve(h_int = H, **p) - if mpi.is_master_node(): + if mpi.is_master_node(): ar['DMFT_input']['Iterations']['solver_dict_it'+str(it)] = p ar['DMFT_results']['Iterations']['Gimp_it'+str(it)] = S.G_iw ar['DMFT_results']['Iterations']['Gtau_it'+str(it)] = S.G_tau @@ -150,13 +149,13 @@ for it in range(iteration_offset, iteration_offset + n_iterations): SK.put_Sigma(Sigma_imp=[S.Sigma_iw]) SK.calc_mu(precision=0.01) S.G_iw << SK.extract_G_loc()[0] - + # print densities for sig,gf in S.G_iw: mpi.report("Orbital %s density: %.6f"%(sig,dm[sig][0,0])) mpi.report('Total charge of Gloc : %.6f'%S.G_iw.total_density()) - if mpi.is_master_node(): + if mpi.is_master_node(): ar['DMFT_results']['iteration_count'] = it ar['DMFT_results']['Iterations']['Sigma_it'+str(it)] = S.Sigma_iw ar['DMFT_results']['Iterations']['Gloc_it'+str(it)] = S.G_iw diff --git a/doc/tutorials/images_scripts/nio_csc.py b/doc/tutorials/images_scripts/nio_csc.py index 329d5a89..be573411 100644 --- a/doc/tutorials/images_scripts/nio_csc.py +++ b/doc/tutorials/images_scripts/nio_csc.py @@ -6,7 +6,6 @@ from triqs.gf import * import sys, triqs.version as triqs_version from triqs_dft_tools.sumk_dft import * from triqs_dft_tools.sumk_dft_tools import * -from triqs_dft_tools.block_structure import gf_struct_flatten from triqs.operators.util.hamiltonians import * from triqs.operators.util.U_matrix import * from triqs_cthyb import * @@ -21,14 +20,14 @@ warnings.filterwarnings("ignore", category=FutureWarning) def dmft_cycle(): filename = 'nio' - + Converter = VaspConverter(filename=filename) Converter.convert_dft_input() - + SK = SumkDFT(hdf_file = filename+'.h5', use_dft_blocks = False) - - beta = 5.0 - + + beta = 5.0 + Sigma = SK.block_structure.create_gf(beta=beta) SK.put_Sigma([Sigma]) G = SK.extract_G_loc() @@ -40,38 +39,38 @@ def dmft_cycle(): mpi.report('block {0:d} consists of orbitals:'.format(iblock)) for keys in list(SK.deg_shells[i_sh][iblock].keys()): mpi.report(' '+keys) - + # Setup CTQMC Solver - + n_orb = SK.corr_shells[0]['dim'] spin_names = ['up','down'] orb_names = [i for i in range(0,n_orb)] - + #gf_struct = set_operator_structure(spin_names, orb_names, orb_hyb) - gf_struct = SK.gf_struct_solver[0] + gf_struct = SK.gf_struct_solver_list[0] mpi.report('Sumk to Solver: %s'%SK.sumk_to_solver) mpi.report('GF struct sumk: %s'%SK.gf_struct_sumk) mpi.report('GF struct solver: %s'%SK.gf_struct_solver) - + S = Solver(beta=beta, gf_struct=gf_struct) - + # Construct the Hamiltonian and save it in Hamiltonian_store.txt - H = Operator() + H = Operator() U = 8.0 J = 1.0 - - + + U_sph = U_matrix(l=2, U_int=U, J_hund=J) U_cubic = transform_U_matrix(U_sph, spherical_to_cubic(l=2, convention='')) Umat, Upmat = reduce_4index_to_2index(U_cubic) - + H = h_int_density(spin_names, orb_names, map_operator_structure=SK.sumk_to_solver[0], U=Umat, Uprime=Upmat) - + # Print some information on the master node mpi.report('Greens function structure is: %s '%gf_struct) mpi.report('U Matrix set to:\n%s'%Umat) mpi.report('Up Matrix set to:\n%s'%Upmat) - + # Parameters for the CTQMC Solver p = {} p["max_time"] = -1 @@ -84,14 +83,14 @@ def dmft_cycle(): p["fit_min_n"] = 30 p["fit_max_n"] = 50 p["perform_tail_fit"] = True - + # Double Counting: 0 FLL, 1 Held, 2 AMF DC_type = 0 DC_value = 59.0 - + # Prepare hdf file and and check for previous iterations n_iterations = 1 - + iteration_offset = 0 if mpi.is_master_node(): ar = HDFArchive(filename+'.h5','a') @@ -119,33 +118,33 @@ def dmft_cycle(): SK.dc_imp = mpi.bcast(SK.dc_imp) SK.dc_energ = mpi.bcast(SK.dc_energ) SK.chemical_potential = mpi.bcast(SK.chemical_potential) - + # Calc the first G0 SK.symm_deg_gf(S.Sigma_iw, ish=0) SK.put_Sigma(Sigma_imp = [S.Sigma_iw]) SK.calc_mu(precision=0.01) S.G_iw << SK.extract_G_loc()[0] SK.symm_deg_gf(S.G_iw, ish=0) - + #Init the DC term and the self-energy if no previous iteration was found if iteration_offset == 0: dm = S.G_iw.density() SK.calc_dc(dm, U_interact=U, J_hund=J, orb=0, use_dc_formula=DC_type,use_dc_value=DC_value) S.Sigma_iw << SK.dc_imp[0]['up'][0,0] - + mpi.report('%s DMFT cycles requested. Starting with iteration %s.'%(n_iterations,iteration_offset)) - - - + + + # The infamous DMFT self consistency cycle for it in range(iteration_offset, iteration_offset + n_iterations): mpi.report('Doing iteration: %s'%it) - + # Get G0 S.G0_iw << inverse(S.Sigma_iw + inverse(S.G_iw)) # Solve the impurity problem S.solve(h_int = H, **p) - if mpi.is_master_node(): + if mpi.is_master_node(): ar['DMFT_input']['Iterations']['solver_dict_it'+str(it)] = p ar['DMFT_results']['Iterations']['Gimp_it'+str(it)] = S.G_iw ar['DMFT_results']['Iterations']['Gtau_it'+str(it)] = S.G_tau @@ -158,13 +157,13 @@ def dmft_cycle(): SK.put_Sigma(Sigma_imp=[S.Sigma_iw]) SK.calc_mu(precision=0.01) S.G_iw << SK.extract_G_loc()[0] - + # print densities for sig,gf in S.G_iw: mpi.report("Orbital %s density: %.6f"%(sig,dm[sig][0,0])) mpi.report('Total charge of Gloc : %.6f'%S.G_iw.total_density()) - - if mpi.is_master_node(): + + if mpi.is_master_node(): ar['DMFT_results']['iteration_count'] = it ar['DMFT_results']['Iterations']['Sigma_it'+str(it)] = S.Sigma_iw ar['DMFT_results']['Iterations']['Gloc_it'+str(it)] = S.G_iw @@ -172,31 +171,31 @@ def dmft_cycle(): ar['DMFT_results']['Iterations']['dc_imp'+str(it)] = SK.dc_imp ar['DMFT_results']['Iterations']['dc_energ'+str(it)] = SK.dc_energ ar['DMFT_results']['Iterations']['chemical_potential'+str(it)] = SK.chemical_potential - - - - + + + + if mpi.is_master_node(): print('calculating mu...') SK.chemical_potential = SK.calc_mu( precision = 0.000001 ) - + if mpi.is_master_node(): print('calculating GAMMA') SK.calc_density_correction(dm_type='vasp') - + if mpi.is_master_node(): print('calculating energy corrections') - + correnerg = 0.5 * (S.G_iw * S.Sigma_iw).total_density() - + dm = S.G_iw.density() # compute the density matrix of the impurity problem SK.calc_dc(dm, U_interact=U, J_hund=J, orb=0, use_dc_formula=DC_type,use_dc_value=DC_value) dc_energ = SK.dc_energ[0] - - if mpi.is_master_node(): + + if mpi.is_master_node(): ar['DMFT_results']['Iterations']['corr_energy_it'+str(it)] = correnerg ar['DMFT_results']['Iterations']['dc_energy_it'+str(it)] = dc_energ - + if mpi.is_master_node(): del ar - + return correnerg, dc_energ diff --git a/python/triqs_dft_tools/block_structure.py b/python/triqs_dft_tools/block_structure.py index 4b9704d3..789b4fc4 100644 --- a/python/triqs_dft_tools/block_structure.py +++ b/python/triqs_dft_tools/block_structure.py @@ -120,7 +120,7 @@ class BlockStructure(object): deg_shells=None, corr_to_inequiv = None, transformation=None): - + # Ensure backwards-compatibility with pre-3.1.x gf_structs show_gf_struct_warning = False if gf_struct_sumk != None: @@ -625,7 +625,7 @@ class BlockStructure(object): for k in list(self.sumk_to_solver[ish].keys()): if not k in su2so: su2so[k] = (None, None) - + for new_block in gf_struct: assert all(np.sort(gf_struct[new_block]) == list(range(len(gf_struct[new_block])))) ,\ "New gf_struct does not have valid 0-based indices!" @@ -1190,45 +1190,5 @@ class BlockStructure(object): s += str(self.transformation) return s -def gf_struct_flatten(gf_struct): - ''' - flattens gf_struct objecti - - input gf_struct can looks like this: - - [('up', [0, 1, 2]), ('down', [0, 1, 2])] - - and will be returned as - - [('up', 3), ('down', 3)] - - Same for dict but replacing the values. This is for compatibility with the upcoming triqs releases. - - Parameters - ---------- - gf_struct: list of tuple or dict representing the Gf structure - __Returns:__ - gf_struct_flat: flattens the values of the dict or the tuple representing the Gf indices by replacing them with the len of the list of indices - - ''' - - if isinstance(gf_struct, list): - # create a copy of the original list - gf_struct_flat = gf_struct.copy() - for idx, block in enumerate(gf_struct_flat): - # exchange list of indices with length of list - gf_struct_flat[idx] = (block[0], len(block[1])) - elif isinstance(gf_struct, dict): - # create a copy of the original dict - gf_struct_flat = dict(gf_struct) - for key, value in gf_struct_flat.items(): - # exchange list of indices with length of list - gf_struct_flat[key] = len(value) - else: - raise Exception('gf_struct input needs to be list or dict') - - - return gf_struct_flat - from h5.formats import register_class register_class(BlockStructure) diff --git a/test/python/blockstructure.py b/test/python/blockstructure.py index d902f757..c0e2fedb 100644 --- a/test/python/blockstructure.py +++ b/test/python/blockstructure.py @@ -3,7 +3,7 @@ from triqs.utility.h5diff import h5diff, compare, failures from triqs.gf import * from triqs.utility.comparison_tests import assert_block_gfs_are_close from scipy.linalg import expm -from triqs_dft_tools.block_structure import BlockStructure, gf_struct_flatten +from triqs_dft_tools.block_structure import BlockStructure import numpy as np