Skip to content

Commit

Permalink
add: required kwargs for dumping in LayerOpt
Browse files Browse the repository at this point in the history
disabled by default, for now
  • Loading branch information
eljost committed Nov 19, 2022
1 parent 8bb8413 commit ad24a40
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions pysisyphus/optimizers/LayerOpt.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,21 @@ def get_opt_kwargs(opt_key, layer_ind, thresh):
opt_kwargs = {
"type": "rfo",
"thresh": "never",
# "prefix": "model",
# "dump": True,
# "h5_group_name": "model_opt",
}
else:
if opt_key is None:
opt_key = "lbfgs"

opt_kwargs = {
"type": opt_key,
"max_cycles": 1_000,
"max_cycles": 1_500,
"thresh": thresh,
"overachieve_factor": 5,
"prefix": f"layer_{layer_ind:02d}",
"overachieve_factor": 3,
# "prefix": f"layer_{layer_ind:02d}",
# "dump": True,
}
try:
opt_kwargs.update(opt_defaults[opt_key])
Expand Down Expand Up @@ -210,8 +214,10 @@ def get_opt_getter():
layer_opt_kwargs = opt_kwargs
layer_opt_cls = opt_cls

def get_opt(geom):
opt = layer_opt_cls(geom, **layer_opt_kwargs)
def get_opt(geom, **kwargs):
kwargs_ = layer_opt_kwargs.copy()
kwargs_.update(kwargs)
opt = layer_opt_cls(geom, **kwargs_)
return opt

return get_opt
Expand All @@ -221,7 +227,7 @@ def get_opt(geom):
if i == 0:
model_opt = get_opt(geom0)

def get_opt(geom):
def get_opt(geom, **kwargs):
return model_opt

self.opt_getters.append(get_opt)
Expand Down Expand Up @@ -318,7 +324,8 @@ def optimize(self) -> None:
print(highlight_text(f"Layer {i}", level=1))
is_last_layer = i == self.layer_num - 1
geom = get_geom(coords3d_cur)
opt = get_opt(geom)
prefix = f"mc{self.cur_cycle:03d}"
opt = get_opt(geom, prefix=prefix, h5_group_name=f"{prefix}_opt")
if is_last_layer:
if self.cur_cycle == 0:
opt.prepare_opt()
Expand Down Expand Up @@ -346,7 +353,7 @@ def optimize(self) -> None:
self.forces.append(cart_forces.copy())

# Also store relevant quantities in the optimizer of the last layer, so
# stuff like Hessian updates are possible. These quantities are usually
# things like Hessian updates are possible. These quantities are usually
# stored in the big optimization-loop in Optimizer.run(). As run() is
# never called for the last optimizer we have to store them manually.
opt.coords.append(geom.coords.copy())
Expand Down

0 comments on commit ad24a40

Please sign in to comment.