Add symmetric option to group_structures, pass through to sm.fit() and test - #133
Conversation
shyuep
left a comment
There was a problem hiding this comment.
🤖 Automated PR review generated by Claude (posted via @shyuep's scheduled review routine)
Clean, minimal change. The order-dependence of group_structures from directional fit() is a real and long-standing footgun (cf. materialsproject/pymatgen#3113), and threading symmetric through with a False default preserves existing behavior. Docstring correctly notes the kwarg is ignored under anonymous=True and that greedy grouping remains non-transitive in general.
Test reuses the existing asymmetric POSCAR pair and covers both orderings — good. All CI green.
One minor note: symmetric=True roughly doubles the fit cost per pair; the 1.04x pipeline figure in the description is reassuring, so no action needed. LGTM.
|
Thanks. |
Summary
This is a small PR to add the
symmetricoption toStructureMatcher.group_structures(), which is then passed through to the underlyingStructureMatcher.fit()usage.Summary with the help of Claude:
StructureMatcher.fitis directional;symmetric=Falseby default, and its docstring says so. Butgroup_structuresconsumes it as if it were an equality test: it pops a reference and always passes that reference asstruct1. So which structure happens to come first decides the grouping.This repo already keeps a structure pair for the asymmetry, used by
test_fit:Using
test-files/io/vasp/inputs/POSCAR_fit_symm_s1and_s2, fromtests/core/test_structure_matcher.py:529-537.This PR threads a
symmetrickwarg through to thefitcall so callers that need an order-independentgrouping can ask for one. It defaults to
False, so no existing caller changes behaviour, and it isignored under
anonymous=Truesincefit_anonymoushas no symmetric mode. One test added.Motivation:
MaterialsProjectDFTMixingSchemegroups GGA and r2SCAN structures this way, and theasymmetry makes its phase diagrams depend on
PYTHONHASHSEED— see materialsproject/pymatgen#3113 andthe follow-up PR (I'll be raising now) to materialsproject/pymatgen#4703, which passes
symmetric=Truehere. Over the 120 permutations of the pre-group in that bug, the current default yields 3 distinct groupings andsymmetric=Trueyields 1, at 1.04x runtime for the full pipeline.Note this does not make greedy grouping order-independent in general — a symmetric relation can still be non-transitive — but it removes the directional class of it at least.
Checklist
uv run pytest tests/core -k latticefor a lattice change — the full suite runs in CI)
uv run ruff check . && uv run ruff format --check .Breaking changes?
behavior changes, changed defaults/output, dropped Python versions, ...).
If so, prefix the title with
[breaking]and describe the change andmigration steps under
## Breaking Changesbelow.Breaking Changes