Skip to content

Commit b0feb0c

Browse files
authored
Merge pull request #796 from pfebrer/patch-9
Clarify out of memory error on density
2 parents 3979468 + c2c8aa0 commit b0feb0c

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

src/sisl/physics/densitymatrix.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -814,12 +814,19 @@ def density(
814814
csrDM = csr.tocsr(dim=0)
815815

816816
if method == "pre-compute":
817-
# Compute orbital values on the grid
818-
psi_values = uc_dm.geometry._orbital_values(grid.shape)
817+
try:
818+
# Compute orbital values on the grid
819+
psi_values = uc_dm.geometry._orbital_values(grid.shape)
819820

820-
psi_values.reduce_orbital_products(
821-
csrDM, uc_dm.lattice, out=grid.grid, **kwargs
822-
)
821+
psi_values.reduce_orbital_products(
822+
csrDM, uc_dm.lattice, out=grid.grid, **kwargs
823+
)
824+
except MemoryError:
825+
raise MemoryError(
826+
"Ran out of memory while computing the density with the 'pre-compute'"
827+
" method. Try using method='direct', which is slower but requires much"
828+
" less memory."
829+
)
823830
elif method == "direct":
824831
self._density_direct(grid, csrDM, atol=atol, eta=eta)
825832

0 commit comments

Comments
 (0)