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

[Feature Request]: Which version do the CHGNet tutorials correspond to? #196

Closed
1 task done
J-You opened this issue Sep 8, 2024 · 3 comments
Closed
1 task done
Labels
bug Something isn't working compatibility Compatibility with different OS, Python, PyTorch, numpy, etc.

Comments

@J-You
Copy link

J-You commented Sep 8, 2024

Email (Optional)

[email protected]

Problem

Could you please clarify which version the CHGNet tutorials correspond to? I encountered errors while running the tutorials with the latest version (0.3.8). Pymatgen version (2024.8.9)

import torch
torch.cuda.is_available()
>>> True
from chgnet.model import CHGNet
import numpy as np
from pymatgen.core import Structure

np.set_printoptions(precision=4, suppress=True)
chgnet = CHGNet.load(model_name='0.3.0', use_device='cpu')
# Alternatively you can read your own model
# chgnet = CHGNet.from_file(model_path)

structure = Structure.from_file("LiMnO2.cif")
structure
>>> Structure Summary
Lattice
    abc : 2.868779 4.634475 5.832507
 angles : 90.0 90.0 90.0
 volume : 77.5448402400077
      A : 2.868779 0.0 1.7566205099055724e-16
      B : 7.452804216860131e-16 4.634475 2.837797487239215e-16
      C : 0.0 0.0 5.832507
    pbc : True True True
PeriodicSite: Li0 (Li+) (1.434, 2.317, 2.215) [0.5, 0.5, 0.3798]
PeriodicSite: Li1 (Li+) (0.0, 0.0, 3.618) [0.0, 0.0, 0.6202]
PeriodicSite: Mn2 (Mn3+) (1.434, 2.317, 5.035) [0.5, 0.5, 0.8633]
PeriodicSite: Mn3 (Mn3+) (0.0, 0.0, 0.7976) [0.0, 0.0, 0.1367]
PeriodicSite: O4 (O2-) (1.434, 0.0, 2.105) [0.5, 0.0, 0.3608]
PeriodicSite: O5 (O2-) (3.726e-16, 2.317, 0.5746) [0.0, 0.5, 0.09851]
PeriodicSite: O6 (O2-) (1.434, 0.0, 5.258) [0.5, 0.0, 0.9015]
PeriodicSite: O7 (O2-) (3.726e-16, 2.317, 3.728) [0.0, 0.5, 0.6392]
prediction = chgnet.predict_structure(structure=structure,task='ef')
ValueError                                Traceback (most recent call last)

Cell In[7], line 1
----> 1 prediction = chgnet.predict_structure(structure=structure,task='ef')


File ~\anaconda3\lib\site-packages\chgnet\model\model.py:572, in CHGNet.predict_structure(self, structure, task, return_site_energies, return_atom_feas, return_crystal_feas, batch_size)
    568     raise ValueError("graph_converter cannot be None!")
    570 structures = [structure] if isinstance(structure, Structure) else structure
--> 572 graphs = [self.graph_converter(struct) for struct in structures]
    573 return self.predict_graph(
    574     graphs,
    575     task=task,
   (...)
    579     batch_size=batch_size,
    580 )


File ~\anaconda3\lib\site-packages\chgnet\model\model.py:572, in <listcomp>(.0)
    568     raise ValueError("graph_converter cannot be None!")
    570 structures = [structure] if isinstance(structure, Structure) else structure
--> 572 graphs = [self.graph_converter(struct) for struct in structures]
    573 return self.predict_graph(
    574     graphs,
    575     task=task,
   (...)
    579     batch_size=batch_size,
    580 )


File ~\anaconda3\lib\site-packages\torch\nn\modules\module.py:1553, in Module._wrapped_call_impl(self, *args, **kwargs)
   1551     return self._compiled_call_impl(*args, **kwargs)  # type: ignore[misc]
   1552 else:
-> 1553     return self._call_impl(*args, **kwargs)


File ~\anaconda3\lib\site-packages\torch\nn\modules\module.py:1562, in Module._call_impl(self, *args, **kwargs)
   1557 # If we don't have any hooks, we want to skip the rest of the logic in
   1558 # this function, and just call forward.
   1559 if not (self._backward_hooks or self._backward_pre_hooks or self._forward_hooks or self._forward_pre_hooks
   1560         or _global_backward_pre_hooks or _global_backward_hooks
   1561         or _global_forward_hooks or _global_forward_pre_hooks):
-> 1562     return forward_call(*args, **kwargs)
   1564 try:
   1565     result = None


File ~\anaconda3\lib\site-packages\chgnet\graph\converter.py:129, in CrystalGraphConverter.forward(self, structure, graph_id, mp_id)
    123 atom_frac_coord = torch.tensor(
    124     structure.frac_coords, dtype=datatype, requires_grad=True
    125 )
    126 lattice = torch.tensor(
    127     structure.lattice.matrix, dtype=datatype, requires_grad=True
    128 )
--> 129 center_index, neighbor_index, image, distance = structure.get_neighbor_list(
    130     r=self.atom_graph_cutoff, sites=structure.sites, numerical_tol=1e-8
    131 )
    133 # Make Graph
    134 graph = self.create_graph(
    135     n_atoms, center_index, neighbor_index, image, distance
    136 )


File ~\anaconda3\lib\site-packages\pymatgen\core\structure.py:1782, in IStructure.get_neighbor_list(self, r, sites, numerical_tol, exclude_self)
   1780 lattice_matrix = np.ascontiguousarray(self.lattice.matrix, dtype=float)
   1781 pbc = np.ascontiguousarray(self.pbc, dtype=int)
-> 1782 center_indices, points_indices, images, distances = find_points_in_spheres(
   1783     cart_coords,
   1784     site_coords,
   1785     r=r,
   1786     pbc=pbc,
   1787     lattice=lattice_matrix,
   1788     tol=numerical_tol,
   1789 )
   1790 cond = np.array([True] * len(center_indices))
   1791 if exclude_self:


File src\\pymatgen\\optimization\\neighbors.pyx:48, in pymatgen.optimization.neighbors.find_points_in_spheres()

ValueError: Buffer dtype mismatch, expected 'const int64_t' but got 'long'

Proposed Solution

implement the old version of chgnet or update these turorials?

Alternatives

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@BowenD-UCB
Copy link
Collaborator

The colab example runs smoothly on my side.
It's with pymatgen-2024.8.9 and chgnet-0.3.8

@janosh
Copy link
Collaborator

janosh commented Sep 10, 2024

this is a numpy v2 compatibility issue that's specific to Windows. see materialsproject/pymatgen#3992. chgnet needs to update to support numpy v2 on Windows. in the meantime you can pip install 'numpy<2'

@janosh janosh added bug Something isn't working compatibility Compatibility with different OS, Python, PyTorch, numpy, etc. labels Sep 10, 2024
@J-You
Copy link
Author

J-You commented Sep 11, 2024

Thanks for your response. Got it!

@J-You J-You closed this as completed Sep 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working compatibility Compatibility with different OS, Python, PyTorch, numpy, etc.
Projects
None yet
Development

No branches or pull requests

3 participants