Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 19 additions & 61 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,89 +20,47 @@ on:
jobs:
build-linux:
runs-on: ubuntu-latest
defaults:
run:
shell: bash -el {0}
strategy:
max-parallel: 10
fail-fast: false
matrix:
python-version:
- "3.8"
- "3.9"
- "3.10"
- "3.11"
- "3.12"
- "3.13"
conda-env:
- "core"
- "full"
name: Python ${{ matrix.python-version }} and ${{ matrix.conda-env }} dependencies
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
- uses: conda-incubator/setup-miniconda@v3
with:
python-version: ${{ matrix.python-version }}
- name: Add conda to system path
run: |
# $CONDA is an environment variable pointing to the root of the miniconda directory
echo $CONDA/bin >> $GITHUB_PATH
conda --version
conda info
- name: Make sure conda is updated
run: |
conda update conda
conda --version
auto-update-conda: true
auto-activate-base: false
conda-remove-defaults: true
channels: conda-forge
activate-environment: ptypy_env
python-version: ${{ matrix.python-version }}
miniforge-version: latest
- name: Install ${{ matrix.conda-env }} dependencies
run: |
# replace python version in dependencies
sed -i 's/python/python=${{ matrix.python-version }}/' dependencies_${{ matrix.conda-env }}.yml
if [ ${{ matrix.conda-env }} == 'full' ] && [ ${{ matrix.python-version }} == '3.12' ]; then
sed -i '/- pyfftw/d' dependencies_${{ matrix.conda-env }}.yml
fi
# if [ ${{ matrix.conda-env }} == 'full' ] && [ ${{ matrix.python-version }} == '3.8' ]; then
# sed -i '/- mpi4py/d' dependencies_${{ matrix.conda-env }}.yml
# fi
# if [ ${{ matrix.conda-env }} == 'full' ] && [ ${{ matrix.python-version }} == '3.9' ]; then
# sed -i '/- mpi4py/d' dependencies_${{ matrix.conda-env }}.yml
# fi
conda install --solver=classic mpich
conda env update --file dependencies_${{ matrix.conda-env }}.yml --name base
conda install --solver=classic flake8 pytest pytest-cov
conda list
conda install -c conda-forge mpich
conda env update --file dependencies_${{ matrix.conda-env }}.yml --name ptypy_env
conda install -c conda-forge flake8 pytest pytest-cov
conda list
- name: Prepare ptypy
run: |
# Install ptypy
pip install .
run: pip install .
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
# flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
flake8 . --count --select=E9,F63,F7,F82 --ignore=F824 --show-source --statistics
- name: Test with pytest
run: |
# pytest ptypy/test -v --doctest-modules --junitxml=junit/test-results.xml --cov=ptypy --cov-report=xml --cov-report=html --cov-config=.coveragerc
pytest -v
# - name: cobertura-report
# if: github.event_name == 'pull_request' && (github.event.action == 'opened' || github.event.action == 'reopened' || github.event.action == 'synchronize')
# uses: 5monkeys/cobertura-action@v7
# with:
# # The GITHUB_TOKEN for this repo
# repo_token: ${{ secrets.GITHUB_TOKEN }}
# # Path to the cobertura file.
# path: coverage.xml
# # If files with 100% should be skipped from report.
# skip_covered: true
# # Minimum allowed coverage percentage as an integer.
# minimum_coverage: 90
# only_changed_files: true
# - name: Junit Report to Annotations
# uses: ashley-taylor/junit-report-annotations-action@master
# with:
# # github token
# access-token: ${{ secrets.GITHUB_TOKEN }}
# # glob to junit xml files
# path: junit/test-results.xml
# # include summary annotation
# includeSummary: true
# # max number of failed tests to include
# numFailures: 10
run: pytest -v
5 changes: 3 additions & 2 deletions cufft/extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import os, re
import subprocess
import sysconfig
from distutils.unixccompiler import UnixCCompiler
from distutils.command.build_ext import build_ext
from setuptools._distutils.unixccompiler import UnixCCompiler
from setuptools.command.build_ext import build_ext


def find_in_path(name, path):
Expand Down Expand Up @@ -116,6 +116,7 @@ def _compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts):
compiler_command = [self.CUDA["nvcc"]] + self.NVCC_FLAGS + self.OPTFLAGS + ["-Xcompiler"] + self.CXXFLAGS + CPPFLAGS
compiler_exec = " ".join(compiler_command)
self.set_executable('compiler_so', compiler_exec)
self.set_executable('compiler_so_cxx', compiler_exec)
postargs = [] # we don't actually have any postargs
super(NvccCompiler, self)._compile(obj, src, ext, cc_args, postargs, pp_opts) # the _compile method
# reset the default compiler_so, which we might have changed for cuda
Expand Down
2 changes: 1 addition & 1 deletion cufft/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# we should aim to remove the distutils dependency
import setuptools
from distutils.core import setup, Extension
from setuptools import setup, Extension
import os

