Skip to content

Commit

Permalink
Cubic uniform splines (#44)
Browse files Browse the repository at this point in the history
The selalib code uses splines optimised for uniform knots and degree 3. This makes it significantly faster than the splines used in pygyro. This PR adds the optimised splines. The tests and simulation now run 2-5 times faster.

As per h5py/h5py#2222 the installation workflow is also modified to fix the h5py installation

* Allocate memory once

* Use same code optimisations for all three accelerators. Rename functions to indicate non-uniform

* Add specialised versions

* Add flag to switch between codes

* Rename functions

* Improve stack array

* Add vector function to spline to avoid unnecessary allocation. Make cubic_uniform_splines bspline-dependent

* Update requirements for new pip standard

* Update requirements for new pip standard

* Pep

* Upgrade versions

* No problem

* Try for newer

* Newer pep

* CODACY

* Hypy needs specific mpi4py

* Lower python version

* Pep

* New pep style

* Update cache version

* Revert changes

* Add new arg

* Correct formulae

* Restrict uniform usage

* Copy changes across languages

* PEP

* Correct errors

* Use new args

* PEP

* Correct indentation

* Better compile time

* Correct numba files

* Correct names

* Examine tests

* Use analytical profile

* Check derivative

* Add derivative test

* Correct calculation

* Remove unnecessary line

* Update numba and pythran

* Don't fail fast

* Fix visual test

* Typos

* Better boundaries

* Increase tolerance

* Finite elements requires non-uniform splines

* Use more readable error checking

* PEP

* Remove verbosity

* Transfer fixes to pythran/numba

* Add new BSplines argument everywhere

* Correct pythran file

* Avoid pyccel issue #1288

* Missing eval func

* Fix pythran compilation

* Fix numba compilation

* PEP

* Add missing export

* CODACY

* Correct string

* Correct array sizes

* Avoid rounding errors

* More accurate name

* Fix rouding issues

* PEP

* Comment future work

* Fix arguments

* Fix arguments

* Add cubic optimised solver

* Pep

* Special treatment for circulant

* Add periodic test

* Correct type

* Pep

* Add transpose solve

* [CODACY] unused variables

* Correct condition

* Remove print

* Remove slow circulant

* Use lapack for dense solve

* Optimise periodic case

* contiguous and fix transpose

* Remove dead code. Fix transpose

* Unused import

* Revert matrix changes to return to fastest settings

* Pep

* Remove dead code

* Unused imports

* Place mpi4py before h5py

* Avoid new h5py

* Try for 3.7

* Update versions

* Requirementes

* Install tricky package on command line

* Correct command

* Revert change

* Test alternative versions

* Revert changes. Try for earlier hdf5

* Try no build isolation

* Put in requirements

* Correct command

* Install numpy earlier

* Missing package

* MPI4PY too

* Remove unnecessary restriction
  • Loading branch information
EmilyBourne committed Jan 16, 2024
1 parent a8562e3 commit a5eef6e
Show file tree
Hide file tree
Showing 39 changed files with 6,694 additions and 860 deletions.
4 changes: 2 additions & 2 deletions .github/actions/pip_installation/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ runs:
shell: bash
run: |
export CC="mpicc" HDF5_MPI="ON"
python -m pip install Cython
python -m pip install -r requirements.txt
python -m pip install Cython numpy>=1.15.1 pkgconfig mpi4py>=3.0.0 # h5py requirements
python -m pip install --no-build-isolation -r requirements.txt
python -m pip install numba
python -m pip install pythran
46 changes: 29 additions & 17 deletions .github/workflows/master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: Install dependencies
uses: ./.github/actions/linux_install
- name: Cache pip
uses: actions/cache@v2
uses: actions/cache@v3
with:
# This path is specific to Ubuntu
path: ~/.cache/pip
Expand Down Expand Up @@ -55,13 +57,15 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: Install dependencies
uses: ./.github/actions/linux_install
- name: Cache pip
uses: actions/cache@v2
uses: actions/cache@v3
env:
cache-name: cache-pip
with:
Expand All @@ -80,13 +84,15 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: Install dependencies
uses: ./.github/actions/linux_install
- name: Cache pip
uses: actions/cache@v2
uses: actions/cache@v3
env:
cache-name: cache-pip
with:
Expand All @@ -105,13 +111,15 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: Install dependencies
uses: ./.github/actions/linux_install
- name: Cache pip
uses: actions/cache@v2
uses: actions/cache@v3
env:
cache-name: cache-pip
with:
Expand All @@ -130,13 +138,15 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: Install dependencies
uses: ./.github/actions/linux_install
- name: Cache pip
uses: actions/cache@v2
uses: actions/cache@v3
env:
cache-name: cache-pip
with:
Expand All @@ -155,9 +165,11 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: Install python dependencies
run: |
python -m pip install autopep8
Expand Down
3 changes: 2 additions & 1 deletion plotting/plotResultDiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@
nkts = [n+1+d*(int(p)-1) for (n, d, p) in zip(npts, degree, period)]
breaks = [np.linspace(*lims, num=num) for (lims, num) in zip(domain, nkts)]
knots = [spl.make_knots(b, d, p) for (b, d, p) in zip(breaks, degree, period)]
bsplines = [spl.BSplines(k, d, p) for (k, d, p) in zip(knots, degree, period)]
bsplines = [spl.BSplines(k, d, p, True)
for (k, d, p) in zip(knots, degree, period)]
eta_grids = [bspl.greville for bspl in bsplines]

# Compute 2D grid of processes for the two distributed dimensions in each layout
Expand Down
5 changes: 3 additions & 2 deletions plotting/plot_flux_slice.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@
nkts = [n+1+d*(int(p)-1) for (n, d, p) in zip(npts, degree, period)]
breaks = [np.linspace(*lims, num=num) for (lims, num) in zip(domain, nkts)]
knots = [spl.make_knots(b, d, p) for (b, d, p) in zip(breaks, degree, period)]
bsplines = [spl.BSplines(k, d, p) for (k, d, p) in zip(knots, degree, period)]
bsplines = [spl.BSplines(k, d, p, True)
for (k, d, p) in zip(knots, degree, period)]
eta_grid = [bspl.greville for bspl in bsplines]

theta = np.repeat(np.append(eta_grid[0] % (2*np.pi), 2*np.pi), npts[1]+1) \
Expand All @@ -73,5 +74,5 @@

ax.set_xlabel("x [m]")
ax.set_ylabel("y [m]")
#~ plt.savefig('debug_results/WO-Flux{}'.format(filename[filename.rfind('/'):-3]))
# ~ plt.savefig('debug_results/WO-Flux{}'.format(filename[filename.rfind('/'):-3]))
plt.show()
5 changes: 3 additions & 2 deletions plotting/plot_poloidal_slice.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@
nkts = [n+1+d*(int(p)-1) for (n, d, p) in zip(npts, degree, period)]
breaks = [np.linspace(*lims, num=num) for (lims, num) in zip(domain, nkts)]
knots = [spl.make_knots(b, d, p) for (b, d, p) in zip(breaks, degree, period)]
bsplines = [spl.BSplines(k, d, p) for (k, d, p) in zip(knots, degree, period)]
bsplines = [spl.BSplines(k, d, p, True)
for (k, d, p) in zip(knots, degree, period)]
eta_grid = [bspl.greville for bspl in bsplines]

theta = np.repeat(np.append(eta_grid[1], 2*np.pi), npts[0]) \
Expand All @@ -74,5 +75,5 @@

ax.set_xlabel("x [m]")
ax.set_ylabel("y [m]")
#~ plt.savefig('debug_results/WO-Flux{}'.format(filename[filename.rfind('/'):-3]))
# ~ plt.savefig('debug_results/WO-Flux{}'.format(filename[filename.rfind('/'):-3]))
plt.show()
12 changes: 6 additions & 6 deletions plotting/plot_unstable.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
breaks = [np.linspace(*lims, num=num) for (lims, num) in zip(domain, nkts)]
knots = [spl.make_knots(b, d, p)
for (b, d, p) in zip(breaks, degree, period)]
bsplines = [spl.BSplines(k, d, p)
bsplines = [spl.BSplines(k, d, p, True)
for (k, d, p) in zip(knots, degree, period)]
eta_grids = [bspl.greville for bspl in bsplines]

Expand Down Expand Up @@ -160,14 +160,14 @@
plt.xlabel('time')
plt.ylabel(r'$abs(\Phi_{mn})(r)$')
plt.legend(loc=4)
#ax = plt.subplot(111)
# ax = plt.subplot(111)
#
#clevels = np.linspace( data.min(), data.max(), 101)
#im = ax.contourf( theta, z, data.T, clevels, cmap='jet' )
# clevels = np.linspace( data.min(), data.max(), 101)
# im = ax.contourf( theta, z, data.T, clevels, cmap='jet' )
# for c in im.collections:
# c.set_edgecolor('face')
#plt.colorbar( im )
#plt.title(f"t = {t}")
# plt.colorbar( im )
# plt.title(f"t = {t}")
# plt.xlabel('$\\theta$')
# plt.ylabel('z')
plt.savefig(os.path.join(foldername, 'unstable_modes.png'))
2 changes: 1 addition & 1 deletion pygyro/advection/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ all: accelerated_advection_steps$(SO_EXT)
@rm -f .ACC.*
@touch $@

DEPS := ../initialisation/$(NAME_PREFIX)initialiser_funcs.py ../splines/$(NAME_PREFIX)spline_eval_funcs.py
DEPS := ../initialisation/$(NAME_PREFIX)initialiser_funcs.py ../splines/$(NAME_PREFIX)spline_eval_funcs.py ../splines/$(NAME_PREFIX)cubic_uniform_spline_eval_funcs.py

ifneq ($(ACC), numba)
ifneq ($(ACC), pythran)
Expand Down
Loading

0 comments on commit a5eef6e

Please sign in to comment.