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

import monty.json slowing down core import #3793

Closed
1 task
DanielYang59 opened this issue Apr 30, 2024 · 4 comments · Fixed by #4128
Closed
1 task

import monty.json slowing down core import #3793

DanielYang59 opened this issue Apr 30, 2024 · 4 comments · Fixed by #4128
Labels
io Input/output functionality needs investigation Needs further research to pinpoint cause of issue vasp Vienna Ab initio Simulation Package

Comments

@DanielYang59
Copy link
Contributor

DanielYang59 commented Apr 30, 2024

Summary

  • from monty.json import xxx significantly slowly down core modules, as torch is eagerly imported
  • Might need to look into other commonly used modules

For example:

python -X importtime -c "from pymatgen.core.structure import Structure" 2> pmg.log && tuna pmg.log

With torch installed (required by optional matgl):
image

After removing torch:

image
@janosh
Copy link
Member

janosh commented May 1, 2024

this is probably import overhead from loading pandas and maybe other big packages. if you start an interactive python session first, wait for it to load and then run poscar = Structure.from_file("./POSCAR") on its own, i expect it will be faster

@janosh janosh added needs investigation Needs further research to pinpoint cause of issue io Input/output functionality vasp Vienna Ab initio Simulation Package labels May 1, 2024
@DanielYang59

This comment was marked as resolved.

@janosh
Copy link
Member

janosh commented May 2, 2024

have a look at #3563 which tried to reduce startup time by lazy-importing pandas only in code that actually needs it. that seems to have back-fired though based on this comment #3563 (comment). this takes more careful testing than i did in #3568 and materialsvirtuallab/monty#604 to make sure any changes really improve startup time

@DanielYang59
Copy link
Contributor Author

DanielYang59 commented Oct 20, 2024

This should also be partially fixed by materialsvirtuallab/monty#713, after that I would dig deeper and see what else is slowing down import

@DanielYang59 DanielYang59 changed the title Read in POSCAR with Structure.from_file seems slow? import monty.json slowing down core import Oct 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
io Input/output functionality needs investigation Needs further research to pinpoint cause of issue vasp Vienna Ab initio Simulation Package
Projects
None yet
2 participants