Skip to content

Commit

Permalink
Merge pull request #48 from PaulSt/pip
Browse files Browse the repository at this point in the history
work on new pip install
  • Loading branch information
PaulSt authored Aug 27, 2022
2 parents 3311c47 + 8534df5 commit 89452fc
Show file tree
Hide file tree
Showing 9 changed files with 174 additions and 67 deletions.
29 changes: 15 additions & 14 deletions .github/workflows/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,16 @@ FROM ubuntu:latest

WORKDIR /home/app

RUN apt-get update && DEBIAN_FRONTEND="noninteractive" apt-get -y install vim python3 python3-pip python3-distutils python3-tk libpython3-dev libxmu-dev tk-dev tcl-dev cmake git g++ libglu1-mesa-dev libblas-dev liblapack-dev
RUN apt-get update && DEBIAN_FRONTEND="noninteractive" apt-get -y install vim python3 python3-pip python3-distutils git #python3-tk libpython3-dev libxmu-dev tk-dev tcl-dev cmake g++ libglu1-mesa-dev libblas-dev liblapack-dev

#RUN pip install ngsolve ngstrefftz
RUN pip install ngsolve
RUN pip install ngstrefftz

RUN apt-get update
RUN apt-get update
RUN apt-get install -y software-properties-common
RUN add-apt-repository universe
RUN add-apt-repository ppa:ngsolve/nightly -y
RUN apt-get install ngsolve -y

ENV PYTHONPATH=/usr/lib/python3/dist-packages/
ENV NETGENDIR=/usr/bin/
#ENV PYTHONPATH=/usr/lib/python3/dist-packages/
#ENV NETGENDIR=/usr/bin/
ENV PYTHONPATH=$PYTHONPATH:/usr/local/lib/python3.10/site-packages/

RUN git clone --recursive https://github.com/PaulSt/NGSTrefftz /home/app/ngstrefftz
RUN cmake -B/home/app/ngstrefftz/make -S/home/app/ngstrefftz/src
RUN make -C/home/app/ngstrefftz/make
RUN make -C/home/app/ngstrefftz/make install

RUN apt-get install npm nodejs -y
RUN pip3 install jupyter_contrib_nbextensions
Expand All @@ -42,3 +34,12 @@ RUN cd /home/app/ngstrefftz/external_dependencies/ngstents/tentswebgui && ./buil
RUN cd /home/app/ngstrefftz/external_dependencies/ngstents/tentswebgui && pip3 install .
RUN jupyter nbextension install --py tentswebgui
RUN jupyter nbextension enable --py tentswebgui

##RUN pip3 install jupyter
RUN pip3 install jupyter_contrib_nbextensions
RUN pip3 install jupyter_nbextensions_configurator
RUN pip3 install RISE
RUN pip3 install ipywidgets
RUN jupyter contrib nbextension install
#RUN cd /home/app/ngstents/tentswebgui && pip3 install --user .

47 changes: 23 additions & 24 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,56 +91,55 @@ jobs:
#if: ${{ failure() }}
#uses: mxschmitt/action-tmate@v3

