Skip to content

Commit

Permalink
Merge pull request #5 from ifilot/develop
Browse files Browse the repository at this point in the history
Fixing bug in parallelization
  • Loading branch information
ifilot authored Dec 15, 2024
2 parents 9e36de6 + 76ac65b commit 0c7599f
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
run: cd docs && make html
- name: Upload math result for job 1
uses: actions/upload-artifact@v3
with:
with:
name: html-docs
path: ./docs/_build/html

Expand Down
4 changes: 2 additions & 2 deletions docs/scripts/00-verbose.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@

# perform DFT calculation on the CO molecule
co = MoleculeBuilder().from_name("CO")
dft = DFT(co, basis='sto3g', verbose=True)
en = dft.scf(1e-5)
dft = DFT(co, basis='sto3g')
en = dft.scf(1e-5, verbose=True)
16 changes: 16 additions & 0 deletions examples/doc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import numpy as np
import sys,os

# add a reference to load the module
ROOT = os.path.dirname(__file__)
sys.path.insert(1, os.path.join(ROOT, '..'))

from pydft import MoleculeBuilder, DFT
import pydft

print(pydft.__version__)

# perform DFT calculation on the CO molecule
co = MoleculeBuilder().from_name("CO")
dft = DFT(co, basis='sto3g', parallel=True)
en = dft.scf(1e-5, verbose=True)
2 changes: 1 addition & 1 deletion meta.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package:
name: "pydft"
version: "0.7.0"
version: "0.7.1"

source:
path: .
Expand Down
2 changes: 1 addition & 1 deletion pydft/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.7.0'
__version__ = '0.7.1'
14 changes: 10 additions & 4 deletions pydft/moleculargrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import multiprocessing
from .xcfunctionals import Functionals
from functools import partial
import platform

class MolecularGrid:
def __init__(self,
Expand Down Expand Up @@ -56,7 +57,7 @@ def __init__(self,
self.__basis = cgfs
self.__functionals = Functionals(functional)
self.__is_initialized = False
self.__enable_parallel = True
self.__enable_parallel = parallel

def initialize(self):
"""
Expand Down Expand Up @@ -848,15 +849,20 @@ def __build_molecular_grid(self, build_parallel=False):
(self.__lmax+1)**2,
np.prod(self.__mweights.shape)))

# perform parallellized calculation of spherical harmonics
if build_parallel:
# perform parallellized calculation of spherical harmonics; this
# unfortunately only works on Linux
if build_parallel and platform.system() != "Windows":
atoms = list(range(len(self.__atoms)))
inputs = zip([self.__theta_gridpoints[i,:] for i in atoms],
[self.__phi_gridpoints[i,:] for i in atoms])
calculate_partial = partial(self.build_ylmgpts_atom,
lmax=self.__lmax,
npts=np.prod(self.__mweights.shape))
with multiprocessing.Pool(processes=multiprocessing.cpu_count()) as pool:

# only parallellize over the atoms
ncpu = min(multiprocessing.cpu_count(), len(self.__atoms))

with multiprocessing.Pool(processes=ncpu) as pool:
result = pool.map(calculate_partial, inputs)
for i,res in enumerate(result):
self.__ylmgpts[i,:,:] = res
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "pydft"
version = "0.7.0"
version = "0.7.1"
authors = [
{ name="Ivo Filot", email="ivo@ivofilot.nl" }
]
Expand Down

0 comments on commit 0c7599f

Please sign in to comment.