Skip to content

Commit 418545f

Browse files
Merge branch 'master' into Diegom_sobol
2 parents 147b87c + 8cf3d2a commit 418545f

2 files changed

Lines changed: 33 additions & 13 deletions

File tree

Modules/Ensemble.py

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1923,25 +1923,26 @@ def get_preconditioned_gradient(self, subtract_sscha = True, return_error = Fals
19231923
"""
19241924

19251925
t1 = time.time()
1926-
supercell_dyn = self.current_dyn.GenerateSupercellDyn(self.supercell)
1927-
1926+
super_struct = self.current_dyn.structure.generate_supercell(self.supercell)
1927+
#supercell_dyn = self.current_dyn.GenerateSupercellDyn(self.supercell)
1928+
19281929
# Dyagonalize
1929-
w, pols = supercell_dyn.DyagDinQ(0)
1930+
w, pols = self.current_dyn.DiagonalizeSupercell()#supercell_dyn.DyagDinQ(0)
19301931

19311932
if not self.ignore_small_w:
1932-
trans = CC.Methods.get_translations(pols, supercell_dyn.structure.get_masses_array())
1933+
trans = CC.Methods.get_translations(pols, super_struct.get_masses_array())
19331934
else:
19341935
trans = np.abs(w) < CC.Phonons.__EPSILON_W__
19351936

1936-
ityp = supercell_dyn.structure.get_ityp() + 1 # Py to fortran convertion
1937-
mass = np.array(list(supercell_dyn.structure.masses.values()))
1938-
1937+
ityp = super_struct.get_ityp() + 1 # Py to fortran convertion
1938+
mass = np.array(list(super_struct.masses.values()))
1939+
19391940
log_err = "err_yesrho"
19401941

19411942
mass *= 2
19421943
w /= 2
19431944

1944-
nat = supercell_dyn.structure.N_atoms
1945+
nat = super_struct.N_atoms
19451946
eforces = np.zeros((self.N, nat, 3), dtype = np.float64, order = "F")
19461947
u_disp = np.zeros((self.N, nat, 3), dtype = np.float64, order = "F")
19471948
#print nat
@@ -1982,11 +1983,20 @@ def get_preconditioned_gradient(self, subtract_sscha = True, return_error = Fals
19821983

19831984
# Perform the fourier transform
19841985
if return_error:
1985-
q_grad,q_grad_err = CC.Phonons.GetDynQFromFCSupercell(grad, np.array(self.current_dyn.q_tot),
1986-
self.current_dyn.structure, supercell_dyn.structure,fc2=grad_err)
1986+
# Check if a multiprocessing function can be exploited
1987+
if hasattr(CC.Phonons, 'GetDynQFromFCSupercell_parallel') and CC.Settings.GetNProc() > 1:
1988+
q_grad,q_grad_err = CC.Phonons.GetDynQFromFCSupercell_parallel(grad, np.array(self.current_dyn.q_tot),
1989+
self.current_dyn.structure, super_struct,fc2=grad_err)
1990+
else:
1991+
q_grad,q_grad_err = CC.Phonons.GetDynQFromFCSupercell(grad, np.array(self.current_dyn.q_tot),
1992+
self.current_dyn.structure, super_struct,fc2=grad_err)
19871993
else:
1988-
q_grad = CC.Phonons.GetDynQFromFCSupercell(grad, np.array(self.current_dyn.q_tot),
1989-
self.current_dyn.structure, supercell_dyn.structure)
1994+
if hasattr(CC.Phonons, 'GetDynQFromFCSupercell_parallel'):
1995+
q_grad = CC.Phonons.GetDynQFromFCSupercell_parallel(grad, np.array(self.current_dyn.q_tot),
1996+
self.current_dyn.structure, super_struct)
1997+
else:
1998+
q_grad = CC.Phonons.GetDynQFromFCSupercell(grad, np.array(self.current_dyn.q_tot),
1999+
self.current_dyn.structure, super_struct)
19902000
#q_grad_err = CC.Phonons.GetDynQFromFCSupercell(grad_err, np.array(self.current_dyn.q_tot),
19912001
# self.current_dyn.structure, supercell_dyn.structure)
19922002
else:

Modules/SchaMinimizer.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,7 @@ def minimization_step(self, custom_function_gradient = None):
352352
#CC.symmetries.CustomASR(err)
353353
else:
354354
# We have a supercell, we must generate the dynamical matrix in the supercell
355+
t_5 = time.time()
355356
super_structure = self.dyn.structure.generate_supercell(supercell)
356357
fc_supercell = CC.Phonons.GetSupercellFCFromDyn(dyn_grad, np.array(self.dyn.q_tot), \
357358
self.dyn.structure, super_structure)
@@ -360,13 +361,22 @@ def minimization_step(self, custom_function_gradient = None):
360361
qe_sym_supcell = CC.symmetries.QE_Symmetry(super_structure)
361362
qe_sym_supcell.SetupFromSPGLIB()
362363

364+
t_6 = time.time()
365+
363366
# Apply the symmetries to the fc_supercell matrix
364367
qe_sym_supcell.ApplySymmetriesToV2(fc_supercell)
365368

369+
t_7 = time.time()
366370
# Convert back to Q space
367-
dyn_grad = CC.Phonons.GetDynQFromFCSupercell(fc_supercell, np.array(self.dyn.q_tot), \
371+
dyn_grad = CC.Phonons.GetDynQFromFCSupercell_parallel(fc_supercell, np.array(self.dyn.q_tot), \
368372
self.dyn.structure, super_structure)
369373

374+
t_8 = time.time()
375+
376+
print(' [symmetrization] Time to prepare the suprecell dyn : {:.6f} s'.format(t_6 - t_5))
377+
print(' [symmetrization] Time to symmetrize in the supercell : {:.6f} s'.format(t_7 - t_6))
378+
print(' [symmetrization] Time to return in fourier space : {:.6f} s'.format(t_8 - t_7))
379+
370380
# Apply the sum rule at gamma
371381
CC.symmetries.CustomASR(dyn_grad[0,:,:])
372382
else:

0 commit comments

Comments
 (0)