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

IndexError on predict_structure #85

Closed
1 of 3 tasks
Yong-Q opened this issue Oct 23, 2023 · 8 comments
Closed
1 of 3 tasks

IndexError on predict_structure #85

Yong-Q opened this issue Oct 23, 2023 · 8 comments
Labels
invalid This doesn't seem right

Comments

@Yong-Q
Copy link

Yong-Q commented Oct 23, 2023

Which OS(es) are you using?

  • MacOS
  • Windows
  • Linux

What happened?

The following code snippet fails:

from chgnet.model.model import CHGNet
from pymatgen.core import Structure

chgnet = CHGNet.load()
structure = Structure.from_file('example/mp-2878.cif')
prediction = chgnet.predict_structure(structure)

for key, unit in [
    ("energy", "eV/atom"),
    ("forces", "eV/A"),
    ("stress", "GPa"),
    ("magmom", "mu_B"),
]:
    print(f"CHGNet-predicted {key} ({unit}):\n{prediction[key[0]]}\n")

Error Message

CHGNet initialized with 400,438 parameters
Traceback (most recent call last):
  File "<script>", line 6, in <module>
    prediction = chgnet.predict_structure(structure)
  File "/path/to/chgnet/model/model.py", line 551, in predict_structure
    return self.predict_graph(...)
  File "/path/to/chgnet/model/model.py", line 340, in forward
    batched_graph = BatchedGraph.from_graphs(...)
  File "/path/to/chgnet/model/model.py", line 754, in from_graphs
    center=atom_cart_coords[graph.atom_graph[:, 0]],
IndexError: tensors used as indices must be long, byte or bool tensors
@Yong-Q Yong-Q added the bug Something isn't working label Oct 23, 2023
@Yong-Q Yong-Q changed the title [Bug]: CHGNet initialized with 400,438 parameters Traceback (most recent call last): File "/home/CHGnet/test/test.py", line 6, in <module> prediction = chgnet.predict_structure(structure) File "/home/qiuyong/.conda/envs/LiIonMl/lib/python3.10/site-packages/chgnet/model/model.py", line 551, in predict_structure return self.predict_graph( File "/home/.conda/envs/LiIonMl/lib/python3.10/site-packages/chgnet/model/model.py", line 603, in predict_graph prediction = self.forward( File "/home/.conda/envs/LiIonMl/lib/python3.10/site-packages/chgnet/model/model.py", line 340, in forward batched_graph = BatchedGraph.from_graphs( File "/home/.conda/envs/LiIonMl/lib/python3.10/site-packages/chgnet/model/model.py", line 754, in from_graphs center=atom_cart_coords[graph.atom_graph[:, 0]], IndexError: tensors used as indices must be long, byte or bool tensors [Bug]: CHGNet initialized with 400,438 parameters Traceback (most recent call last): line 6, in <module> prediction = chgnet.predict_structure(structure) chgnet/model/model.py", line 551, in predict_structure return self.predict_graph( /chgnet/model/model.py", line 340, in forward batched_graph = BatchedGraph.from_graphs( chgnet/model/model.py", line 754, in from_graphs center=atom_cart_coords[graph.atom_graph[:, 0]], IndexError: tensors used as indices must be long, byte or bool tensors Oct 23, 2023
@BowenD-UCB
Copy link
Collaborator

I can't reproduce this error

@janosh janosh changed the title [Bug]: CHGNet initialized with 400,438 parameters Traceback (most recent call last): line 6, in <module> prediction = chgnet.predict_structure(structure) chgnet/model/model.py", line 551, in predict_structure return self.predict_graph( /chgnet/model/model.py", line 340, in forward batched_graph = BatchedGraph.from_graphs( chgnet/model/model.py", line 754, in from_graphs center=atom_cart_coords[graph.atom_graph[:, 0]], IndexError: tensors used as indices must be long, byte or bool tensors IndexError on predict_structure Oct 23, 2023
@janosh
Copy link
Collaborator

janosh commented Oct 23, 2023

Me neither.

@janosh janosh added invalid This doesn't seem right and removed bug Something isn't working labels Oct 23, 2023
@Yong-Q
Copy link
Author

Yong-Q commented Oct 23, 2023

Why is this, I installed it via pip, this problem occurs in both cpu and gpu
1.txt

@Yong-Q
Copy link
Author

Yong-Q commented Oct 23, 2023

Me neither.
#structure = Structure.from_file(f"{ROOT}/examples/mp-18767-LiMnO2.cif")

structure = Structure.from_file("./mp-18767-LiMnO2.cif")
I only changed this one item, but looking at the output shouldn't be the problem

@BowenD-UCB
Copy link
Collaborator

I suppose it's a version issue of pymatgen and CHGNet. Can you try upgrade pymatgen and CHGNet? @Yong-Q

@Yong-Q
Copy link
Author

Yong-Q commented Oct 23, 2023 via email

@Yong-Q Yong-Q closed this as completed Oct 23, 2023
@Yong-Q
Copy link
Author

Yong-Q commented Oct 23, 2023

good

@Yong-Q
Copy link
Author

Yong-Q commented Oct 24, 2023

我想这是pymatgen和CHGNet的版本问题。你能尝试升级pymatgen和CHGNet吗?

I would like to ask how the prediction of energy etc. can be improved by constructing the Angle relationship on the GNN structure

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

3 participants