diff --git a/.ci_support/environment-openmpi-mac.yml b/.ci_support/environment-openmpi-mac.yml new file mode 100644 index 0000000..38a33e3 --- /dev/null +++ b/.ci_support/environment-openmpi-mac.yml @@ -0,0 +1,11 @@ +channels: +- conda-forge +dependencies: +- coverage +- lammps =2024.06.27=*_mpi_openmpi_* +- openmpi =4.1.6 +- numpy =1.26.4 +- mpi4py =3.1.6 +- executorlib =1.6.0 +- ase =3.25.0 +- scipy =1.15.2 \ No newline at end of file diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.yml index 3576a8e..7b29186 100644 --- a/.github/workflows/pipeline.yml +++ b/.github/workflows/pipeline.yml @@ -89,7 +89,7 @@ jobs: pip install . --no-deps --no-build-isolation pip check - unittest_mpich: + unittest_linux_mpich: needs: [black] runs-on: ubuntu-latest strategy: @@ -113,7 +113,28 @@ jobs: pip install . --no-deps --no-build-isolation python -m unittest discover tests - unittest_openmpi: + unittest_mac_mpich: + needs: [black] + runs-on: macos-latest + steps: + - uses: actions/checkout@v4 + - name: Conda config + run: echo -e "channels:\n - conda-forge\n" > .condarc + - uses: conda-incubator/setup-miniconda@v3 + with: + python-version: '3.12' + miniforge-version: latest + condarc-file: .condarc + environment-file: .ci_support/environment-mpich.yml + - name: Test + shell: bash -l {0} + timeout-minutes: 5 + run: | + pip install versioneer[toml]==0.29 + pip install . --no-deps --no-build-isolation + python -m unittest discover tests + + unittest_linux_openmpi: needs: [black] runs-on: ubuntu-latest strategy: @@ -137,6 +158,27 @@ jobs: pip install . --no-deps --no-build-isolation python -m unittest discover tests + unittest_mac_openmpi: + needs: [black] + runs-on: macos-latest + steps: + - uses: actions/checkout@v4 + - name: Conda config + run: echo -e "channels:\n - conda-forge\n" > .condarc + - uses: conda-incubator/setup-miniconda@v3 + with: + python-version: '3.12' + miniforge-version: latest + condarc-file: .condarc + environment-file: .ci_support/environment-openmpi-mac.yml + - name: Test + shell: bash -l {0} + timeout-minutes: 5 + run: | + pip install versioneer[toml]==0.29 + pip install . --no-deps --no-build-isolation + python -m unittest discover tests + unittest_old: needs: [black] runs-on: ubuntu-latest @@ -159,7 +201,7 @@ jobs: python -m unittest discover tests autobot: - needs: [unittest_old, unittest_openmpi, unittest_mpich, pip_check, coverage] + needs: [unittest_old, unittest_linux_openmpi, unittest_mac_openmpi, unittest_mac_mpich, unittest_linux_mpich, pip_check, coverage] permissions: contents: write pull-requests: write diff --git a/pylammpsmpi/wrapper/ase.py b/pylammpsmpi/wrapper/ase.py index 2fa4ac5..bd9f63f 100644 --- a/pylammpsmpi/wrapper/ase.py +++ b/pylammpsmpi/wrapper/ase.py @@ -36,6 +36,7 @@ def __init__( log_file: Optional[str] = None, library: Optional[object] = None, disable_log_file: bool = True, + hostname_localhost: bool = False, ): self._logger = logger self._prism = None @@ -60,7 +61,9 @@ def __init__( ) else: self._interactive_library = LammpsBase( - cores=self._cores, working_directory=working_directory + cores=self._cores, + working_directory=working_directory, + hostname_localhost=hostname_localhost, ) def interactive_lib_command(self, command: str) -> None: diff --git a/pylammpsmpi/wrapper/concurrent.py b/pylammpsmpi/wrapper/concurrent.py index 377465b..352a986 100644 --- a/pylammpsmpi/wrapper/concurrent.py +++ b/pylammpsmpi/wrapper/concurrent.py @@ -31,6 +31,7 @@ def execute_async( cmdargs: Optional[list[str]] = None, cores: int = 1, oversubscribe: bool = False, + hostname_localhost: bool = False, cwd: Optional[str] = None, ) -> None: """ @@ -59,10 +60,12 @@ def execute_async( cores=cores, openmpi_oversubscribe=oversubscribe, ), + hostname_localhost=hostname_localhost, ) while True: task_dict = future_queue.get() if "shutdown" in task_dict and task_dict["shutdown"]: + future_queue.task_done() interface.shutdown(wait=task_dict["wait"]) break elif "command" in task_dict and "future" in task_dict: @@ -73,6 +76,7 @@ def execute_async( except Exception as error: f.set_exception(error) break + future_queue.task_done() class LammpsConcurrent: @@ -82,6 +86,7 @@ def __init__( oversubscribe: bool = False, working_directory: str = ".", cmdargs: list = None, + hostname_localhost: bool = False, ): """ Initialize the LammpsConcurrent object. @@ -106,6 +111,7 @@ def __init__( self._future_queue = Queue() self._process = None self._oversubscribe = oversubscribe + self._hostname_localhost = hostname_localhost self._cmdargs = cmdargs self._start_process() @@ -118,6 +124,7 @@ def _start_process(self): "cores": self.cores, "oversubscribe": self._oversubscribe, "cwd": self.working_directory, + "hostname_localhost": self._hostname_localhost, }, ) self._process.start() diff --git a/pylammpsmpi/wrapper/extended.py b/pylammpsmpi/wrapper/extended.py index 4e87f19..1cec120 100644 --- a/pylammpsmpi/wrapper/extended.py +++ b/pylammpsmpi/wrapper/extended.py @@ -257,6 +257,7 @@ def __init__( client: Any = None, mode: str = "local", cmdargs: Optional[list[str]] = None, + hostname_localhost: bool = False, ) -> None: self.cores = cores self.working_directory = working_directory @@ -268,6 +269,7 @@ def __init__( oversubscribe=self.oversubscribe, working_directory=self.working_directory, cmdargs=cmdargs, + hostname_localhost=hostname_localhost, ) def __getattr__(self, name: str) -> Any: diff --git a/tests/test_ase_interface.py b/tests/test_ase_interface.py index 82296a0..9ef6547 100644 --- a/tests/test_ase_interface.py +++ b/tests/test_ase_interface.py @@ -1,4 +1,5 @@ import logging +import sys import unittest import numpy as np @@ -27,6 +28,7 @@ def test_static(self): log_file=None, library=LammpsLibrary(cores=2, mode="local"), disable_log_file=True, + hostname_localhost=True, ) structure = bulk("Al", cubic=True).repeat([2, 2, 2]) lmp.interactive_structure_setter( @@ -86,6 +88,7 @@ def test_small_displacement(self): log_file=None, library=LammpsLibrary(cores=2, mode="local"), disable_log_file=True, + hostname_localhost=True, ) structure = bulk("Al", cubic=True) lmp.interactive_structure_setter( @@ -121,6 +124,7 @@ def test_small_displacement(self): np.all(np.isclose(lmp.interactive_positions_getter(), positions)) ) + @unittest.skipIf(sys.platform == "darwin", "This test is not supported on MacOs") def test_small_displacement_skewed(self): lmp = LammpsASELibrary( working_directory=None, @@ -130,6 +134,7 @@ def test_small_displacement_skewed(self): log_file=None, library=LammpsLibrary(cores=2, mode="local"), disable_log_file=True, + hostname_localhost=True, ) structure = bulk("Al").repeat([2, 2, 2]) lmp.interactive_structure_setter( @@ -175,6 +180,7 @@ def test_static_with_statement(self): log_file=None, library=None, disable_log_file=True, + hostname_localhost=True, ) as lmp: lmp.interactive_structure_setter( structure=structure, @@ -419,6 +425,7 @@ def test_individual_calculation(self): log_file=None, library=LammpsLibrary(cores=2, mode="local"), disable_log_file=True, + hostname_localhost=True, ) lmp.interactive_structure_setter( structure=structure, @@ -444,6 +451,7 @@ def test_interactive_calculation(self): log_file=None, library=LammpsLibrary(cores=2, mode="local"), disable_log_file=True, + hostname_localhost=True, ) for structure in self.structure_lst: lmp.interactive_structure_setter( @@ -470,6 +478,7 @@ def test_interactive_calculation_inverse(self): log_file=None, library=LammpsLibrary(cores=2, mode="local"), disable_log_file=True, + hostname_localhost=True, ) for structure in self.structure_lst[::-1]: lmp.interactive_structure_setter( diff --git a/tests/test_base.py b/tests/test_base.py index cba9c24..315f0e3 100644 --- a/tests/test_base.py +++ b/tests/test_base.py @@ -20,6 +20,7 @@ def setUpClass(cls): oversubscribe=False, working_directory=".", cmdargs=["-cite", cls.citation_file], + hostname_localhost=True, ) cls.lmp.file(cls.lammps_file) @@ -33,6 +34,7 @@ def test_file_not_found(self): oversubscribe=False, working_directory=".", cmdargs=["-cite", self.citation_file], + hostname_localhost=True, ) with self.assertRaises(FileNotFoundError): lmp.file("file_does_not_exist.txt") diff --git a/tests/test_concurrent.py b/tests/test_concurrent.py index a93584c..399a39b 100644 --- a/tests/test_concurrent.py +++ b/tests/test_concurrent.py @@ -17,6 +17,7 @@ def setUpClass(cls): oversubscribe=False, working_directory=".", cmdargs=["-cite", cls.citation_file], + hostname_localhost=True, ) cls.lmp.file(cls.lammps_file).result() diff --git a/tests/test_executor.py b/tests/test_executor.py index 0651591..30ddacf 100644 --- a/tests/test_executor.py +++ b/tests/test_executor.py @@ -18,6 +18,7 @@ def calc_lmp(structure): log_file=None, library=None, disable_log_file=True, + hostname_localhost=True, ) lmp.interactive_structure_setter( structure=structure,