Skip to content

Commit

Permalink
Merge pull request #17 from WISDEM/develop
Browse files Browse the repository at this point in the history
final changes to enable mesonpy and cross compilation
  • Loading branch information
gbarter authored Jan 18, 2024
2 parents e8f7897 + c96e4c1 commit 10b39e1
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 38 deletions.
6 changes: 2 additions & 4 deletions .github/workflows/CI_pyHAMS.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -130,7 +128,7 @@ jobs:
env:
MESON_ARGS: ""
run: |
python -m pip install .
python -m pip install . -v
- name: Test run
run: |
Expand Down
48 changes: 42 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -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 <https://github.com/WISDEM/pyHAMS/issues>. 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.
2 changes: 1 addition & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ channels:
dependencies:
- cmake
- meson
- meson-python
- ninja
- numpy
- openblas
- openmp
- pip
- pkg-config
- python
- setuptools
18 changes: 6 additions & 12 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand All @@ -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())
Expand Down
6 changes: 0 additions & 6 deletions meson_options.txt
Original file line number Diff line number Diff line change
@@ -1,9 +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.''')
18 changes: 9 additions & 9 deletions pyhams/meson.build
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 10b39e1

Please sign in to comment.