Skip to content

Commit 9ddd062

Browse files
author
Francesco Libbi
committed
Fixed a bug on the remove
1 parent d4833ee commit 9ddd062

3 files changed

Lines changed: 26 additions & 2 deletions

File tree

Modules/Ensemble.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1884,11 +1884,14 @@ def get_preconditioned_gradient_parallel(self, *args, **kwargs):
18841884
For documentation, see get_preconditioned_gradient
18851885
"""
18861886

1887+
print("force length:", len(self.force_computed))
18871888

18881889
def work_function(argument):
1890+
print("force length [inside]:", len(self.force_computed))
18891891
ensemble_start_config, ensemble_end_config = argument
18901892
mask = np.zeros(self.N, dtype = bool)
18911893
mask[ensemble_start_config : ensemble_end_config] = True
1894+
print("mask length:", np.sum(mask.astype(int))," total N:", len(mask))
18921895
new_ensemble = self.split(mask)
18931896

18941897
gradient, error = new_ensemble.get_preconditioned_gradient(*args, **kwargs)
@@ -1909,7 +1912,10 @@ def work_function(argument):
19091912

19101913
list_of_inputs.append( (start_config, end_config) )
19111914

1912-
gradient, error = CC.Settings.GoParallelTuple(work_function, list_of_inputs, "+")
1915+
results = CC.Settings.GoParallelTuple(work_function, list_of_inputs, "+")
1916+
print(results)
1917+
print(np.shape(results))
1918+
gradient, error = results
19131919
gradient /= np.sum(self.rho)
19141920
error /= np.sum(self.rho)
19151921

@@ -3082,9 +3088,12 @@ def compute_ensemble(self, calculator, compute_stress = True, stress_numerical =
30823088
else:
30833089
computing_ensemble.get_energy_forces(calculator, compute_stress, stress_numerical, verbose = verbose)
30843090

3091+
print("CE BEFORE MERGE:", len(self.force_computed))
3092+
30853093
if should_i_merge:
30863094
# Remove the noncomputed ensemble from here, and merge
30873095
self.merge(computing_ensemble)
3096+
print("CE AFTER MERGE:", len(self.force_computed))
30883097

30893098
print('ENSEMBLE ALL PROPERTIES:', self.all_properties)
30903099

@@ -3150,6 +3159,11 @@ def split(self, split_mask):
31503159
N = np.sum(split_mask.astype(int))
31513160
ens = Ensemble(self.dyn_0, self.T0, self.dyn_0.GetSupercell())
31523161
ens.init_from_structures(structs)
3162+
print("Split length:", len(split_mask))
3163+
print("original force legnth:", len(self.force_computed))
3164+
print("Expected length:", len(ens.force_computed))
3165+
print("Splitting force length:", len(self.force_computed[split_mask]))
3166+
31533167
ens.force_computed[:] = self.force_computed[split_mask]
31543168
ens.stress_computed[:] = self.stress_computed[split_mask]
31553169
ens.energies[:] = self.energies[split_mask]
@@ -3172,7 +3186,7 @@ def remove_noncomputed(self):
31723186
It may be used to run a minimization even if the ensemble was not completely calculated.
31733187
"""
31743188

3175-
good_mask = self.force_computed
3189+
good_mask = np.copy(self.force_computed)
31763190
if self.has_stress:
31773191
good_mask = good_mask & self.stress_computed
31783192

@@ -3184,6 +3198,8 @@ def remove_noncomputed(self):
31843198
self.sscha_energies = self.sscha_energies[good_mask]
31853199
self.xats = self.xats[good_mask, :, :]
31863200
self.u_disps = self.u_disps[good_mask, :]
3201+
self.force_computed = self.force_computed[good_mask]
3202+
self.stress_computed = self.stress_computed[good_mask]
31873203

31883204
self.structures = [self.structures[x] for x in np.arange(len(good_mask))[good_mask]]
31893205
self.all_properties = [self.all_properties[x] for x in np.arange(len(good_mask))[good_mask]]
@@ -3236,6 +3252,7 @@ def get_energy_forces(self, ase_calculator, compute_stress = True, stress_numeri
32363252

32373253
# Setup the calculator for each structure
32383254
parallel = False
3255+
print("Force computed shape:", len(self.force_computed))
32393256
if __MPI__:
32403257
comm = MPI.COMM_WORLD
32413258
size = comm.Get_size()
@@ -3392,6 +3409,7 @@ def get_energy_forces(self, ase_calculator, compute_stress = True, stress_numeri
33923409
# Reshape the arrays
33933410
self.forces[:, :, :] = np.reshape(total_forces, (N_rand, self.current_dyn.structure.N_atoms*np.prod(self.supercell), 3), order = "C")
33943411
self.force_computed[:] = True
3412+
print("Force computed shape:", len(self.force_computed))
33953413

33963414
if compute_stress:
33973415
self.stresses[:,:,:] = np.reshape(total_stress, (N_rand, 3, 3), order = "C")

Modules/Relax.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,15 +576,20 @@ def vc_relax(self, target_press = 0, static_bulk_modulus = 100,
576576
cluster = self.cluster)
577577
#self.minim.ensemble.get_energy_forces(self.calc, True, stress_numerical = stress_numerical)
578578

579+
print("RELAX force length:", len(self.minim.ensemble.force_computed))
580+
579581
if ensemble_loc is not None and self.save_ensemble:
580582
self.minim.ensemble.save_bin(ensemble_loc, pop)
583+
print("RELAX force length:", len(self.minim.ensemble.force_computed))
581584

582585
self.minim.population = pop
583586
self.minim.init(delete_previous_data = False)
584587

588+
print("RELAX force length:", len(self.minim.ensemble.force_computed))
585589
self.minim.run(custom_function_pre = self.__cfpre__,
586590
custom_function_post = self.__cfpost__,
587591
custom_function_gradient = self.__cfg__)
592+
588593

589594

590595
self.minim.finalize()

Modules/SchaMinimizer.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ def minimization_step(self, custom_function_gradient = None):
304304
It takes as input the two gradient (the dynamical matrix one and the structure one), and
305305
modifies them (or does some I/O on it).
306306
"""
307+
print("Minimization step, force computed:", len(self.ensemble.force_computed))
307308

308309
# Setup the symmetries
309310
qe_sym = CC.symmetries.QE_Symmetry(self.dyn.structure)

0 commit comments

Comments
 (0)