Skip to content

Commit

Permalink
merging changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Sworzzy committed Sep 24, 2024
2 parents eb54321 + a16f7f8 commit 72c7af5
Show file tree
Hide file tree
Showing 12 changed files with 78 additions and 28 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ jobs:
- name: Set default MPI and HDF5 C compilers on Ubuntu
if: matrix.os == 'ubuntu-latest'
run: |
sudo apt-get update
sudo apt-get install --reinstall openmpi-bin libhdf5-openmpi-dev
- name: Install non-Python dependencies on macOS
Expand Down Expand Up @@ -159,9 +160,9 @@ jobs:
python -m pip install .
python -m pip freeze
- name: Test pyccel optimization flags
- name: Test Pyccel optimization flags
run: |
pyccel --verbose ./psydac/linalg/kernels/axpy_kernels.py
pytest --pyargs psydac -m pyccel --capture=no
- name: Initialize test directory
run: |
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ jobs:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN}}
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: 3.9
- name: Install non-Python dependencies on Ubuntu
Expand All @@ -37,9 +37,9 @@ jobs:
make -C docs html
python docs/update_links.py
- name: Setup Pages
uses: actions/configure-pages@v3
uses: actions/configure-pages@v5
- name: Upload artifact
uses: actions/upload-pages-artifact@v1
uses: actions/upload-pages-artifact@v3
with:
path: 'docs/build/html'

Expand All @@ -53,4 +53,4 @@ jobs:
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v2
uses: actions/deploy-pages@v4
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ __test__/
# pycharm directory
.idea

#macOs
# macOS
*/.DS_Store
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ python3 <PSYDAC-PATH>/mpi_tester.py --pyargs psydac -m "parallel and petsc"

