-
Notifications
You must be signed in to change notification settings - Fork 21
optimizer as an argument for optimize #365
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,7 +34,7 @@ def _new_log(self, forces=None): | |
| def _run_autopara_wrappable(atoms, calculator, fmax=1.0e-3, smax=None, steps=1000, pressure=None, | ||
| stress_mask=None, keep_symmetry=True, traj_step_interval=1, traj_subselect=None, | ||
| skip_failures=True, results_prefix='last_op__optimize_', verbose=False, update_config_type="append", | ||
| rng=None, _autopara_per_item_info=None, | ||
| optimizer=PreconLBFGS, rng=None, _autopara_per_item_info=None, | ||
| **opt_kwargs): | ||
| """runs a structure optimization. By default calculator properties will be stored in keys | ||
| prefixed with "last_op__optimize_", which may be overwritten by next operation. | ||
|
|
@@ -73,6 +73,8 @@ def _run_autopara_wrappable(atoms, calculator, fmax=1.0e-3, smax=None, steps=100 | |
| optimisation logs are not printed unless this is True | ||
| update_config_type: ["append" | "overwrite" | False], default "append" | ||
| whether/how to add at.info['optimize_config_type'] to at.info['config_type'] | ||
| optimizer : ASE optimizer | ||
| optimizer to use, default LBFGSPrecon | ||
| opt_kwargs | ||
| keyword arguments for PreconLBFGS | ||
| rng: numpy.random.Generator, default None | ||
|
|
@@ -93,7 +95,7 @@ def _run_autopara_wrappable(atoms, calculator, fmax=1.0e-3, smax=None, steps=100 | |
|
|
||
| calculator = construct_calculator_picklesafe(calculator) | ||
|
|
||
| if smax is None: | ||
| if "precon" in optimizer.__module__.split(".") and smax is None: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it be safer to do
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems Also there's
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're right,
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Try this diff file
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could also write it with nested try/except, but I think that ends up uglier
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the try/catch version Neither is well tested
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems to work for both precon and non-precon optimizers though it's a bit longer.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like for some reason |
||
| smax = fmax | ||
|
|
||
| if keep_symmetry: | ||
|
|
@@ -134,7 +136,7 @@ def _run_autopara_wrappable(atoms, calculator, fmax=1.0e-3, smax=None, steps=100 | |
| else: | ||
| wrapped_at = at | ||
|
|
||
| opt = PreconLBFGS(wrapped_at, **opt_kwargs_to_use) | ||
| opt = optimizer(wrapped_at, **opt_kwargs_to_use) | ||
|
|
||
| # default status, will be overwritten for first and last configs in traj | ||
| at.info['optimize_config_type'] = 'optimize_mid' | ||
|
|
@@ -162,7 +164,10 @@ def process_step(): | |
| converged = False | ||
|
|
||
| try: | ||
| converged = opt.run(fmax=fmax, smax=smax, steps=steps) | ||
| if smax is None: | ||
| converged = opt.run(fmax=fmax, steps=steps) | ||
| else: | ||
| converged = opt.run(fmax=fmax, smax=smax, steps=steps) | ||
| except Exception as exc: | ||
| # label actual failed optimizations | ||
| # when this happens, the atomic config somehow ends up with a 6-vector stress, which can't be | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.