Skip to content

Speed up thermal displacements by batching mode populations - #1121

Closed
rpinho wants to merge 2 commits into
phonopy:mainfrom
rpinho:perf-thermal-displacement-populations
Closed

rpinho wants to merge 2 commits into
phonopy:mainfrom
rpinho:perf-thermal-displacement-populations

Conversation

@rpinho

@rpinho rpinho commented Nov 18, 2026

Copy link
Copy Markdown

Thermal displacements recompute Bose populations once per mode and look up the Gamma index at every q-point. A silicon 31 by 31 by 31 mesh with 101 temperatures runs 2.65 times faster in the paired measurements, saving a median 2.17 seconds with the stored mesh path. Evaluate the mode populations together at each q-point, contract their projections and cache the Gamma index. Existing tests and a comparison with projected displacement tensors cover the outputs, with agreement within 1e-12 relative and 1e-14 square angstrom absolute tolerance. This patch was prepared with AI assistance.

🤖 Generated with Claude Code

https://claude.ai/code/session_01LKxc9GKLwnyeV2jaZBxH9N

@atztogo

atztogo commented Nov 24, 2026

Copy link
Copy Markdown
Member

Thank you for this one too. Your change computes the contributions of
all phonon modes at a q-point together, instead of one mode at a time.
I checked it: the results agree with the current code, and it is
faster.

Reading the code around it, I found that this part needed refactoring
more than speed: ThermalDisplacements and
ThermalDisplacementMatrices had separate loops doing the same sums.
In #1131, one loop sums the thermal displacement matrices with the
modes at a q-point computed together as you did, and the thermal
displacements are taken from them.

To make it really faster, IterMesh would have to be improved. For
historical reasons, the phonopy command uses it for thermal
displacements so that a dense mesh does not run out of memory. Since
speed was not a concern, it computes phonons one q-point at a time.
Computing them in batches should make it faster, but I don't see a need
for it now; I'll work on it if there is a demand. #1131 includes a
first step toward it: IterMesh now diagonalizes the dynamical
matrices with diagonalize_dynamical_matrices, as Mesh does.

Making a new PR was less work for me than asking for changes here, so
I'm closing this PR without merging it.

@atztogo atztogo closed this Nov 24, 2026
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.

2 participants