ext_modules = []
Expand Down
1 change: 1 addition & 0 deletions dependencies_dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ dependencies:
- pyzmq
- pep8
- mpi4py
- packaging
- pillow
- pyfftw
- pip
Expand Down
1 change: 1 addition & 0 deletions dependencies_full.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ dependencies:
- h5py
- pyzmq
- mpi4py
- packaging
- pillow
- pyfftw
- pyyaml
Expand Down
30 changes: 15 additions & 15 deletions doc/script2rst.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import sys
import io
from importlib.resources import files
import contextlib
import os

Expand All @@ -9,13 +10,12 @@
'simupod.py',
'ownengine.py',
'subclassptyscan.py']
_ptypy_dir = files('ptypy')

if len(sys.argv) == 1:
import pkg_resources

for script in scripts:
scr = pkg_resources.resource_filename('ptypy', tutorial_dir+script)
if not os.path.exists(scr):
scr = _ptypy_dir / (tutorial_dir + script)
if not scr.exists():
print('Using backup tutorial for %s' % script)
scr = '../tutorial/'+script
#subprocess.call(['python',sys.argv[0]+' '+scr]) # doesn't work
Expand Down Expand Up @@ -50,13 +50,13 @@ def stdoutIO(stdout=None):
frst.write("""
.. note::
This tutorial was generated from the python source
:file:`[ptypy_root]/tutorial/%(fname)s` using :file:`ptypy/doc/%(this)s`.
:file:`[ptypy_root]/tutorial/%(fname)s` using :file:`ptypy/doc/%(this)s`.
You are encouraged to modify the parameters and rerun the tutorial with::

$ python [ptypy_root]/tutorial/%(fname)s

""" % {'fname': os.path.split(script_name)[-1], 'this': sys.argv[0]})

was_comment = True

while True:
Expand Down Expand Up @@ -86,7 +86,7 @@ def stdoutIO(stdout=None):
frst.write(' '+line2[1:].strip()+'\n')
frst.write('\n')
continue

if line.startswith('"""'):
frst.write('.. parsed-literal::\n\n')
while True:
Expand All @@ -95,11 +95,11 @@ def stdoutIO(stdout=None):
break
frst.write(' ' + line2)
continue

decorator = False
indent = False
for key in indent_keys:
if line.startswith(key):
if line.startswith(key):
indent = True
break

Expand All @@ -125,12 +125,12 @@ def stdoutIO(stdout=None):
pt = fpy.tell()
exec(func+'\n')
continue

wline = line.strip()
if not wline:
frst.write('\n')
continue

with stdoutIO() as sout:
exec(wline)
out = sout.getvalue()
Expand All @@ -150,15 +150,15 @@ def stdoutIO(stdout=None):
if was_comment:
wline = '\n::\n\n'+wline
was_comment = False

frst.write(wline+'\n')

#print out
if out.strip():
print(out)
for l in out.split('\n'):
frst.write(' '*3+l+'\n')
out = ''



18 changes: 12 additions & 6 deletions ptypy/accelerate/base/array_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,20 @@ def complex_gaussian_filter(input, mfs):
'''
takes 2D and 3D arrays. Complex input, complex output. mfs has len 0<x<=2
'''
if len(mfs) > 2:
if isinstance(mfs, list) and len(mfs) > 2:
raise NotImplementedError("Only batches of 2D arrays allowed!")
if isinstance(mfs, (int, float)):
mfs_list = [mfs, mfs]
if input.ndim == 3:
mfs_list = [0, mfs, mfs]
elif isinstance(mfs, (list,tuple)):
mfs_list = list(mfs)
if input.ndim == 3:
mfs_list.insert(0,0)
else:
raise NotImplementedError(f"Cannot interpret mfs of type {type(mfs)}")

if input.ndim == 3:
mfs = np.insert(mfs, 0, 0)

return (ndi.gaussian_filter(np.real(input), mfs) + 1j * ndi.gaussian_filter(np.imag(input), mfs)).astype(
input.dtype)
return (ndi.gaussian_filter(np.real(input), mfs_list).astype(input.dtype) + 1j * ndi.gaussian_filter(np.imag(input), mfs_list))


def complex_gaussian_filter_fft(input, mfs):
Expand Down
Loading
Loading