Repository navigation
fix(utils): correctly round cube root in auto_grid_detection - #183
Open
Davis Rens (davrens101) wants to merge 1 commit into
Open
Davis Rens (davrens101) wants to merge 1 commit into
Davis Rens (davrens101) wants to merge 1 commit into
Conversation
Signed-off-by: Davis Rens <166565828+davrens101@users.noreply.github.com>
Author
|
@microsoft-github-policy-service agree [company=] |
|
Davis Rens (@davrens101) the command you issued was incorrect. Please try again. Examples are: and |
Author
|
@microsoft-github-policy-service agree |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
In
mattersim.utils.supercell_utils.auto_grid_detection, calculating the number of supercell replicas along lattice directions was written as:Because the closing parenthesis of
np.roundwas placed before** (1 / 3),np.roundwas called onmax_atoms / len(atom)instead of the cube root result.In Python floating-point arithmetic, taking the cube root of perfect cubes often produces values slightly below integers (for example,
64 ** (1 / 3) == 3.9999999999999996and216 ** (1 / 3) == 5.999999999999999). Casting this withint(...)truncated the value, resulting in:max_atoms = 64(with 1-atom unit cell) yielding(3, 3, 3)(27 atoms) instead of(4, 4, 4)(64 atoms).max_atoms = 216yielding(5, 5, 5)(125 atoms) instead of(6, 6, 6)(216 atoms).Similarly, in Case 2 (asymmetric lengths beyond tolerance),
asymmetric_replicawas computed withint(...)without rounding the cube root.Changes
np.roundoperates on the cube root:int(np.round((max_atoms / len(atom)) ** (1 / 3))).np.roundtoasymmetric_replicacalculation as well.tests/utils/test_supercell_utils.pyverifying detection on cubic systems and withinratio_tolerance.