# version. # # TRIQS is distributed in the hope that it will be useful, but WITHOUT ANY # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more # details. # # You should have received a copy of the GNU General Public License along with # TRIQS. If not, see <http://www.gnu.org/licenses/>. # ################################################################################ class Dummy(object): """ Dummy class that is writable to a HDFArchive. """ def __init__(self): pass def __reduce_to_dict__(self): return self.__dict__ @classmethod def __factory_from_dict__(cls, name, d): ret = cls() ret.__dict__.update(d) return ret from pytriqs.archive.hdf_archive_schemes import register_class register_class(Dummy)
def invert(self): """Inverse all the blocks inplace""" self.__check_attr("invert") for i,g in self: g.invert() def inverse(self): """Return inverse of the BlockGf""" self.__check_attr("inverse") return self.__class__( name_block_generator = [ (n, g.inverse()) for n,g in self], make_copies=False) def transpose(self): """Return transpose of the BlockGf""" self.__check_attr("transpose") return self.__class__( name_block_generator = [ (n, g.transpose()) for n,g in self], make_copies=False) def conjugate(self): """Return conjugate of the BlockGf""" self.__check_attr("conjugate") return self.__class__( name_block_generator = [ (n, g.conjugate()) for n,g in self], make_copies=False) # def make_real_in_tau(self): # """ """ # self.__check_attr("make_real_in_tau") # return self.__class__( name_block_generator = [ (n, g.make_real_in_tau()) for n,g in self], make_copies=False) #--------------------------------------------------------- from pytriqs.archive.hdf_archive_schemes import register_class register_class (BlockGf)
self._constant_shift = dict.fromkeys(set(self.S_iw.indices), constant_shift) self._calculate_Gaux_iw() def _calculate_Gaux_iw(self): def _calculate_gaux_iw(g): g[1] << Omega + self._constant_shift[g[0]] - g[1] g[1].invert() self.Gaux_iw = self.S_iw.copy() map(_calculate_gaux_iw, self.Gaux_iw) if self._BlockGf else _calculate_gaux_iw( ('0', self.Gaux_iw)) def _calculate_S_w(self): def _calculate_s_w(s): s[1] << Omega + self._constant_shift[s[0]] - inverse(s[1]) self.S_w = self.Gaux_w.copy() map(_calculate_s_w, self.S_w) if self._BlockGf else _calculate_s_w( ('0', self.S_w)) try: from pytriqs.archive.hdf_archive_schemes import register_class register_class(InversionSigmaContinuator) register_class(DirectSigmaContinuator) except ImportError: # notriqs pass
return "MeshProduct of :" + ', '.join(repr(x) for x in self._mlist) def __str__(self): """ """ return ', '.join(str(x) for x in self._mlist) #----------------------------- IO ----------------------------------- def __reduce__(self): return call_factory_from_dict, (self.__class__, "", self.__reduce_to_dict__()) def __reduce_to_dict__(self): return dict( ('MeshComponent%s' % i, m) for i, m in enumerate(self._mlist)) # @classmethod # def __factory_from_dict__(cls, l): # return cls(*l) @classmethod def __factory_from_dict__(cls, name, d): return cls(*(d['MeshComponent%s' % i] for i in range(len(d)))) #.values()) #--------------------------------------------------------- from pytriqs.archive.hdf_archive_schemes import register_class register_class(MeshProduct)
def __check_attr(self,ATTR) : if not hasattr(self._first(), ATTR ) : raise RuntimeError, "The blocks of this Green Function do not possess the %s method"%ATTR def invert(self) : """Inverse all the blocks""" self.__check_attr("invert") for i,g in self : g.invert() def delta(self) : """Compute delta from G0""" self.__check_attr("delta") return self.__class__( name_block_generator = [ (n, g.delta()) for n,g in self], make_copies=False) def transpose(self): """Transpose of the BlockGf""" self.__check_attr("transpose") return self.__class__( name_block_generator = [ (n, g.transpose()) for n,g in self], make_copies=False) def conjugate(self): """Conjugate of the BlockGf""" self.__check_attr("conjugate") return self.__class__( name_block_generator = [ (n, g.conjugate()) for n,g in self], make_copies=False) #--------------------------------------------------------- from pytriqs.archive.hdf_archive_schemes import register_class register_class (BlockGf)
# literal_eval is a saje alternative to eval d[ish][literal_eval(k)] = literal_eval(v) return d D['solver_to_sumk'] = reconstruct_mapping(D['solver_to_sumk']) D['sumk_to_solver'] = reconstruct_mapping(D['sumk_to_solver']) return cls(**D) def __str__(self): s = '' s += "gf_struct_sumk " + str(self.gf_struct_sumk) + '\n' s += "gf_struct_solver " + str(self.gf_struct_solver) + '\n' s += "solver_to_sumk_block " + str(self.solver_to_sumk_block) + '\n' for el in ['solver_to_sumk', 'sumk_to_solver']: s += el + '\n' element = getattr(self, el) for ish in range(len(element)): s += ' shell ' + str(ish) + '\n' def keyfun(el): return '{}_{:05d}'.format(el[0], el[1]) keys = sorted(element[ish].keys(), key=keyfun) for k in keys: s += ' ' + str(k) + str(element[ish][k]) + '\n' return s from pytriqs.archive.hdf_archive_schemes import register_class register_class(BlockStructure)
for ish in range(len(mapping)): d.append({}) for k,v in mapping[ish].iteritems(): # literal_eval is a saje alternative to eval d[ish][literal_eval(k)] = literal_eval(v) return d D['solver_to_sumk']=reconstruct_mapping(D['solver_to_sumk']) D['sumk_to_solver']=reconstruct_mapping(D['sumk_to_solver']) return cls(**D) def __str__(self): s='' s+= "gf_struct_sumk "+str( self.gf_struct_sumk)+'\n' s+= "gf_struct_solver "+str(self.gf_struct_solver)+'\n' s+= "solver_to_sumk_block "+str(self.solver_to_sumk_block)+'\n' for el in ['solver_to_sumk','sumk_to_solver']: s+=el+'\n' element=getattr(self,el) for ish in range(len(element)): s+=' shell '+str(ish)+'\n' def keyfun(el): return '{}_{:05d}'.format(el[0],el[1]) keys = sorted(element[ish].keys(),key=keyfun) for k in keys: s+=' '+str(k)+str(element[ish][k])+'\n' return s from pytriqs.archive.hdf_archive_schemes import register_class register_class(BlockStructure)
def __repr__(self): """ """ return "MeshProduct of :" + ', '.join(repr(x) for x in self._mlist) def __str__(self): """ """ return ', '.join(str(x) for x in self._mlist) #----------------------------- IO ----------------------------------- def __reduce__(self): return call_factory_from_dict, (self.__class__, "", self.__reduce_to_dict__()) def __reduce_to_dict__(self): return dict (('MeshComponent%s'%i, m) for i,m in enumerate(self._mlist)) # @classmethod # def __factory_from_dict__(cls, l): # return cls(*l) @classmethod def __factory_from_dict__(cls, name, d): return cls(*(d['MeshComponent%s'%i] for i in range(len(d)))) #.values()) #--------------------------------------------------------- from pytriqs.archive.hdf_archive_schemes import register_class register_class (MeshProduct)
def __reduce_to_dict__(self) : return dict( [ (_my_str(n),v) for (n,v) in enumerate (self.ob)]) @classmethod def __factory_from_dict__(cls, name, D) : return tuple([x for (n,x) in sorted(D.items())]) class PythonDictWrap: def __init__(self,ob) : self.ob = ob def __reduce_to_dict__(self) : return dict( [ (str(n),v) for (n,v) in self.ob.items()]) @classmethod def __factory_from_dict__(cls, name, D) : return dict([(n,x) for (n,x) in D.items()]) register_class (PythonListWrap) register_class (PythonTupleWrap) register_class (PythonDictWrap) # ------------------------------------------- # # A view of a subgroup of the archive # # -------------------------------------------- class HDFArchiveGroup (HDFArchiveGroupBasicLayer) : """ """ _wrappedType = { type([]) : PythonListWrap, type(()) : PythonTupleWrap, type({}) : PythonDictWrap} _MaxLengthKey = 500
def get_my_name(self): ans = [] frame = inspect.currentframe().f_back tmp = dict(frame.f_globals.items() + frame.f_locals.items()) for k, var in tmp.items(): if isinstance(var, self.__class__): if hash(self) == hash(var): ans.append(k) return ans # -- Register ParameterCollection in Triqs hdf_archive_schemes from pytriqs.archive.hdf_archive_schemes import register_class register_class(ParameterCollection) # ---------------------------------------------------------------------- class ParameterCollections(object): def __init__(self, objects=[]): self.objects = objects def append(self, obj): self.objects.append(obj) def sort_on(self, attr): val = self.getattr_from_objects(attr) sidx = np.argsort(val) self.set_sorted_order(sidx)
@property def indicesL(self): warnings.warn("g.indicesL is deprecated. Use g.indices[0] instead") return self.indices.data[0] @property def indicesR(self): warnings.warn("g.indicesR is deprecated. Use g.indices[1] instead") return self.indices.data[1] #--------------------------------------------------------- from pytriqs.archive.hdf_archive_schemes import register_class, register_backward_compatibility_method register_class(Gf) # A backward compatility function def bckwd(hdf_scheme): # we know scheme is of the form GfM1_x_M2_s/tv3 m, t = hdf_scheme[2:], '' # get rid of Gf for suffix in ['_s', 'Tv3', 'Tv4']: if m.endswith(suffix): m, t = m[:-len(suffix)], suffix break return {'mesh': 'Mesh' + m, 'indices': 'GfIndices'} register_backward_compatibility_method("Gf", "Gf", bckwd)
""" assert callable(function), "function is not callable" self.function,self.x_min,self.x_max = function,x_min,x_max try : e = function(0.001) len(numpy.array(e).shape) ==1 except : raise RuntimeError , "Value of the function must be a 1d-array" self.__f(n_pts) # compute arrays DOS.__init__(self,self.eps,self.rho,name) #------------------------------------------------------------- def __reduce__(self) : return self.__class__, (self.function,self.x_min, self.x_max, len(self.eps), self.name) #------------------------------------------------------------- def __f(self,N) : r = (self.x_max - self.x_min)/float(N-1) self.eps = numpy.array( [self.x_min + r* i for i in range(N) ] ) self.rho = numpy.array( [self.function(e) for e in self.eps]) #----------------------------------------------------- # Register the class for HDFArchive #----------------------------------------------------- from pytriqs.archive.hdf_archive_schemes import register_class register_class (DOS)
assert callable(function), "function is not callable" self.function, self.x_min, self.x_max = function, x_min, x_max try: e = function(0.001) len(numpy.array(e).shape) == 1 except: raise RuntimeError, "Value of the function must be a 1d-array" self.__f(n_pts) # compute arrays DOS.__init__(self, self.eps, self.rho, name) #------------------------------------------------------------- def __reduce__(self): return self.__class__, (self.function, self.x_min, self.x_max, len(self.eps), self.name) #------------------------------------------------------------- def __f(self, N): r = (self.x_max - self.x_min) / float(N - 1) self.eps = numpy.array([self.x_min + r * i for i in range(N)]) self.rho = numpy.array([self.function(e) for e in self.eps]) #----------------------------------------------------- # Register the class for HDFArchive #----------------------------------------------------- from pytriqs.archive.hdf_archive_schemes import register_class register_class(DOS)
return tuple(x for n, x in sorted([(int(n), x) for n, x in D.items()])) class PythonDictWrap: def __init__(self, ob): self.ob = ob def __reduce_to_dict__(self): return {str(n): v for n, v in self.ob.items()} @classmethod def __factory_from_dict__(cls, name, D): return {n: x for n, x in D.items()} register_class(PythonListWrap) register_class(PythonTupleWrap) register_class(PythonDictWrap) # ------------------------------------------- # # A view of a subgroup of the archive # # -------------------------------------------- class HDFArchiveGroup(HDFArchiveGroupBasicLayer): """ """ _wrappedType = { list: PythonListWrap,
np.exp( np.polyval(self['linefit_params'][0], np.log(maxent_result.alpha))), np.exp( np.polyval(self['linefit_params'][1], np.log(maxent_result.alpha))))), dict(label=r'linefit {}'.format(self['name']), x_label=r'$\alpha$', y_label=r'linefit', log_x=True, log_y=True)) try: from pytriqs.archive.hdf_archive_schemes import register_class register_class(AnalyzerResult) except ImportError: # notriqs pass class Analyzer(object): r""" Analyzer base class The base class for analyzing the values :math:`A_{\alpha}` and getting the one true (:math:`\alpha`-independent) solution from the data. """ def __init__(self, name=None, **kwargs): if name is None: self.name = self.__class__.__name__ else: self.name = name
return self._zero_elements @saved def use_hermiticity(self): return self._use_hermiticity @saved def complex_elements(self): return self._complex_elements @property def data(self): """ Get a :py:class:`.MaxEntResultData` data object that can be saved to h5-files. """ # in order to make sure that everything is saved try: d = self.__reduce_to_dict__() return MaxEntResultData.__factory_from_dict__( "MaxEntResultData", d) except AttributeError as e: raise Exception(e) try: from pytriqs.archive.hdf_archive_schemes import register_class register_class(MaxEntResultData) except ImportError: # notriqs pass