Skip to content

Commit

Permalink
Merge pull request #272 from pyiron/main
Browse files Browse the repository at this point in the history
merge main
  • Loading branch information
jan-janssen authored Feb 18, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
2 parents 12eb452 + d9edd2d commit f5dfa73
Showing 6 changed files with 129 additions and 6 deletions.
57 changes: 57 additions & 0 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# This workflow is used to run the unittest of pyiron

name: Benchmark

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
build:

runs-on: ${{ matrix.operating-system }}
strategy:
matrix:
include:
- operating-system: ubuntu-latest
python-version: '3.12'
label: linux-64-py-3-12-openmpi
prefix: /Users/runner/miniconda3/envs/my-env
environment-file: .ci_support/environment-openmpi.yml

- operating-system: ubuntu-latest
python-version: '3.12'
label: linux-64-py-3-12-mpich
prefix: /usr/share/miniconda3/envs/my-env
environment-file: .ci_support/environment-mpich.yml

steps:
- uses: actions/checkout@v2
- uses: conda-incubator/[email protected]
with:
python-version: ${{ matrix.python-version }}
mamba-version: "*"
channels: conda-forge
miniforge-variant: Mambaforge
channel-priority: strict
auto-update-conda: true
environment-file: ${{ matrix.environment-file }}
- name: Test
shell: bash -l {0}
timeout-minutes: 10
run: |
pip install versioneer[toml]==0.29
pip install . --no-deps --no-build-isolation
python tests/benchmark/llh.py static >> timing.log
python tests/benchmark/llh.py process >> timing.log
python tests/benchmark/llh.py thread >> timing.log
mpiexec -n 4 python -m mpi4py.futures tests/benchmark/llh.py mpi4py >> timing.log
python tests/benchmark/llh.py pympipool >> timing.log
cat timing.log
python -m unittest tests/benchmark/test_results.py
env:
OMPI_MCA_plm: 'isolated'
OMPI_MCA_rmaps_base_oversubscribe: 'yes'
OMPI_MCA_btl_vader_single_copy_mechanism: 'none'
2 changes: 1 addition & 1 deletion .github/workflows/unittest-flux.yml
Original file line number Diff line number Diff line change
@@ -63,5 +63,5 @@ jobs:
OMPI_MCA_rmaps_base_oversubscribe: 'yes'
OMPI_MCA_btl_vader_single_copy_mechanism: 'none'
- name: Coveralls
if: matrix.label == 'linux-64-py-3-11-openmpi'
if: matrix.label == 'linux-64-py-3-12-openmpi'
uses: coverallsapp/github-action@v2
11 changes: 7 additions & 4 deletions pympipool/shared/interface.py
Original file line number Diff line number Diff line change
@@ -98,10 +98,13 @@ def generate_command(self, command_lst):


def generate_mpiexec_command(cores, oversubscribe=False):
command_prepend_lst = [MPI_COMMAND, "-n", str(cores)]
if oversubscribe:
command_prepend_lst += ["--oversubscribe"]
return command_prepend_lst
if cores == 1:
return []
else:
command_prepend_lst = [MPI_COMMAND, "-n", str(cores)]
if oversubscribe:
command_prepend_lst += ["--oversubscribe"]
return command_prepend_lst


def generate_slurm_command(
1 change: 0 additions & 1 deletion pympipool/slurm/executor.py
Original file line number Diff line number Diff line change
@@ -23,7 +23,6 @@ class PySlurmExecutor(ExecutorBase):
oversubscribe (bool): adds the `--oversubscribe` command line flag (OpenMPI only) - default False
init_function (None): optional function to preset arguments for functions which are submitted later
cwd (str/None): current working directory where the parallel python task is executed
sleep_interval (float): synchronization interval - default 0.1
hostname_localhost (boolean): use localhost instead of the hostname to establish the zmq connection. In the
context of an HPC cluster this essential to be able to communicate to an
Executor running on a different compute node within the same allocation. And
47 changes: 47 additions & 0 deletions tests/benchmark/llh.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import sys
from time import time


def llh_numpy(mean, sigma):
import numpy
data = numpy.random.normal(size=100000000).astype('float64')
s = (data - mean) ** 2 / (2 * (sigma ** 2))
pdfs = numpy.exp(- s)
pdfs /= numpy.sqrt(2 * numpy.pi) * sigma
return numpy.log(pdfs).sum()


def run_with_executor(executor=None, mean=0.1, sigma=1.1, runs=32, **kwargs):
with executor(**kwargs) as exe:
future_lst = [exe.submit(llh_numpy, mean=mean, sigma=sigma) for i in range(runs)]
return [f.result() for f in future_lst]


def run_static(mean=0.1, sigma=1.1, runs=32):
return [llh_numpy(mean=mean, sigma=sigma) for i in range(runs)]


if __name__ == "__main__":
run_mode = sys.argv[1]
start_time = time()
if run_mode == "static":
run_static(mean=0.1, sigma=1.1, runs=32)
elif run_mode == "process":
from concurrent.futures import ProcessPoolExecutor
run_with_executor(executor=ProcessPoolExecutor, mean=0.1, sigma=1.1, runs=32, max_workers=4)
elif run_mode == "thread":
from concurrent.futures import ThreadPoolExecutor
run_with_executor(executor=ThreadPoolExecutor, mean=0.1, sigma=1.1, runs=32, max_workers=4)
elif run_mode == "pympipool":
from pympipool.mpi.executor import PyMPIExecutor
run_with_executor(executor=PyMPIExecutor, mean=0.1, sigma=1.1, runs=32, max_workers=4)
elif run_mode == "flux":
from pympipool.flux.executor import PyFluxExecutor
run_with_executor(executor=PyFluxExecutor, mean=0.1, sigma=1.1, runs=32, max_workers=4)
elif run_mode == "mpi4py":
from mpi4py.futures import MPIPoolExecutor
run_with_executor(executor=MPIPoolExecutor, mean=0.1, sigma=1.1, runs=32, max_workers=4)
else:
raise ValueError(run_mode)
stop_time = time()
print(run_mode, stop_time-start_time)
17 changes: 17 additions & 0 deletions tests/benchmark/test_results.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import unittest


class TestResults(unittest.TestCase):
def test_result(self):
with open("timing.log") as f:
content = f.readlines()
timing_dict = {l.split()[0]: float(l.split()[1]) for l in content}
self.assertEqual(min(timing_dict, key=timing_dict.get), "process")
self.assertEqual(max(timing_dict, key=timing_dict.get), "static")
self.assertTrue(timing_dict["process"] < timing_dict["pympipool"])
self.assertTrue(timing_dict["pympipool"] < timing_dict["process"] * 1.1)
self.assertTrue(timing_dict["process"] < timing_dict["mpi4py"])
self.assertTrue(timing_dict["pympipool"] < timing_dict["mpi4py"])
self.assertTrue(timing_dict["mpi4py"] < timing_dict["process"] * 1.15)
self.assertTrue(timing_dict["thread"] < timing_dict["static"])
self.assertTrue(timing_dict["mpi4py"] < timing_dict["thread"])

0 comments on commit f5dfa73

Please sign in to comment.