Skip to content

optimizer as an argument for optimize#365

Merged
bernstei merged 6 commits into
libAtoms:mainfrom
jungsdao:main
Jul 22, 2026
Merged

optimizer as an argument for optimize#365
bernstei merged 6 commits into
libAtoms:mainfrom
jungsdao:main

Conversation

@jungsdao

Copy link
Copy Markdown
Contributor

As mentioned in #364, I made small change that can take different optimizer for optimize function because some cases, results are quite sensitive to the optimizer.
Hope this might be a useful change.

closes #364

Comment thread wfl/generate/optimize.py Outdated
Comment thread wfl/generate/optimize.py Outdated
calculator = construct_calculator_picklesafe(calculator)

if smax is None:
if "precon" in optimizer.__module__.split(".") and smax is None:

@bernstei bernstei Jul 21, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be safer to do isinstance(optimizer, PreconLBFGS)?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems isinstance is not good way to check it.

optimizer = PreconLBFGS
isinstance(optimizer, PreconLBFGS)
## False

Also there's PreconFIRE. I don't have better idea than this but if you have better solution, please let me know I'll adapt it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, isinstance is wrong. Maybe optimizer.__name__ in ["PreconLBFGS", "PreconFIRE"]? Really it would be better to do this by trying to pass smax to the dynamics and falling back if it fails. Let me try to write something like that.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try this diff file
opt_smax_diff.txt

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the try/catch version
opt_smax_diff_trycatch.txt

Neither is well tested

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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.
There seems to be a test failures which is not related to this PR.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like for some reason gap_fit doesn't exist in the CI. I'll merge this PR, and then try to figure out why that's happening.

@bernstei
bernstei merged commit 0ef2858 into libAtoms:main Jul 22, 2026
2 of 3 checks passed
@jungsdao

Copy link
Copy Markdown
Contributor Author

Thank you for accepting PR !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Specifying which optimizer to be used

2 participants