From b2976dcb457fbd400b4f7efb7666352b8a65af9a Mon Sep 17 00:00:00 2001 From: dreamer2368 Date: Mon, 19 Dec 2022 21:50:30 -0600 Subject: [PATCH] setupInitialStep: read last step size from hdf5 file if cgStep > 0. --- utils/optimization_ver3/optimizer.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/utils/optimization_ver3/optimizer.py b/utils/optimization_ver3/optimizer.py index 99a507e..abaf1c6 100644 --- a/utils/optimization_ver3/optimizer.py +++ b/utils/optimization_ver3/optimizer.py @@ -57,6 +57,8 @@ class Optimizer: zeroControlForcing = True # control at the current CG step (directory x0) zeroLagrangian = True # augmented_lagrangian at the current stage (root directory) + lastStepSize = -1.0 # step size of last cg step + def __init__(self, config): self.config = config self.const = Constants(config) @@ -184,6 +186,11 @@ def loadState(self): self.result = Result(f.attrs['result']) if (self.const.useLagrangian): self.zeroLagrangian = f.attrs['lagrangian'] + + if (self.cgStep > 0): + dsetName = "%s/%d/%d" % (self.fl.lineMinLog, self.hyperStep, self.cgStep - 1) + bIdx = f[dsetName].attrs['b'] + self.lastStepSize = f[dsetName][bIdx, 0] return def loadPreviousPenalty(self): @@ -422,14 +429,9 @@ def setupInitialSteps(self): commands += ['cp x0/%s ./a/ ' % self.const.globalControlSpaceFiles[j]] commandString += self.scriptor.nonMPILoopCommand(commands,'copy_control_params') - numFiles = len(os.listdir(self.fl.LINMINDIR)) - if (numFiles>0): - df_file = '%s/%d/%s' % (self.fl.LINMINDIR, numFiles-1, self.fl.lineMinLogFile) - df_temp = pd.read_csv(df_file, sep='\t', header=0) - lastStep = np.array(df_temp['step'][df_temp['directory index']=='b'])[0] - steps, Js = np.zeros(2), np.zeros(2) - steps[1] = self.const.initial_step if numFiles==0 else lastStep + steps[1] = self.lastStepSize if (self.cgStep > 0) else self.const.initial_step + assert(steps[1] > 0.0) Js[0] = J0 temp = ['x0/'+file for file in self.fl.globalControlSpaceFiles]