Skip to content

Commit

Permalink
setupInitialStep: read last step size from hdf5 file if cgStep > 0.
Browse files Browse the repository at this point in the history
  • Loading branch information
dreamer2368 committed Dec 20, 2022
1 parent 229bfdf commit b2976dc
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions utils/optimization_ver3/optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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]
Expand Down

0 comments on commit b2976dc

Please sign in to comment.