-
Notifications
You must be signed in to change notification settings - Fork 875
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
Faster structure matching via StructureMatcher
(and by extension, group_structures
)
#2593
Comments
Speed ups are always welcome. But I want to note a few things:
If any further optimizations are implemented, it should not be at the cost of code maintainability or support for simple single CPU machines. I should add that as implemented, StructureMatcher is meant for simple one-off comparisons. When we actually run matching across large structure sets (e.g., entire ICSD), we use various tricks to speed it up. Pre-grouping by composition. Reducing to primitive cell. All these allow us to disable some of the more costly aspects of the general structure matcher, e.g., generating supercells. Of course, the only people who really care about performance in this regard are people working with large databases of materials. That's not a huge population to begin with. |
Thanks for creating this issue @sgbaird. I agree with @shyuep's general points, but note that I don't think this is the easiest code to maintain as it is currently written either (eg, we do use the custom Cython linear assignment code that's quite difficult to understand), so I hope that there's good scope for improvements! While large-scale usage may be comparatively rare, I certainly think the number of people needing to do large numbers of comparisons is increasing, and it's often been a bottleneck. |
For the specific suggestions:
Yes, this seems like an obvious optimization if this is being repeated. It's probably not the most critical piece (since it only has to be done once for each structure) but perhaps
Think we'd have to try this out to see how useful it'd be in practice; it's not obvious to me how many supercells are needed to be generated.
Agreed, I do want to point out this for examples of where else optimized code in pymatgen lives (this was for neighbor finding). I note that |
Let me mention that |
That's fantastic @lan496! Sometimes the key to big speed improvements is lots of "small" optimizations, this is definitely appreciated :) |
Just to second the discussions here, any form of further optimisation for |
Is your feature request related to a problem? Please describe.
Using
StructureMatcher
repeatedly causes a large overhead (in my use-case, ~40 hrs to check the performance of a generative benchmark viamatbench-genmetrics
).Describe the solution you'd like
Explore speeding up bottlenecks in the
StructureMatcher
algorithm, pre-screening, leveraging GPU for distributed calculation of matches, etc.Describe alternatives you've considered
These are in active discussion at sparks-baird/matbench-genmetrics#9, e.g. AFLOW's
XtalFinder
,dscribe
kernelsAdditional context
As a follow-up to @mkhorton 's sparks-baird/matbench-genmetrics#9 (comment), here are some flame graphs on repeated evaluations of
StructureMatcher().fit(...)
:@mkhorton figured we could chat about bottlenecks and the potential for precomputing things and speedups. Here are some of my initial thoughts:
_preprocess
on all structures once and short-circuit it during later match matrix calculationspymatgen/pymatgen/analysis/structure_matcher.py
Lines 469 to 492 in 6d1eae9
_cart_dists
is probably the easiest to replace ornumba
-fy, e.g. by implementing ajit
-ed version of the Kabsch algorithm (@kjappelbaum)Would be good to know how much memory is taken up by each calculation and whether or not these could be calculated in parallel on typical consumer GPUs.
Happy to move this to discussions if that's a better place.
The text was updated successfully, but these errors were encountered: