MaterSim / PyXtal

A code to generate atomic structure with symmetry
MIT License
247 stars 65 forks source link

Memory Reduction && Test supergroup #273

Closed qzhu2017 closed 2 weeks ago

qzhu2017 commented 2 weeks ago

After the recent changes on symmetry modules, the speed of supergroup is likely to become slower due to the visit of t/k subgroup data. Needs to bring the speed back.

On the bright side, the memory usage is less.

import psutil
import os

def print_memory_usage():
    process = psutil.Process(os.getpid())
    mem_info = process.memory_info()
    print(f"Memory usage: {mem_info.rss / 1024 ** 2:.2f} MB")  # RSS is the Resident Set Size

if __name__ == "__main__":
    print_memory_usage()
    from pyxtal.symmetry import Group
    print_memory_usage()
    g = Group(4, quick=True)
    print_memory_usage()
    g = Group(227)
    print_memory_usage()

    from pyxtal import pyxtal
    xtal = pyxtal()
    xtal.from_spg_wps_rep(194, ['2c', '2b'], [2.46, 6.70])
    print_memory_usage()

    xtal.subgroup_once()
    print_memory_usage()
Memory usage: 15.17 MB
Memory usage: 292.17 MB
Memory usage: 292.20 MB
Memory usage: 297.22 MB
Memory usage: 298.00 MB
Memory usage: 308.62 MB

The old results are

qzhu8@MAC ~/GitHub/PyXtal master $ python 0.py 
Memory usage: 15.02 MB
Memory usage: 424.39 MB
Memory usage: 424.39 MB
Memory usage: 426.28 MB
Memory usage: 426.86 MB

commit 07d63b30a7019e1af5a92e0cb99ae6d5a9c5088e

$ python test_supergroup.py 
----------------------------------------------------------------------
Ran 9 tests in 47.220s

commit 85aa6ae7d6a827a50b849cb73b69ddabffb81a2c

qzhu8@MAC ~/GitHub/PyXtal master $ python test_supergroup.py                            
----------------------------------------------------------------------
Ran 9 tests in 14.752s
qzhu2017 commented 2 weeks ago

Todo: Avoid the instance of Group