From 76ac65b33145cca1cc77d38d41894c71c2a0a830 Mon Sep 17 00:00:00 2001 From: ifilot Date: Sun, 15 Dec 2024 08:37:51 +0100 Subject: [PATCH] Fixing bug in parallellization --- .github/workflows/docs.yml | 2 +- docs/scripts/00-verbose.py | 4 ++-- examples/doc.py | 16 ++++++++++++++++ meta.yaml | 2 +- pydft/_version.py | 2 +- pydft/moleculargrid.py | 14 ++++++++++---- pyproject.toml | 2 +- 7 files changed, 32 insertions(+), 10 deletions(-) create mode 100644 examples/doc.py diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 56bbdf0..72ba1f1 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -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 diff --git a/docs/scripts/00-verbose.py b/docs/scripts/00-verbose.py index 26d627a..f37538d 100644 --- a/docs/scripts/00-verbose.py +++ b/docs/scripts/00-verbose.py @@ -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) \ No newline at end of file +dft = DFT(co, basis='sto3g') +en = dft.scf(1e-5, verbose=True) \ No newline at end of file diff --git a/examples/doc.py b/examples/doc.py new file mode 100644 index 0000000..f790242 --- /dev/null +++ b/examples/doc.py @@ -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) \ No newline at end of file diff --git a/meta.yaml b/meta.yaml index 4786f34..06a4113 100644 --- a/meta.yaml +++ b/meta.yaml @@ -1,6 +1,6 @@ package: name: "pydft" - version: "0.7.0" + version: "0.7.1" source: path: . diff --git a/pydft/_version.py b/pydft/_version.py index a71c5c7..f0788a8 100644 --- a/pydft/_version.py +++ b/pydft/_version.py @@ -1 +1 @@ -__version__ = '0.7.0' +__version__ = '0.7.1' diff --git a/pydft/moleculargrid.py b/pydft/moleculargrid.py index fe61fb9..67c53d7 100644 --- a/pydft/moleculargrid.py +++ b/pydft/moleculargrid.py @@ -10,6 +10,7 @@ import multiprocessing from .xcfunctionals import Functionals from functools import partial +import platform class MolecularGrid: def __init__(self, @@ -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): """ @@ -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 diff --git a/pyproject.toml b/pyproject.toml index 1c47938..dd0ff03 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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" } ]