From 1a5c8cf0298e75c545a025b5ecf37b24f6494044 Mon Sep 17 00:00:00 2001 From: Garrett Barter Date: Wed, 10 Jan 2024 22:11:55 -0700 Subject: [PATCH 1/3] final changes to enable mesonpy and cross compilation --- .github/workflows/CI_pyHAMS.yml | 2 +- environment.yml | 2 +- meson.build | 18 ++++++------------ meson_options.txt | 12 ++++++------ pyhams/meson.build | 18 +++++++++--------- 5 files changed, 23 insertions(+), 29 deletions(-) diff --git a/.github/workflows/CI_pyHAMS.yml b/.github/workflows/CI_pyHAMS.yml index ec93b0d..a11089e 100644 --- a/.github/workflows/CI_pyHAMS.yml +++ b/.github/workflows/CI_pyHAMS.yml @@ -37,7 +37,7 @@ jobs: if: contains( matrix.os, 'windows') run: | #vcpkg install openblas - #pacman -S mingw-w64-x86_64-openblas64 + pacman -S mingw-w64-x86_64-openblas64 mingw-w64-lapack #'${{ steps.cp.outputs.python-path }}' -m pip install pylib-openblas - name: Mac openblas diff --git a/environment.yml b/environment.yml index 0bd93b3..071aed6 100644 --- a/environment.yml +++ b/environment.yml @@ -5,6 +5,7 @@ channels: dependencies: - cmake - meson + - meson-python - ninja - numpy - openblas @@ -12,4 +13,3 @@ dependencies: - pip - pkg-config - python - - setuptools diff --git a/meson.build b/meson.build index 43312f9..48f8309 100644 --- a/meson.build +++ b/meson.build @@ -27,16 +27,15 @@ endif # Adding at project level causes many spurious -lgfortran flags. _fflags = [] -if fc.get_id() == 'gcc' - _fflags = fc.get_supported_arguments('-fdec-math') - _fflags += fc.get_supported_arguments('-fno-align-commons') -endif -if fc.get_id() == 'intel' +if fc.get_id() in ['intel', 'intel-llvm'] _fflags = fc.get_supported_arguments('-qmkl') -elif fc.get_id() == 'intel-cl' +elif fc.get_id() in ['intel-cl', 'intel-llvm-cl'] # Intel Fortran on Windows does things differently, so deal with that # (also specify dynamic linking and the right name mangling) _fflags = fc.get_supported_arguments('/qmkl') +else + _fflags = fc.get_supported_arguments('-fdec-math') + _fflags += fc.get_supported_arguments('-fno-align-commons') endif add_project_arguments(_fflags, language: 'fortran') @@ -59,12 +58,7 @@ lapack = dependency('openblas', 'mkl_rt', 'blas', 'lapack', required: true) # https://mesonbuild.com/Python-module.html # Here we differentiate from the python used by meson, py3_command, and that python target, py3_target. This is useful # when cross compiling like on conda-forge -py_mod = import('python') -if get_option('python_target') != '' - py3 = py_mod.find_installation(get_option('python_target')) -else - py3 = py_mod.find_installation('python') -endif +py3 = import('python').find_installation(pure: false) py3_dep = py3.dependency() message(py3.path()) diff --git a/meson_options.txt b/meson_options.txt index a768c27..3b93898 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -1,9 +1,9 @@ option('incdir_numpy', type: 'string', value: '', description: 'Include directory for numpy. If left empty Meson will try to find it on its own.') -option('python_target', type: 'string', value: '', - description: '''Target python path. This is used in the case that the Python installation that PyOptSparse is intended - to be built for is different than the Python installation that is used to run Meson. For example, Meson may be installed - on the user's system which is run using the system Python installation, but the user may want build PyOptSparse for - a Python installation in a virtual environment. Leave as an empty string to build for Python installation running - Meson.''') +#option('python_target', type: 'string', value: '', +# description: '''Target python path. This is used in the case that the Python installation that PyOptSparse is intended +# to be built for is different than the Python installation that is used to run Meson. For example, Meson may be installed +# on the user's system which is run using the system Python installation, but the user may want build PyOptSparse for +# a Python installation in a virtual environment. Leave as an empty string to build for Python installation running +# Meson.''') diff --git a/pyhams/meson.build b/pyhams/meson.build index 161294f..a567087 100644 --- a/pyhams/meson.build +++ b/pyhams/meson.build @@ -1,13 +1,13 @@ # NumPy include directory - needed in all submodules -incdir_numpy = get_option('incdir_numpy') -if incdir_numpy == '' - incdir_numpy = run_command(py3, - [ - '-c', - 'import os; os.chdir(".."); import numpy; print(numpy.get_include())' - ], - check: true - ).stdout().strip() +incdir_numpy = meson.get_external_property('numpy-include-dir', 'not-given') +if incdir_numpy == 'not-given' + incdir_numpy = run_command(py3, + [ + '-c', + 'import os; os.chdir(".."); import numpy; print(numpy.get_include())' + ], + check: true + ).stdout().strip() endif # this creates a raw string which is useful for Windows use of '\' for paths incdir_numpy = '''@0@'''.format(incdir_numpy) From 0977bf3f5dbc07b78a5b81efb67d4b6718f40ac8 Mon Sep 17 00:00:00 2001 From: Garrett Barter Date: Wed, 17 Jan 2024 17:37:52 -0700 Subject: [PATCH 2/3] cleanup --- .github/workflows/CI_pyHAMS.yml | 4 +-- README.md | 48 ++++++++++++++++++++++++++++----- meson_options.txt | 1 + 3 files changed, 44 insertions(+), 9 deletions(-) diff --git a/.github/workflows/CI_pyHAMS.yml b/.github/workflows/CI_pyHAMS.yml index a11089e..9751b2d 100644 --- a/.github/workflows/CI_pyHAMS.yml +++ b/.github/workflows/CI_pyHAMS.yml @@ -56,8 +56,6 @@ jobs: # uses: mxschmitt/action-tmate@v3 - name: Pip Install pyHAMS - env: - MESON_ARGS: -Dpython_target=${{ steps.cp.outputs.python-path }} run: | '${{ steps.cp.outputs.python-path }}' -m pip install --upgrade pip '${{ steps.cp.outputs.python-path }}' -m pip install meson-python meson numpy ninja wheel @@ -130,7 +128,7 @@ jobs: env: MESON_ARGS: "" run: | - python -m pip install . + python -m pip install . -v - name: Test run run: | diff --git a/README.md b/README.md index 484c697..b5a7157 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,47 @@ # pyHAMS -This is a python wrapper for [HAMS](https://github.com/YingyiLiu/HAMS) +This is a python wrapper for [HAMS](https://github.com/YingyiLiu/HAMS), a boundary element method for hydrodynamic analysis of submerged structures. -Install via: +There is cylinder test case that demonstrates usage and outputs in ``test/test_cylinder.py``. -``` -pip install . -``` +## Prerequisites + +pyHAMS requires a Fortran compiler. The python wrapper currently supports GNU and Intel compilers. HAMS can be built with Flang, but that is not yet recognized by pyHAMS. + +## Install (as a library) + +To install pyHAMS as a library that can be used by WEIS or RAFT in the backend, you can use either conda or PyPi package management: + + $ pip install pyHAMS + +or + + $ conda install pyHAMS + + +## Install (from source) + +If you would like to build the project locally from source for easier access to the underlying methods and tests, do: + + $ git clone https://github.com/WISDEM/pyHAMS.git + $ cd pyHAMS + $ pip install . + +If developer/editable mode, do the same `git clone` step, but on install do: + + $ pip install --no-build-isolation -e . + +The `--no-build-isolation` option is important per [Meson guidelines](https://meson-python.readthedocs.io/en/latest/how-to-guides/editable-installs.html). Note that this package uses `mesonpy` for an installation backend, so there is no `setup.py` file. + + +## Unit Tests + + $ pytest test + +For software issues please use . For theory related questions and comments please use the [HAMS issues page](https://github.com/YingyiLiu/HAMS/issues). + + +## License + +pyHAMS uses the Apache License v2.0 -Note that this package uses `mesonpy` for an installation backend, so there is no `setup.py` file. diff --git a/meson_options.txt b/meson_options.txt index 3b93898..e95dc6a 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -7,3 +7,4 @@ option('incdir_numpy', type: 'string', value: '', # on the user's system which is run using the system Python installation, but the user may want build PyOptSparse for # a Python installation in a virtual environment. Leave as an empty string to build for Python installation running # Meson.''') +y From c96e4c12fabf22a7c939e9f1082772ae3518de25 Mon Sep 17 00:00:00 2001 From: Garrett Barter Date: Wed, 17 Jan 2024 19:29:37 -0700 Subject: [PATCH 3/3] remove errant line in options --- meson_options.txt | 7 ------- pyproject.toml | 1 + 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/meson_options.txt b/meson_options.txt index e95dc6a..1bd3d33 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -1,10 +1,3 @@ option('incdir_numpy', type: 'string', value: '', description: 'Include directory for numpy. If left empty Meson will try to find it on its own.') -#option('python_target', type: 'string', value: '', -# description: '''Target python path. This is used in the case that the Python installation that PyOptSparse is intended -# to be built for is different than the Python installation that is used to run Meson. For example, Meson may be installed -# on the user's system which is run using the system Python installation, but the user may want build PyOptSparse for -# a Python installation in a virtual environment. Leave as an empty string to build for Python installation running -# Meson.''') -y diff --git a/pyproject.toml b/pyproject.toml index 77736a3..e5a1523 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -78,6 +78,7 @@ download = "https://github.com/WISDEM/pyHAMS/releases" tracker = "https://github.com/WISDEM/pyHAMS/issues" [tool.meson-python.args] +setup = ['--python.install-env=auto'] install = ['--tags=runtime,python-runtime,bin'] # This is configuration specific to the `setuptools` build backend.