Skip to content

Commit 07c370e

Browse files
committed
[pybs] timings printout
1 parent 833bf26 commit 07c370e

4 files changed

Lines changed: 20 additions & 5 deletions

File tree

python/triqs_xca/block_sparse_solver.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
from .module import trace
2121
from .module import convolve_ppsc as conv
2222

23+
from .ase.utils.timing import Timer, timer
24+
2325

2426
def is_root():
2527
return mpi.is_master_node()
@@ -34,7 +36,7 @@ def scatter_array_over_ranks(arr):
3436

3537
class 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):

test/python/block_sparse_api.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ def test_oca_diagram_cf_block_sparse_and_dense(beta=2.0, verbose=False):
104104
BSS.Delta_tau['dn'] << Delta_tau
105105

106106
BSS.fit_hybridization(tol=eps)
107+
BSS.init_diagram_evaluator()
107108

108109

109110
# -- Dense solver

test/python/block_sparse_api_one_fermion.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ def test_oca_diagram_cf_block_sparse_and_dense(
167167
BSS.Delta_tau['0'] << Delta_tau
168168

169169
BSS.fit_hybridization(tol=eps)
170-
170+
BSS.init_diagram_evaluator()
171171

172172
# -- Compare pseudo particle Green's function
173173

test/python/block_sparse_api_two_fermions.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ def test_diagrams_cf_block_sparse_and_dense(e1=-1.5, beta=2.0, conserved_operato
9494
BSS.Delta_tau['0'] << Delta_tau
9595

9696
BSS.fit_hybridization(tol=eps)
97+
BSS.init_diagram_evaluator()
9798

9899

99100
# -- Compare pseudo particle Green's function

0 commit comments

Comments
 (0)