Many of Psydac's low-level Python functions can be translated to a compiled language using the [Pyccel](https://github.com/pyccel/pyccel) transpiler. Currently, all of those functions are collected in modules which follow the name pattern `[module]_kernels.py`.
The classical installation translates all kernel files to Fortran without user intervention. This does not happen in the case of an editable install, but the command `psydac-accelerate` is made available to the user instead. This command applies Pyccel to all the kernel files in the source directory, and the C language may be selected instead of Fortran (which is the default).
The classical installation translates all kernel files to Fortran without user intervention. This does not happen in the case of an editable install, but the command `psydac-accelerate` is made available to the user instead. This command applies Pyccel to all the kernel files in the source directory. The default language is currently Fortran, C should also be supported in a near future.
- **Only in development mode**:
```bash
Expand Down
2 changes: 1 addition & 1 deletion psydac/api/ast/glt.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
from sympde.topology import LogicalExpr
from sympde.topology import SymbolicExpr
from sympde.calculus.matrices import SymbolicDeterminant
from sympde.topology.analytic_mappings import IdentityMapping
from sympde.topology.analytic_mappings import IdentityMapping

from sympde.expr.evaluation import TerminalExpr

Expand Down
19 changes: 15 additions & 4 deletions psydac/api/settings.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# coding: utf-8
import subprocess # nosec B404
import platform
import re
from packaging.version import Version


__all__ = ('PSYDAC_DEFAULT_FOLDER', 'PSYDAC_BACKENDS')
Expand Down Expand Up @@ -40,18 +43,26 @@
'openmp' : False}
# ...

# Get gfortran version
gfortran_version_output = subprocess.check_output(['gfortran', '--version']).decode('utf-8') # nosec B603, B607
gfortran_version_string = re.search("(\d+\.\d+\.\d+)", gfortran_version_output).group()
gfortran_version = Version(gfortran_version_string)

# Platform-dependent flags
if platform.system() == "Darwin" and platform.machine() == 'arm64':
if platform.system() == "Darwin" and platform.machine() == 'arm64' and gfortran_version >= Version("14"):

# Apple silicon requires architecture-specific flags (see https://github.com/pyccel/psydac/pull/411)
import subprocess # nosec B404
# which are only available on GCC version >= 14
cpu_brand = subprocess.check_output(['sysctl','-n','machdep.cpu.brand_string']).decode('utf-8') # nosec B603, B607
if "Apple M1" in cpu_brand:
PSYDAC_BACKEND_GPYCCEL['flags'] += ' -mcpu=apple-m1'
if "Apple M1" in cpu_brand: PSYDAC_BACKEND_GPYCCEL['flags'] += ' -mcpu=apple-m1'
elif "Apple M2" in cpu_brand: PSYDAC_BACKEND_GPYCCEL['flags'] += ' -mcpu=apple-m2'
elif "Apple M3" in cpu_brand: PSYDAC_BACKEND_GPYCCEL['flags'] += ' -mcpu=apple-m3'
else:
# TODO: Support later Apple CPU models. Perhaps the CPU naming scheme could be easily guessed
# based on the output of 'sysctl -n machdep.cpu.brand_string', but I wouldn't rely on this
# guess unless it has been manually verified. Loud errors are better than silent failures!
raise SystemError(f"Unsupported Apple CPU '{cpu_brand}'.")

else:
# Default architecture flags
PSYDAC_BACKEND_GPYCCEL['flags'] += ' -march=native -mtune=native'
Expand Down
11 changes: 10 additions & 1 deletion psydac/api/tests/test_api_feec_2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ def run_maxwell_2d_TE(*, use_spline_mapping,
from sympde.topology import Domain
from sympde.topology import Square

from sympde.topology import CollelaMapping2D, BaseAnalyticMapping
from sympde.topology import BaseAnalyticMapping #, CollelaMapping2D

from sympde.topology import Derham
from sympde.topology import elements_of
Expand Down Expand Up @@ -280,6 +280,15 @@ def run_maxwell_2d_TE(*, use_spline_mapping,
else:
# Logical domain is unit square [0, 1] x [0, 1]
logical_domain = Square('Omega')

# WARNING: this Collela mapping is not the same as in SymPDE
class CollelaMapping2D(BaseAnalyticMapping):

_ldim = 2
_pdim = 2
_expressions = {'x': 'a * (x1 + eps / (2*pi) * sin(2*pi*x1) * sin(2*pi*x2))',
'y': 'b * (x2 + eps / (2*pi) * sin(2*pi*x1) * sin(2*pi*x2))'}

mapping = CollelaMapping2D('M1', a=a, b=b, eps=eps)
domain = mapping(logical_domain)

Expand Down
35 changes: 35 additions & 0 deletions psydac/api/tests/test_epyccel_flags.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import pytest


@pytest.mark.pyccel
def test_epyccel_flags():

from pyccel.epyccel import epyccel
from psydac.api.settings import PSYDAC_BACKEND_GPYCCEL as backend

kwargs = {'language' : 'fortran',
'compiler' : backend['compiler'],
'fflags' : backend['flags'],
'accelerators' : ['openmp'] if backend['openmp'] else [],
'verbose' : True,
}

# Function to be Pyccel-ized
def f(x : float):
return 3 * x

# Pyccel magic
# ------------
# Fortran code is generated and then compiled with the selected compiler.
# The compiled function is callable from Python through the C Python API.
# The necessary C wrapper functions are also generated by Pyccel.
fast_f = epyccel(f, **kwargs)

# Check output of pyccelized function
assert fast_f(3.5) == f(3.5)


# Interactive usage
if __name__ == '__main__':
test_epyccel_flags()
print('PASSED')
2 changes: 1 addition & 1 deletion psydac/fem/tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ def eval_fields(self, grid, *fields, weights=None, npts_per_cell=None, overlap=0
npts_per_cell = (npts_per_cell,) * self.ldim
for i in range(self.ldim):
ncells_i = len(self.breaks[i]) - 1
grid[i] = np.reshape(grid[i], newshape=(ncells_i, npts_per_cell[i]))
grid[i] = np.reshape(grid[i], (ncells_i, npts_per_cell[i]))
out_fields = self.eval_fields_regular_tensor_grid(grid, *fields, weights=weights, overlap=overlap)
# return a list
return [np.ascontiguousarray(out_fields[..., i]) for i in range(len(fields))]
Expand Down
6 changes: 3 additions & 3 deletions psydac/mapping/discrete.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ def jac_mat_grid(self, grid, npts_per_cell=None, overlap=0):
npts_per_cell = (npts_per_cell,) * self.ldim
for i in range(self.ldim):
ncells_i = len(self.space.breaks[i]) - 1
grid[i] = np.reshape(grid[i], newshape=(ncells_i, npts_per_cell[i]))
grid[i] = np.reshape(grid[i], (ncells_i, npts_per_cell[i]))
jac_mats = self.jac_mat_regular_tensor_grid(grid, overlap=overlap)
return jac_mats

Expand Down Expand Up @@ -465,7 +465,7 @@ def inv_jac_mat_grid(self, grid, npts_per_cell=None, overlap=0):
npts_per_cell = (npts_per_cell,) * self.ldim
for i in range(self.ldim):
ncells_i = len(self.space.breaks[i]) - 1
grid[i] = np.reshape(grid[i], newshape=(ncells_i, npts_per_cell[i]))
grid[i] = np.reshape(grid[i], (ncells_i, npts_per_cell[i]))
inv_jac_mats = self.inv_jac_mat_regular_tensor_grid(grid, overlap=overlap)
return inv_jac_mats

Expand Down Expand Up @@ -636,7 +636,7 @@ def jac_det_grid(self, grid, npts_per_cell=None, overlap=0):
npts_per_cell = (npts_per_cell,) * self.ldim
for i in range(self.ldim):
ncells_i = len(self.space.breaks[i]) - 1
grid[i] = np.reshape(grid[i], newshape=(ncells_i, npts_per_cell[i]))
grid[i] = np.reshape(grid[i], (ncells_i, npts_per_cell[i]))
jac_dets = self.jac_det_regular_tensor_grid(grid, overlap=overlap)
return jac_dets

Expand Down
11 changes: 2 additions & 9 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ dependencies = [
'pyevtk',

# Our packages from PyPi
'sympde == 0.19.0',
'sympde @ https://github.com/pyccel/sympde/archive/refs/heads/new-mapping-hierarchy-lagarrigue.zip',
'pyccel >= 1.11.2',
'gelato == 0.12',

Expand All @@ -49,15 +49,8 @@ dependencies = [
# tracebacks, which allows mpi4py to broadcast exceptions
'tblib',

# SYMPDE - development version
# 'sympde @ https://github.com/pyccel/sympde/archive/refs/heads/master.zip'

# IGAKIT - not on PyPI

# !! WARNING !! Path to igakit below is from fork pyccel/igakit. This was done to
# quickly fix the numpy 2.0 issue. See https://github.com/dalcinl/igakit/pull/4
# !! WARNING !! commenting igakit to support python 3.12
# 'igakit @ https://github.com/pyccel/igakit/archive/refs/heads/bugfix-numpy2.0.zip'
'igakit @ https://github.com/dalcinl/igakit/archive/refs/heads/master.zip'
]

[project.urls]
Expand Down
1 change: 1 addition & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ markers =
serial: single-process test,
parallel: test to be run using 'mpiexec',
petsc: test requiring a working PETSc installation with petsc4py Python bindings
pyccel: test for checking Pyccel setup on machine

python_files = test_*.py
python_classes =
Expand Down

0 comments on commit 72c7af5

Please sign in to comment.