@@ -160,8 +160,8 @@ def __init__(self, ChainObj,
160160 # band, forces, distances, rhs_fun, action_fun,
161161 # n_images, n_dofs_image,
162162 maxSteps = 1000 ,
163- maxCreep = 6 , actionTol = 1e-2 , forcesTol = 1e-6 ,
164- etaScale = 1e-6 , dEta = 4. , minEta = 1e-6 ,
163+ maxCreep = 4 , actionTol = 1e-2 , forcesTol = 1e-8 ,
164+ etaScale = 1e4 , dEta = 4. , minEta = 1e-6 ,
165165 # perturbSeed=42, perturbFactor=0.1,
166166 nTrail = 13 , resetMax = 20
167167 ):
@@ -188,13 +188,17 @@ def __init__(self, ChainObj,
188188 self .n_dofs_image = self .ChainObj .n_dofs_image
189189 # self.forces_prev = np.zeros_like(band).reshape(n_images, -1)
190190 # self.G :
191- self .forces = self .ChainObj .G
191+ self .forces = - self .ChainObj .G
192192 self .distances = self .ChainObj .distances
193193 self .forces_old = np .zeros_like (self .ChainObj .G )
194194
195195 # self.band should be just a reference to the band in the ChainObj
196- self .band = self .ChainObj .band
197- self .band_old = np .copy (self .band )
196+ # self.band = self.ChainObj.band
197+ self .band_old = np .copy (self .ChainObj .band )
198+
199+ # CHECK
200+ self .ChainObj .k [:] = 0.0
201+ self .ChainObj .spring_force [:] = 0.0
198202
199203 def run_for (self , n_steps ):
200204
@@ -218,43 +222,67 @@ def run_for(self, n_steps):
218222 self .ChainObj .tablewriter_dm .save ()
219223
220224 np .save (self .ChainObj .name + '_init.npy' , self .ChainObj .band )
225+ self .action_old = 0.0
221226
222227 while not exitFlag :
223228
224229 if totalRestart :
225230 if self .i_step > 0 :
226231 print ('Restarting' )
227- self .band [:] = self .band_old
232+ self .ChainObj . band [:] = self .band_old
228233
229234 # Compute from self.band. Do not update the step at this stage:
230235 # This step updates the forces and distances in the G array of the nebm module,
231236 # using the current band state self.y
232237 # TODO: make a specific function to update G??
233238 print ('Computing forces' )
234- self .ChainObj .nebm_step (self .band , ensure_zero_extrema = True )
239+ self .ChainObj .nebm_step (self .ChainObj . band , ensure_zero_extrema = True )
235240 self .action = self .ChainObj .compute_action ()
236241
237242 # self.step += 1
238- self .forces_old [:] = self .forces # Scale field??
243+ self .forces_old [:] = self .ChainObj . G # Scale field??
239244 # self.gradE_last[~_material] = 0.0
240245 # self.gradE[:] = self.gradE_last
241246 self .action_old = self .action
242247 self .trailAction [nStart ] = self .action
243248 nStart = next (trailPool )
244249 eta = 1.0
245250 totalRestart = False
246-
247251 creepCount = 0
248252
253+
249254 # Creep stage: minimise with a fixed eta
250255 while creepCount < self .maxCreep :
251256 # Update spin. Avoid pinned or zero-Ms sites
252- self .band [:] = self .band_old - eta * self .etaScale * self .forces_old
253- normalise_spins (self .band )
257+ self .ChainObj .band [:] = self .band_old - eta * self .etaScale * self .forces_old
258+ normalise_spins (self .ChainObj .band )
259+
260+ # self.refine_path(self.ChainObj.path_distances, self.ChainObj.band) # Resets the path to equidistant structures (smoothing kinks?)
261+ # normalise_spins(self.ChainObj.band)
262+
263+ self .trailAction [nStart ] = self .action
264+ nStart = next (trailPool )
254265
255- self .trailAction
266+ self .ChainObj .nebm_step (self .ChainObj .band , ensure_zero_extrema = True )
267+
268+ # gradE = self.ChainObj.gradientE.reshape(self.n_images, -1)
269+ # band = self.ChainObj.band.reshape(self.n_images, -1)
270+ # tgts = self.ChainObj.tangents.reshape(self.n_images, -1)
271+ # forces = self.ChainObj.G.reshape(self.n_images, -1)
272+ # for im_idx in range(gradE.shape[0]):
273+ # gradE_dot_tgt = np.sum(forces[im_idx] * tgts[im_idx])
274+ # print(f'Im {im_idx}', forces[im_idx], tgts[im_idx], gradE_dot_tgt)
275+ # print('-----', np.linalg.norm(tgts[im_idx]))
276+ # gradE = self.ChainObj.gradientE.reshape(self.n_images, -1)
277+ # band = self.ChainObj.band.reshape(self.n_images, -1)
278+ # tgts = self.ChainObj.tangents.reshape(self.n_images, -1)
279+ # forces = self.ChainObj.G.reshape(self.n_images, -1)
280+
281+ # for im_idx in range(gradE.shape[0]):
282+ # gradE_dot_tgt = np.sum(forces[im_idx] * tgts[im_idx])
283+ # print(np.linalg.norm(tgts[im_idx]), gradE_dot_tgt)
284+ # print('--')
256285
257- self .ChainObj .nebm_step (self .band , ensure_zero_extrema = True )
258286 self .action = self .ChainObj .compute_action ()
259287
260288 self .trailAction [nStart ] = self .action
@@ -269,9 +297,9 @@ def run_for(self, n_steps):
269297 # Getting averages of forces from the INNER images in the band (no extrema)
270298 # (forces are given by vector G in the chain method code)
271299 # TODO: we might use all band images, not only inner ones, although G is zero at the extrema
272- Gnorms2 = np .sum (self .forces [ INNER_DOFS ] .reshape (- 1 , 3 )** 2 , axis = 1 )
300+ Gnorms2 = np .sum (self .ChainObj . G .reshape (- 1 , 3 )** 2 , axis = 1 )
273301 # Compute the root mean square per image
274- rms_G_norms_per_image = np .sum (Gnorms2 .reshape (self .n_images - 2 , - 1 ), axis = 1 ) / self .ChainObj .n_spins
302+ rms_G_norms_per_image = np .sum (Gnorms2 .reshape (self .n_images , - 1 ), axis = 1 ) / self .ChainObj .n_images
275303 rms_G_norms_per_image = np .sqrt (rms_G_norms_per_image )
276304 mean_rms_G_norms_per_image = np .mean (rms_G_norms_per_image )
277305
@@ -314,7 +342,7 @@ def run_for(self, n_steps):
314342 resetCount += 1
315343 # bestAction = self.action_old
316344 print ('Refining path' )
317- self .refine_path (self .ChainObj .path_distances , self .band ) # Resets the path to equidistant structures (smoothing kinks?)
345+ self .refine_path (self .ChainObj .path_distances , self .ChainObj . band ) # Resets the path to equidistant structures (smoothing kinks?)
318346 # PathChanged[:] = True
319347
320348 if resetCount > self .resetMax :
@@ -328,14 +356,14 @@ def run_for(self, n_steps):
328356 # Otherwise, just start again with smaller alpha
329357 else :
330358 print ('Decreasing alpha' )
331- self .band [:] = self .band_old
332- self .forces [:] = self .forces_old
359+ self .ChainObj . band [:] = self .band_old
360+ self .ChainObj . G [:] = self .forces_old
333361 # If action decreases, move to next creep step
334362 else :
335363 creepCount += 1
336364 self .action_old = self .action
337- self .band_old [:] = self .band
338- self .forces_old [:] = self .forces
365+ self .band_old [:] = self .ChainObj . band
366+ self .forces_old [:] = self .ChainObj . G
339367
340368 if (mean_rms_G_norms_per_image < self .forcesTol ):
341369 print ('Change of mean of the force RMSquares negligible' )
0 commit comments