Skip to content
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

A few functions use unrounded float as dict keys #4162

Open
DanielYang59 opened this issue Nov 10, 2024 · 0 comments
Open

A few functions use unrounded float as dict keys #4162

DanielYang59 opened this issue Nov 10, 2024 · 0 comments

Comments

@DanielYang59
Copy link
Contributor

DanielYang59 commented Nov 10, 2024

Using float as dict keys can be prone to precision issues (especially when float is not rounded), a few functions operate on such dict[float, Any] (could be more not annotated):

core.bonds.obtain_all_bond_lengths

def obtain_all_bond_lengths(
sp1: SpeciesLike,
sp2: SpeciesLike,
default_bl: float | None = None,
) -> dict[float, float]:
"""Obtain bond lengths for all bond orders from bond length database.
Args:
sp1 (Species): First specie.
sp2 (Species): Second specie.
default_bl: If a particular type of bond does not exist, use this
bond length as a default value (bond order = 1).
If None, a ValueError will be thrown.
Returns:
A dict mapping bond order to bond length in angstrom

core.lattice.Lattie

@property
def lll_matrix(self) -> np.ndarray:
"""The matrix for LLL reduction."""
if 0.75 not in self._lll_matrix_mappings:
self._lll_matrix_mappings[0.75] = self._calculate_lll()
return self._lll_matrix_mappings[0.75][0]
@property
def lll_mapping(self) -> np.ndarray:
"""The mapping between the LLL reduced lattice and the original lattice."""
if 0.75 not in self._lll_matrix_mappings:
self._lll_matrix_mappings[0.75] = self._calculate_lll()
return self._lll_matrix_mappings[0.75][1]

diffraction patterns

peaks: dict[float, list[float | list[tuple[int, ...]]]] = {}

peaks: dict[float, list[float | list[tuple[int, ...]]]] = {}

@DanielYang59 DanielYang59 changed the title A few functions use float as dict keys A few functions use unrounded float as dict keys Nov 13, 2024
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

No branches or pull requests

1 participant