@@ -160,10 +160,10 @@ def __init__(self, ChainObj,
160160 # band, forces, distances, rhs_fun, action_fun,
161161 # n_images, n_dofs_image,
162162 maxSteps = 1000 ,
163- maxCreep = 5 , actionTol = 1e-10 , forcesTol = 1e-6 ,
164- etaScale = 1.0 , dEta = 2 , minEta = 0.001 ,
163+ maxCreep = 6 , actionTol = 1e-10 , forcesTol = 1e-6 ,
164+ etaScale = 1e-6 , dEta = 4. , minEta = 1e-6 ,
165165 # perturbSeed=42, perturbFactor=0.1,
166- nTrail = 10 , resetMax = 20
166+ nTrail = 13 , resetMax = 20
167167 ):
168168 # super(FSIntegrator, self).__init__(band, rhs_fun)
169169
@@ -188,17 +188,16 @@ 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 .forces
191+ self .forces = self .ChainObj .G
192192 self .distances = self .ChainObj .distances
193- self .forces_old = np .zeros_like (self .ChainObj .forces )
193+ self .forces_old = np .zeros_like (self .ChainObj .G )
194194
195195 # self.band should be just a reference to the band in the ChainObj
196196 self .band = self .ChainObj .band
197- self .band_old = np .zeros_like (self .band )
197+ self .band_old = np .copy (self .band )
198198
199199 def run_for (self , n_steps ):
200200
201- t = 0.0
202201 nStart = 0
203202 exitFlag = False
204203 totalRestart = True
@@ -214,19 +213,25 @@ def run_for(self, n_steps):
214213
215214 INNER_DOFS = slice (self .n_dofs_image , - self .n_dofs_image )
216215
216+ # Save data of energies on every step
217+ self .ChainObj .tablewriter .save ()
218+ self .ChainObj .tablewriter_dm .save ()
219+
220+ np .save (self .ChainObj .name + '_init.npy' , self .ChainObj .band )
221+
217222 while not exitFlag :
218223
219224 if totalRestart :
220- if self .step > 0 :
225+ if self .i_step > 0 :
221226 print ('Restarting' )
222227 self .band [:] = self .band_old
223228
224229 # Compute from self.band. Do not update the step at this stage:
225230 # This step updates the forces and distances in the G array of the nebm module,
226231 # using the current band state self.y
227- # TODO: remove time from chain method rhs
228- # make a specific function to update G??
229- self .rhs ( t , self .y )
232+ # TODO: make a specific function to update G??
233+ print ( 'Computing forces' )
234+ self .ChainObj . nebm_step ( self .band , ensure_zero_extrema = True )
230235 self .action = self .ChainObj .compute_action ()
231236
232237 # self.step += 1
@@ -250,13 +255,17 @@ def run_for(self, n_steps):
250255 self .trailAction
251256
252257 self .ChainObj .nebm_step (self .band , ensure_zero_extrema = True )
253- self .action = self .ChainObj .action_fun ()
258+ self .action = self .ChainObj .compute_action ()
254259
255260 self .trailAction [nStart ] = self .action
256261 nStart = next (trailPool )
257262
258263 self .i_step += 1
259264
265+ # Save data of energies on every step
266+ self .ChainObj .tablewriter .save ()
267+ self .ChainObj .tablewriter_dm .save ()
268+
260269 # Getting averages of forces from the INNER images in the band (no extrema)
261270 # (forces are given by vector G in the chain method code)
262271 # TODO: we might use all band images, not only inner ones, although G is zero at the extrema
@@ -268,10 +277,14 @@ def run_for(self, n_steps):
268277 # Average step difference between trailing action and new action
269278 deltaAction = (np .abs (self .trailAction [nStart ] - self .action )) / self .nTrail
270279
280+ # print('trail Actions', self.trailAction)
281+
271282 # Print log
272283 print (f'Step { self .i_step } ⟨RMS(G)〉= { mean_rms_G_norms_per_image :.5e} ' ,
273284 f'deltaAction = { deltaAction :.5e} Creep n = { creepCount :>3} resetC = { resetCount :>3} ' ,
274- f'eta = { eta :>5.4e} ' )
285+ f'eta = { eta :>5.4e} '
286+ f'action = { self .action :>5.4e} action_old = { self .action_old :>5.4e} '
287+ )
275288
276289 # 10 seems like a magic number; we set here a minimum number of evaulations
277290 if (nStart > self .nTrail * 10 ) and (deltaAction < self .actionTol ):
@@ -291,17 +304,25 @@ def run_for(self, n_steps):
291304 eta = eta / (self .dEta * self .dEta )
292305
293306 # If eta is too small, reset and start again
294- if (eta < 1e-3 ):
295- print ('' )
307+ if (eta < self . minEta ):
308+ # print('')
296309 resetCount += 1
297310 # bestAction = self.action_old
298- self .refine_path (self .ChainObj .distances , self .band ) # Resets the path to equidistant structures (smoothing kinks?)
311+ print ('Refining path' )
312+ self .refine_path (self .ChainObj .path_distances , self .band ) # Resets the path to equidistant structures (smoothing kinks?)
299313 # PathChanged[:] = True
300314
301315 if resetCount > self .resetMax :
302- print ('Failed to converge!' )
303- # Otherwise, just
316+ print ('Failed to converge! Reached max number of restarts' )
317+ exitFlag = True
318+ break # creep loop
319+
320+ totalRestart = True
321+ break # creep loop
322+
323+ # Otherwise, just start again with smaller alpha
304324 else :
325+ print ('Decreasing alpha' )
305326 self .band [:] = self .band_old
306327 self .forces [:] = self .forces_old
307328 # If action decreases, move to next creep step
@@ -318,20 +339,22 @@ def run_for(self, n_steps):
318339 # END creep while loop
319340
320341 # After creep loop:
321- self . eta = self . eta * self .dEta
342+ eta = eta * self .dEta
322343 resetCount = 0
323344
345+ np .save (self .ChainObj .name + '.npy' , self .ChainObj .band )
346+
324347 # Taken from the string method class
325- def refine_path (self , distances , band ):
348+ def refine_path (self , path_distances , band ):
326349 """
327350 """
328- new_dist = np .linspace (distances [0 ], distances [- 1 ], distances .shape [0 ])
351+ new_dist = np .linspace (path_distances [0 ], path_distances [- 1 ], path_distances .shape [0 ])
329352 # Restructure the string by interpolating every spin component
330353 # print(self.integrator.y[self.n_dofs_image:self.n_dofs_image + 10])
331354 bandrs = band .reshape (self .n_images , self .n_dofs_image )
332355 for i in range (self .n_dofs_image ):
333356
334- cs = si .CubicSpline (distances , bandrs [:, i ])
357+ cs = si .CubicSpline (path_distances , bandrs [:, i ])
335358 bandrs [:, i ] = cs (new_dist )
336359
337360 # def set_options(self):
0 commit comments