pypi-test:
pypi:
needs: [ubuntu]
runs-on: ubuntu-latest
container:
image: quay.io/pypa/manylinux2014_x86_64:latest
steps:
- name: install pkgs
run: |
sudo apt-get update && DEBIAN_FRONTEND="noninteractive" sudo apt-get -y install vim python3 python3-pip python3-distutils python3-tk libpython3-dev libxmu-dev tk-dev tcl-dev cmake git g++ libglu1-mesa-dev libblas-dev liblapack-dev
sudo apt-get install -y software-properties-common
sudo add-apt-repository universe
sudo add-apt-repository ppa:ngsolve/nightly -y
sudo apt-get install ngsolve -y
- name: set path
run: |
echo "PYTHONPATH=/usr/lib/python3/dist-packages/" >> $GITHUB_ENV
echo "NETGENDIR=/usr/bin/" >> $GITHUB_ENV
- uses: actions/checkout@v2
with:
submodules: 'True'
- name: Update pip and Install setuptools
run: |
python3 -m pip install --upgrade pip
python3 -m pip install setuptools
- name: Package ngstrefftz sources for PyPI
run: python3 setup.py sdist
- name: pip install ngstrefftz
run: pip install dist/*
path: 'NGSTrefftz'
fetch-depth: 0 # otherwise, you will failed to push refs to dest repo
- name: build pip
run: cd NGSTrefftz/.github/workflows && sh build_pip.sh
- name: Publish source distribution to PyPI
uses: pypa/gh-action-pypi-publish@master
with:
password: ${{ secrets.PYPI_API_TOKEN }}
packages_dir: NGSTrefftz/wheelhouse/
#repository_url: https://test.pypi.org/legacy/

pypi-publish:
needs: [pypi-test]
pypi-src:
needs: [ubuntu]
runs-on: ubuntu-latest
if: github.event_name == 'release' && github.event.action == 'created' #startsWith(github.ref, 'refs/tags/v') # && github.event_name == 'push'
steps:
- uses: actions/checkout@v2
with:
submodules: 'True'
- name: install pkgs
run: |
sudo apt-get update && DEBIAN_FRONTEND="noninteractive" sudo apt-get -y install vim python3 python3-pip python3-distutils python3-tk libpython3-dev libxmu-dev tk-dev tcl-dev cmake git g++ libglu1-mesa-dev libblas-dev liblapack-dev
pip install ngsolve
- name: Update pip and Install setuptools
run: |
python3 -m pip install --upgrade pip
python3 -m pip install setuptools
- name: Package ngstrefftz sources for PyPI
run: python3 setup.py sdist
- name: pip install ngstrefftz
run: pip install dist/*
- name: Publish source distribution to PyPI
uses: pypa/gh-action-pypi-publish@master
if: github.event_name == 'release' && github.event.action == 'created' #startsWith(github.ref, 'refs/tags/v') # && github.event_name == 'push'
with:
skip_existing: true
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}

docker:
needs: [ubuntu]
needs: [ubuntu,pypi]
runs-on: ubuntu-latest
if: github.event_name == 'release' && github.event.action == 'created'
steps:
Expand Down
44 changes: 44 additions & 0 deletions .github/workflows/build_pip.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#! /bin/bash
set -e
yum -y update
yum -y install ninja-build fontconfig-devel tk-devel tcl-devel libXmu-devel mesa-libGLU-devel ccache

py=/opt/python/cp39-cp39/bin/python
$py fix_auditwheel_policy.py
cd ../..

git config --global --add safe.directory '*'

export ORIGINAL_PATH="$PATH"

for pyversion in 38 39 310
do
export PYDIR="/opt/python/cp${pyversion}-cp${pyversion}/bin"
export PATH="$ORIGINAL_PATH:$PYDIR"
#echo $PYDIR
#$PYDIR/pip install -U pytest-check numpy wheel scikit-build mkl==2021.* mkl-devel==2021.*
#$PYDIR/pip install netgen-mesher
#NETGENDIR=/opt/_internal/cpython-3.9.13/bin

#rm -rf /home/app/ngstrefftz/make
rm -rf _skbuild
$PYDIR/pip install ngsolve

$PYDIR/pip wheel -vvv .
auditwheel repair ngstrefftz*.whl
rm -rf *.whl
$PYDIR/pip uninstall -y ngsolve
$PYDIR/pip uninstall -y netgen-mesher

# avx2 build:
rm -rf _skbuild
$PYDIR/pip install ngsolve-avx2
NETGEN_ARCH=avx2 $PYDIR/pip wheel -vvv .
auditwheel repair ngstrefftz*.whl
rm -rf *.whl
$PYDIR/pip uninstall -y ngsolve-avx2
$PYDIR/pip uninstall -y netgen-mesher-avx2
done

$PYDIR/pip install -U twine
#$PYDIR/twine upload wheelhouse/*manylinux*.whl
41 changes: 41 additions & 0 deletions .github/workflows/fix_auditwheel_policy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import json

policy_file = "/opt/_internal/pipx/venvs/auditwheel/lib/python3.9/site-packages/auditwheel/policy/manylinux-policy.json"
data = json.load(open(policy_file))
# todo: read libs from netgen.libs directory and remove hashes from names, then add just libmkl_rt.so.1
additional_libs = [
"libGLU.so.1",
"libGLX.so.0",
"libGLdispatch.so.0",
"libOpenGL.so.0",
"libXmu.so.6",
"libbz2.so.1.0.6",
"libcsg.so",
"libcsgvis.so",
"libfontconfig.so.1.11.1",
"libfreetype.so.6.14.0",
"libgeom2d.so",
"libgeom2dvis.so",
"libgui.so",
"libinterface.so",
"libmesh.so",
"libmkl_rt.so.1",
"libngcore.so",
"libnggui.so",
"libnglib.so",
"libocc.so",
"libpng15.so.15.13.0",
"libstl.so",
"libstlvis.so",
"libtcl8.so",
"libtk8.so",
"libuuid.so.1.3.0",
"libvisual.so",
"libz.so.1.2.7",
]

for entry in data:
if 'manylinux' in entry['name']:
entry['lib_whitelist'] += additional_libs

json.dump(data, open(policy_file, 'w'))
20 changes: 10 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
FROM paulstdocker/ngstrefftz:latest

#RUN pip3 install jupyter
RUN pip3 install jupyter_contrib_nbextensions
RUN pip3 install jupyter_nbextensions_configurator
RUN pip3 install RISE
RUN pip3 install ipywidgets
RUN jupyter contrib nbextension install
#RUN cd /home/app/ngstents/tentswebgui && pip3 install --user .
##RUN pip3 install jupyter
#RUN pip3 install jupyter_contrib_nbextensions
#RUN pip3 install jupyter_nbextensions_configurator
#RUN pip3 install RISE
#RUN pip3 install ipywidgets
#RUN jupyter contrib nbextension install
##RUN cd /home/app/ngstents/tentswebgui && pip3 install --user .

ARG NB_USER=jovyan
ARG NB_UID=1000
Expand All @@ -26,8 +26,8 @@ RUN jupyter nbextensions_configurator enable --user
RUN jupyter nbextension enable --user codefolding/main
RUN jupyter nbextension enable --user --py tentswebgui

WORKDIR /home/${NB_USER}

COPY . ${HOME}
#WORKDIR /home/${NB_USER}
#COPY . ${HOME}
WORKDIR /home/app/ngstrefftz/docs/notebooks

CMD ["jupyter", "notebook", "--port=8888", "--no-browser", "--ip=0.0.0.0", "--allow-root" ]
5 changes: 5 additions & 0 deletions DockerfileML
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM quay.io/pypa/manylinux2014_x86_64
USER root
COPY . /home/app/ngstrefftz
WORKDIR /home/app/ngstrefftz
#RUN chmod +x build_pip.sh && ./build_pip.sh
2 changes: 1 addition & 1 deletion docs/notebooks/twavetents.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
"metadata": {},
"outputs": [],
"source": [
"from ngstents._pytents import TentSlab\n",
"from ngstrefftz import TWave\n",
"from ngstents._pytents import TentSlab\n",
"from ngsolve.TensorProductTools import *\n",
"from netgen.geom2d import unit_square\n",
"from ngsolve import *\n",
Expand Down
37 changes: 27 additions & 10 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import os
import re
import subprocess

def get_version():
"""
Gets the current version number.
Expand Down Expand Up @@ -93,6 +94,11 @@ def build_extension(self, ext):
cmake_args = ['-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=' + extdir,
'-DPYTHON_EXECUTABLE=' + sys.executable,
'-DCMAKE_CXX_COMPILER=ngscxx']
if 'PYDIR' in os.environ:
cmake_args += [f'-DCMAKE_PREFIX_PATH={os.environ["PYDIR"]}/..']
cmake_args += [f'-DPYTHON_EXECUTABLE={os.environ["PYDIR"]}/python3']
cmake_args += [f'-DPYTHON_LIBRARY={os.environ["PYDIR"]}/../lib']
cmake_args += [f'-DPYTHON_INCLUDE_DIR={os.environ["PYDIR"]}/../include']
cfg = 'Debug' if self.debug else 'Release'
build_args = ['--config', cfg]
cmake_args += ['-DCMAKE_BUILD_TYPE=' + cfg]
Expand All @@ -110,26 +116,37 @@ def build_extension(self, ext):
# subprocess.check_call(['mkdir', 'ngstents'], cwd=self.build_lib)
# subprocess.check_call(['mv', '_pytents.so', 'ngstents'], cwd=self.build_lib)

import netgen.version
import ngsolve
netgen_name = netgen.config.NETGEN_PYTHON_PACKAGE_NAME
avx2 = netgen_name.replace('netgen-mesher', '') # keep -avx2 suffix
name = 'ngstrefftz' + avx2
install_requires = [ 'ngsolve'+avx2+'>='+ngsolve.__version__ ]

if sys.argv[1] == "sdist":
package_data = {"ngstrefftz": ["*"
,"../test/*"
,"../external_dependencies/ngstents/*"\
,"../external_dependencies/ngstents/src/*"\
,"../external_dependencies/ngstents/py/*"\
]}
name += "-src"
else:
package_data = {}

setup(
name='ngstrefftz',
name=name,
version=str(get_version()),
author='Paul Stocker',
author_email='[email protected]',
description='NGSTrefftz is an add-on to NGSolve for Trefftz methods.',
long_description='NGSTrefftz provides a framework to implement Trefftz finite element spaces for NGSolve, with several Trefftz spaces already implemented. Additionally, Trefftz-DG on tent-pitched meshes for the acoustic wave equation is implemented using meshes provided by ngstents. Furthermore, the package includes an implementation of the embedded Trefftz method.',
url="https://github.com/PaulSt/ngstrefftz",
install_requires=install_requires,
ext_modules=[CMakeExtension('ngstrefftz_py','src')],
cmdclass=dict(build_ext=CMakeBuild),
packages=["ngstrefftz"],
package_dir={"ngstrefftz": "src"},
package_data={"ngstrefftz": ["*"
,"../test/*"
,"../external_dependencies/ngstents/*"\
,"../external_dependencies/ngstents/src/*"\
,"../external_dependencies/ngstents/py/*"\
]},
python_requires='>=3.5',
# install_requires=[
# 'NGSolve>=6.2',
# ]
package_data=package_data,
)
16 changes: 8 additions & 8 deletions test/tents.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def SolveWaveTents(initmesh, order, c, t_step):
>>> order = 4
>>> SetNumThreads(4)
>>> c = 1
>>> t_step = 2/sqrt(3)
>>> t_step = 0.5
>>> meshes=[ Mesh(SegMesh(4,0,math.pi)), Mesh(unit_square.GenerateMesh(maxh = 0.4)) , Mesh(unit_cube.GenerateMesh(maxh = 1))]
>>> for initmesh in meshes:
... for maxh in range(3):
Expand All @@ -25,14 +25,14 @@ def SolveWaveTents(initmesh, order, c, t_step):
... initmesh.Refine()
... else:
... initmesh=Mesh(SegMesh(initmesh.ne*2,0,1))
0.14...
0.12...
...e-05
...e-06
0.01...
0.002...
0.001...
0.0001...
0.1...
0.06...
0.05...
0.003...
same example with Neumann boundary conditions
Expand All @@ -46,11 +46,11 @@ def SolveWaveTents(initmesh, order, c, t_step):
... initmesh.Refine()
... else:
... initmesh=Mesh(SegMesh(initmesh.ne*2,0,1))
0.14...
0.12...
...e-05
...e-06
0.01...
0.002...
0.0...
0.001...
0.0001...
0.1...
0.05...
Expand Down Expand Up @@ -216,7 +216,7 @@ def SolveWaveTentsFO(initmesh, order, c, t_step):
... SolveWaveTentsFO(initmesh, order, c, t_step) # doctest:+ELLIPSIS
... initmesh.Refine()
0.01...
0.002...
0.00...
0.0001...
"""

Expand Down

0 comments on commit 89452fc

Please sign in to comment.