Skip to content

Commit

Permalink
Clarify out of memory error on density
Browse files Browse the repository at this point in the history
I have been testing the limits and for 10000 orbitals numpy needs to allocate 23GiB, which is too much for my RAM, and it fails.

It then throws a `numpy.core._exceptions._ArrayMemoryError`, which a user might not understand how to solve. Here we raise a clearer error for the user that is trying to compute the density.

It takes veeery long to compute such a system with the direct method, but at least it can be computed.
  • Loading branch information
pfebrer authored Jun 20, 2024
1 parent 3979468 commit c2c8aa0
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/sisl/physics/densitymatrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -814,12 +814,19 @@ def density(
csrDM = csr.tocsr(dim=0)

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

psi_values.reduce_orbital_products(
csrDM, uc_dm.lattice, out=grid.grid, **kwargs
)
psi_values.reduce_orbital_products(
csrDM, uc_dm.lattice, out=grid.grid, **kwargs
)
except MemoryError:
raise MemoryError(
"Ran out of memory while computing the density with the 'pre-compute'"
" method. Try using method='direct', which is slower but requires much"
" less memory."
)
elif method == "direct":
self._density_direct(grid, csrDM, atol=atol, eta=eta)

Expand Down

0 comments on commit c2c8aa0

Please sign in to comment.