Skip to content

Commit

Permalink
Merge pull request #13 from MP-Gadget/fixes
Browse files Browse the repository at this point in the history
Fix the build! Enable github action tests!
  • Loading branch information
sbird authored Aug 20, 2024
2 parents 3e7cf2b + 55bbda7 commit ed8af3c
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 34 deletions.
49 changes: 49 additions & 0 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# main test workflow; ported from .travis.yaml
name: main

on:
push:
branches: [ '*', $default-branch ]
pull_request:
branches: [ $default-branch ]

jobs:
build:
runs-on: ubuntu-latest
defaults:
run:
shell: bash -l {0}
strategy:
matrix:
python-version: ['3.10', '3.12']
steps:
- name: Checkout source code
uses: actions/checkout@v4
- name: Install build deps
run: |
sudo apt-get update
sudo apt-get -y install openmpi-bin libopenmpi-dev
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Build
run: |
python -m pip install setuptools wheel nose mpi4py numpy cython build runtests
python -m build
- name: Install
run: |
python -m pip install `ls dist/pfft_python*.whl`
- name: Unit tests
run: |
python ./runtests.py --mpirun="mpirun -np 4"
- name: Roundtrips
run: |
mpirun -n 1 python $PWD/scripts/pfft-roundtrip-matrix.py -v -diag -Nproc 1 1 -Nmesh 13 15 16
mpirun -n 2 python $PWD/scripts/pfft-roundtrip-matrix.py -v -diag -Nproc 2 1 -Nproc 1 2 -Nmesh 13 15 16
#Not enough slots o github for this test.
# mpirun -n 4 python $PWD/scripts/pfft-roundtrip-matrix.py -v -diag -Nproc 2 2 -Nmesh 13 15 16
# mpirun -n 4 python $PWD/scripts/pfft-roundtrip-matrix.py -v -diag -Nproc 2 2 -Nmesh 13 15
- name: Version
run: |
bash check_tag.sh pfft/version.py
12 changes: 6 additions & 6 deletions examples/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@

procmesh = pfft.ProcMesh([4], comm=MPI.COMM_WORLD)
partition = pfft.Partition(
pfft.Type.PFFT_C2C,
[8, 8],
procmesh,
pfft.Type.PFFT_C2C,
[8, 8],
procmesh,
pfft.Flags.PFFT_TRANSPOSED_OUT | pfft.Flags.PFFT_DESTROY_INPUT
)
for irank in range(4):
Expand All @@ -32,7 +32,7 @@
buffer = pfft.LocalBuffer(partition)

