2020from .module import trace
2121from .module import convolve_ppsc as conv
2222
23+ from .ase .utils .timing import Timer , timer
24+
2325
2426def is_root ():
2527 return mpi .is_master_node ()
@@ -34,7 +36,7 @@ def scatter_array_over_ranks(arr):
3436
3537class BlockSparseSolver (object ):
3638
37- def __init__ (self , H_loc , beta , w_max , eps , gf_struct , conserved_operators = 'automatic' ):
39+ def __init__ (self , H_loc , beta , w_max , eps , gf_struct , conserved_operators = 'automatic' , timer = None ):
3840
3941 self .H_loc = H_loc
4042 self .gf_struct = gf_struct
@@ -46,6 +48,8 @@ def __init__(self, H_loc, beta, w_max, eps, gf_struct, conserved_operators='auto
4648 self .fundamental_operators = fundamental_operators_from_gf_struct (gf_struct )
4749 self .use_dense_solver = (self .conserved_operators == []) # Without symmetries, use the dense solver
4850
51+ self .timer = timer if timer is not None else Timer ()
52+
4953 if is_root ():
5054 print (logo ())
5155 print ()
@@ -85,6 +89,7 @@ def __init__(self, H_loc, beta, w_max, eps, gf_struct, conserved_operators='auto
8589 self .dysons = [DysonItPPSC (self .beta , ito , G0_block .data ) for _ , G0_block in self .G0 ]
8690
8791
92+ @timer ('Fit hybridization' )
8893 def fit_hybridization (self , tol = None , use_polefitting_dlr = False ):
8994
9095 self .tol_adapol = self .eps if tol is None else tol
@@ -161,9 +166,8 @@ def set_hybridization_poles_and_coefficients(self, poles, coefficients):
161166 #print(f'hyb.poles = {self.hyb.poles}')
162167 #print(f'hyb.coefficients =\n{self.hyb.coefficients}')
163168
164- self .init_diagram_evaluator () # FIXME! Evaluator takes hyb poles and coeffs in constructor
165-
166169
170+ @timer ('Diagram Evaluator init' )
167171 def init_diagram_evaluator (self ):
168172 if is_root (): print (f'Initializing diagram evaluator with use_dense_solver = { self .use_dense_solver } ' )
169173 if self .use_dense_solver :
@@ -179,6 +183,7 @@ def solve(self, max_order, tol=1e-7, maxiter=10, mix=1., delta_tol=None):
179183 self .delta_tol = delta_tol if delta_tol is not None else 0.1 * tol
180184
181185 self .fit_hybridization (tol = tol )
186+ self .init_diagram_evaluator () # FIXME! Evaluator takes hyb poles and coeffs in constructor
182187
183188 for iter in range (1 , maxiter + 1 ):
184189
@@ -214,6 +219,9 @@ def solve(self, max_order, tol=1e-7, maxiter=10, mix=1., delta_tol=None):
214219 G_tau = self .eval_single_particle_greens_function (self .G , max_order = self .max_order )
215220 self .G_tau = self .__from_dense_to_blockgf (G_tau , self .gf_struct )
216221
222+ if is_root ():
223+ print (); self .timer .write ()
224+
217225
218226 def normalize_pseudo_particle_gf (self , G ):
219227 """ Normalize the pseudo particle Green's function by updating the pseudo particle chemical potential eta, such that the partition function Z is equal to 1. """
@@ -263,6 +271,7 @@ def partition_function(self):
263271 return self .partition_function_from_ppgf (self .G )
264272
265273
274+ @timer ('Dyson' )
266275 def solve_dyson (self , Sigma , eta ):
267276
268277 assert type (Sigma ) is BlockGf , 'Sigma must be a BlockGf'
@@ -279,6 +288,7 @@ def pseudo_particle_self_energy(self):
279288 return self .Sigma
280289
281290
291+ @timer ('Sigma' )
282292 def eval_pseudo_particle_self_energy (self , G , max_order ):
283293
284294 self .Sigma = self .get_zero_pseudo_particle_propagator ()
@@ -336,6 +346,7 @@ def single_particle_greens_function(self, max_order):
336346 return self .eval_single_particle_greens_function (self .G , max_order = max_order )
337347
338348
349+ @timer ('Single-particle Gf' )
339350 def eval_single_particle_greens_function (self , G , max_order ):
340351 self .spgf = self .get_zero_single_particle_greens_function ()
341352
@@ -468,6 +479,7 @@ def d2eta_dalpha_deta(self, alpha, eta):
468479 return d2eta_dalpha_deta .real
469480
470481
482+ @timer ('PPSC chempot ODE' )
471483 def solve_ppsc_chempot_adiabatic_ode (self , tol = 1e-9 , method = 'DOP853' ):
472484
473485 func = lambda t , y : self .deta_dalpha (t , y [0 ])
@@ -492,6 +504,7 @@ def solve_ppsc_chempot_adiabatic_ode(self, tol=1e-9, method='DOP853'):
492504 return sol
493505
494506
507+ @timer ('PPSC chempot Newton' )
495508 def solve_ppsc_chempot_newton (self , tol = 1e-9 ):
496509
497510 f = lambda eta : self .Z_alpha (1. , eta ) - 1
@@ -550,7 +563,7 @@ def __eq__(self, obj):
550563
551564
552565 def __skip_keys (self ):
553- return ['d' , 'dysons' , 'ad' ]
566+ return ['d' , 'dysons' , 'ad' , 'timer' ]
554567
555568
556569 def __reduce_to_dict__ (self ):
0 commit comments