jacobjma / PyQSTEM

A Python interface to the electron microscopy simulation program QSTEM
GNU General Public License v3.0
60 stars 30 forks source link

Crash when reusing PyQSTEM object with different number of slices. #19

Open schiotz opened 4 years ago

schiotz commented 4 years ago

Hi Jacob,

PyQSTEM sometimes crashes when you reuse the same object with a different number of slices. Using a new pyqstem object in each iteration instead leads to a memory leak.

The attached script shows the problem. On a Mac, it gives the error

Corrupt value: 0x3f0278d13f0278d1
Python(6133,0x1136c5dc0) malloc: *** set a breakpoint in malloc_error_break to debug
Abort trap: 6

On linux, it just gives a Segmentation fault (core dumped). It is not 100% reproducible, the attached script crashes every second time or so.

schiotz commented 4 years ago
import numpy as np
from pyqstem import PyQSTEM
import ase.build

qstem=PyQSTEM('TEM')
rng = np.random.default_rng()

for i in range(10):
    atoms = ase.build.bulk('Au', orthorhombic=True).repeat((2,2,2))
    atoms.center(vacuum=10*rng.random(), axis=2)

    wave_size=(int(atoms.get_cell()[0,0]*10),int(atoms.get_cell()[1,1]*10))
    print("Setting atoms")
    qstem.set_atoms(atoms)
    print("Building wave:", wave_size)
    qstem.build_wave('plane', 300, wave_size)
    slices = int(atoms.get_cell()[2,2]*2)
    print("Building potential: slices =", slices)
    qstem.build_potential(slices)
    print("Running multislice")
    qstem.run()

(Sorry, cannot attach a .py file).

jacobjma commented 4 years ago

Hi Jakob,

PyQSTEM has quite a few issues. I will probably not have time to fix them, as I will release its replacement at the MM20 meeting. I have spent quite a bit of time on the new package, and it should be better in every possible way.

schiotz commented 4 years ago

Hi Jacob,

This makes sense. I saw your M&M2020 talk, and I am looking forward to trying it out!