plan = pfft.Plan(partition, pfft.Direction.PFFT_FORWARD, buffer)
iplan = pfft.Plan(partition, pfft.Direction.PFFT_BACKWARD, buffer,
iplan = pfft.Plan(partition, pfft.Direction.PFFT_BACKWARD, buffer,
flags=pfft.Flags.PFFT_TRANSPOSED_OUT | pfft.Flags.PFFT_DESTROY_INPUT,
)

Expand All @@ -50,8 +50,8 @@

output = buffer.view_output()

# denormalize the forward transform
output /= numpy.product(partition.n)
# denormalize the forward transform
output /= numpy.prod(partition.n)

iplan.execute(buffer)

Expand Down
9 changes: 9 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[build-system]
requires = [
"setuptools>=42",
"wheel",
"mpi4py",
"Cython", # Ensure Cython is included as a build dependency
"numpy" # It's often necessary to include numpy if using it in setup.py
]
build-backend = "setuptools.build_meta"
26 changes: 13 additions & 13 deletions scripts/pfft-roundtrip-matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
given by -Nmesh. Default is [29, 30, 31].
Tested features are:
regular transform (r2c + c2r, c2c)
transposed in / out,
padded in / out,
transposed in / out,
padded in / out,
destroy input,
inplace transform
inplace transform
Examples:
Expand All @@ -18,7 +18,7 @@
* for single-rank numpy agreement test, run with
mpirun -np 1 python roundtrip.py -Nmesh 32 32 32 -Nmesh 3 3 3 -verbose
* for multi-rank tests, run with
* for multi-rank tests, run with
mpirun -np 4 python roundtrip.py -Nmesh 32 32 32 -Nmesh 3 3 3 --verbose
n can be any number. procmeshes tested are:
Expand All @@ -35,9 +35,9 @@

import os.path

parser = argparse.ArgumentParser(description='Roundtrip testing of pfft',
parser = argparse.ArgumentParser(description='Roundtrip testing of pfft',
epilog=__doc__,
formatter_class=argparse.RawDescriptionHelpFormatter
formatter_class=argparse.RawDescriptionHelpFormatter
)

from pfft import *
Expand Down Expand Up @@ -85,7 +85,7 @@ def test_roundtrip_3d(procmesh, type, flags, inplace, Nmesh):
else:
buf2 = LocalBuffer(partition)

input = buf1.view_input()
input = buf1.view_input()
output = buf2.view_output()

assert input.base == buf1
Expand All @@ -95,7 +95,7 @@ def test_roundtrip_3d(procmesh, type, flags, inplace, Nmesh):
# print 'input', input.shape
forward = Plan(
partition,
Direction.PFFT_FORWARD,
Direction.PFFT_FORWARD,
buf1,
buf2,
type=type,
Expand Down Expand Up @@ -135,10 +135,10 @@ def test_roundtrip_3d(procmesh, type, flags, inplace, Nmesh):

backward = Plan(
partition,
Direction.PFFT_BACKWARD,
Direction.PFFT_BACKWARD,
buf2,
buf1,
type=btype,
type=btype,
flags=bflags,
)
#print(repr(backward))
Expand Down Expand Up @@ -183,7 +183,7 @@ def test_roundtrip_3d(procmesh, type, flags, inplace, Nmesh):
bpreserr = 0.0

if input.size > 0:
input[:] /= numpy.product(Nmesh)
input[:] /= numpy.prod(Nmesh)
# some distributions have no input value
c2rerr = numpy.abs(original - input).max()
else:
Expand All @@ -200,7 +200,7 @@ def test_roundtrip_3d(procmesh, type, flags, inplace, Nmesh):
# print(repr(forward.type), 'preserve', "error = ", fpreserr)
# print(repr(forward.type), 'forward', "error = ", r2cerr)
# print(repr(forward.type), 'backward', "error = ", c2rerr)

fpreserr = MPI.COMM_WORLD.allreduce(fpreserr, MPI.MAX)
bpreserr = MPI.COMM_WORLD.allreduce(bpreserr, MPI.MAX)
r2cerr = MPI.COMM_WORLD.allreduce(r2cerr, MPI.MAX)
Expand Down Expand Up @@ -229,7 +229,7 @@ def main():
Nmesh = ns.Nmesh

if len(Nmesh) == 0:
# default
# default
Nmesh = [[29, 30, 31]]

if MPI.COMM_WORLD.size == 1 and len(ns.Nproc) == 0:
Expand Down
32 changes: 17 additions & 15 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ def build_pfft(prefix, compiler, cflags):
# Avoid enabling SSE2 by default. aarch64 doesn't have it.
# optimize="--enable-sse2"
optimize=""
line = ('CFLAGS="%s -fvisibility=hidden" ' % cflags+
line = ('CFLAGS="%s -fvisibility=hidden -Wno-error=incompatible-pointer-types" ' % cflags+
'MPICC="%s" ' % compiler +
'CC="%s" ' % compiler +
'sh %s/depends/install_pfft.sh ' % package_basedir +
os.path.abspath(prefix) +
' %s' % optimize)
if os.path.exists(os.path.join(prefix,
if os.path.exists(os.path.join(prefix,
'lib', 'libpfft.a')):
return

Expand All @@ -42,10 +42,10 @@ def initialize_options(self):

self.mpicc = os.environ.get('MPICC', compiler)

build_ext.initialize_options(self)
build_ext.initialize_options(self)

def finalize_options(self):
build_ext.finalize_options(self)
build_ext.finalize_options(self)
self.pfft_build_dir = os.path.join(self.build_temp, 'depends')

self.include_dirs.insert(0, os.path.join(
Expand All @@ -56,13 +56,13 @@ def build_extensions(self):
self.compiler.compiler_so[0] = self.mpicc
self.compiler.linker_so[0] = self.mpicc
build_pfft(self.pfft_build_dir, self.mpicc, ' '.join(self.compiler.compiler_so[1:]))
link_objects = [
'libpfft.a',
link_objects = [
'libpfft.a',
'libpfftf.a',
'libfftw3_mpi.a',
'libfftw3.a',
'libfftw3f_mpi.a',
'libfftw3f.a',
'libfftw3_mpi.a',
'libfftw3.a',
'libfftw3f_mpi.a',
'libfftw3f.a',
]

link_objects = [list(glob.glob(os.path.join(self.pfft_build_dir, '*', i)))[0] for i in link_objects]
Expand Down Expand Up @@ -96,19 +96,21 @@ def find_version(path):
install_requires=['cython', 'numpy', 'mpi4py'],
packages= ['pfft', 'pfft.tests'],
requires=['numpy'],
ext_modules = cythonize([Extension(
"pfft.core",
ext_modules = cythonize([Extension(
"pfft.core",
["pfft/core.pyx"],
include_dirs=["./",
include_dirs=["./",
numpy.get_include(),
mpi4py.get_include(),
],
libraries=['m'],
cython_directives = {"embedsignature": True}
)]),
)],
include_path=[os.path.join(mpi4py.get_include(),"../"),],
),
license='GPL3',
scripts=['scripts/pfft-roundtrip-matrix.py'],
cmdclass = {
"build_py":build_py,
"build_ext": build_ext_subclass}
)

0 comments on commit ed8af3c

Please sign in to comment.