Skip to content

Commit

Permalink
resolved the awful merge commit from combining wall_tests and add_tor…
Browse files Browse the repository at this point in the history
…ques.
  • Loading branch information
rykerfish committed Aug 27, 2024
2 parents a9be545 + d013acf commit 2b92689
Show file tree
Hide file tree
Showing 29 changed files with 224 additions and 142 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ jobs:
- name: Linux (CUDA 12)
steps:
- name: Check out
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: recursive

- name: Show dependency file
Expand Down Expand Up @@ -87,7 +88,8 @@ jobs:
micromamba activate libmobility
# install conda-build
micromamba install -c conda-forge conda-build
conda build conda
export CUDA_VERSION=12
conda build devtools/conda-build
shell: bash -el {0}

- name: Install via pip
Expand Down
44 changes: 44 additions & 0 deletions .github/workflows/conda.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Build and upload conda packages

on:
release:
types: ['released', 'prereleased']
# lets add on PR for testing
# pull_request:
# types: ['opened', 'edited', 'reopened', 'synchronize']

workflow_dispatch: # Un comment line if you also want to trigger action manually

jobs:
conda_deployment_with_new_tag:
name: Conda deployment of package with Python ${{ matrix.python-version }}
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12"]
cuda-version: ["12.1", "12.6"]
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: recursive
- name: Conda environment creation and activation
uses: conda-incubator/setup-miniconda@v2
with:
python-version: ${{ matrix.python-version }}
environment-file: devtools/conda-envs/build_env.yaml # Path to the build conda environment
auto-update-conda: false
auto-activate-base: false
show-channel-urls: true
- name: Build and upload the conda packages
uses: uibcdf/action-build-and-upload-conda-packages@v1.3.0
# Export cuda-version as an environment variable
env:
CUDA_VERSION: ${{ matrix.cuda-version }}
with:
meta_yaml_dir: devtools/conda-build
python-version: ${{ matrix.python-version }} # Values previously defined in `matrix`
user: stochasticHydroTools
label: auto
overwrite: true
token: ${{ secrets.ANACONDA_TOKEN }}
24 changes: 18 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ This repository is organized into the following directories:

- **include/**: Includes the essential C++ base classes and utility files needed to construct the modules.

- **conda/**: Contains a meta.yaml file to build a conda package for libMobility using conda-build.
- **devtools/**: Contains dev specific scripts and files, like a meta.yaml file to build a conda package for libMobility using conda-build.

- **docs/**: Contains the source files for the documentation.

Expand Down Expand Up @@ -70,12 +70,23 @@ The solvers constructor will check the provided configuration and throw an error


## How to use this repo

### Installation

#### Installing a pre-built binary

You can install libMobility latest release through our conda channel:

```shell
$ conda install -c conda-forge -c stochasticHydroTools libmobility
```

#### Compiling from source

Be sure to clone this repository recursively (using ```git clone --recurse```).

After compilation (see below) you will have all the tools mentioned above available for each solver.

## Compilation

We recommend working with a [conda](https://docs.conda.io/en/latest/) environment. The file environment.yml contains the necessary dependencies to compile and use the library.

You can create the environment with:
Expand Down Expand Up @@ -108,7 +119,7 @@ The following variables are available to customize the compilation process:
* DOUBLEPRECISION : If this variable is defined libMobility is compiled in double precision (single by default).


## Python Usage
### Python Usage

Importing libMobility will make available any module under "solvers".

Expand All @@ -119,12 +130,13 @@ Calling
```
will provide more in depth information about the solver.

## C++ Usage
### C++ Usage

In order to use a module called SolverName, the header solvers/SolverName/mobility.h must be included.
If the module has been compiled correctly the definitions required for the functions in mobility.h will be available at solvers/SolverName/mobility.so.
An example is available in cpp/example.cpp.
## Adding a new solver

### Adding a new solver

Solvers must be added following the ```libmobility::Mobility``` directives (see include/MobilityInterface). This C++ base class joins every solver under a common interface. When the C++ interface is prepared, the python bindings can be added automagically by using ```pythonify.h``` (a tool under MobilityInterface).

Expand Down
File renamed without changes.
File renamed without changes.
18 changes: 11 additions & 7 deletions conda/meta.yaml → devtools/conda-build/meta.yaml
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
package:
name: libmobility
version: 0.1.0
version: {{ GIT_DESCRIBE_TAG }}

source:
path: ../ # Path to your project's source code
git_url: ../../

build:
number: 0
string: cuda{{ CUDA_VERSION }}py{{ CONDA_PY }}h{{ PKG_HASH }}_{{ PKG_BUILDNUM }}

requirements:

build:
- cmake >=3.22
- cuda-version 12.*
- cuda-version {{ CUDA_VERSION }}
- gxx
- cuda-libraries-dev
- cuda-nvcc
- make
- mkl-devel
- pybind11
- python 3.11.*
- python
run:
- python 3.11.*
- cuda-version 12.*
- python
- cuda-version >={{ CUDA_VERSION }}
- numpy
- cuda-libraries
- mkl
Expand All @@ -33,7 +37,7 @@ test:
source_files:
- tests
commands:
- pytest -vs -k SelfMobility tests/test_*py
- pytest -vs -k "SelfMobility and not fluct" tests/test_*py

about:
home: https://github.com/stochasticHydroTools/libmobility
Expand Down
7 changes: 7 additions & 0 deletions devtools/conda-envs/build_env.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
channels: # write here the list of channels to look for your library dependencies
- conda-forge
- default

dependencies: # Keep this block with only these two packages
- anaconda-client
- conda-build
74 changes: 47 additions & 27 deletions docs/source/installation.rst
Original file line number Diff line number Diff line change
@@ -1,11 +1,32 @@
Installation
============

We recommend working with a `conda <https://docs.conda.io/en/latest/>`_ environment. The file ``environment.yml`` contains the necessary dependencies to compile and use the library.
We recommend working with a `conda <https://docs.conda.io/en/latest/>`_ environment.

You can install libMobility's latest release through our conda channel:

.. code-block:: shell
$ conda install -c conda-forge -c stochasticHydroTools libmobility
Compilation from source
~~~~~~~~~~~~~~~~~~~~~~~

If you want to compile the library from source, you can clone the repository with:

.. code-block:: shell
$ git clone --recursive https://github.com/stochasticHydroTools/libMobility
The ``--recursive`` flag is necessary to clone the submodules of the repository.

Getting dependencies
--------------------

The file ``environment.yml`` contains the necessary dependencies to compile and use the library.

You can create the environment with:

.. code-block:: shell
Expand All @@ -20,21 +41,39 @@ Then, activate the environment with:
.. hint:: At the moment we offer several installation methods: via pip, conda or building from source. We recommend using pip or conda first, resorting to building from source only if the other methods do not work for you.

Building from source
--------------------

CMake is used for compilation under the hood. After installing the dependencies you can compile and install everything with:

.. code-block:: shell
$ mkdir build && cd build
$ cmake -DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX ..
$ make all install
It is advisable to install the library in the conda environment, so that the python bindings are available. The environment variable ``$CONDA_PREFIX`` is set to the root of the conda environment.

After compilation, the python bindings will be available in the conda environment under the name ``libMobility``. See :ref:`usage` for more information.

The following variables are available to customize the compilation process:

- ``DOUBLEPRECISION``: If this variable is defined, libMobility is compiled in double precision (single by default).

Installing via pip
------------------
Alternative: Installing via pip
-------------------------------

After installing the dependencies, you can install the library with pip. Go to the root of the repository and run:

.. code-block:: shell
$ pip install .
Alternative: Building a conda package
-------------------------------------

Building a conda package
------------------------

Building the conda package only requires the conda-build package. You can install it with:
Building the conda package only requires the conda-build package (dependencies will be fetched automatically). You can install it with:

.. code-block:: shell
Expand All @@ -44,7 +83,7 @@ You can build a conda package with the following command from the root of the re

.. code-block:: shell
$ conda build conda
$ conda build devtools/conda-build
This will build and test the package, which you can install in any environment with:

Expand All @@ -55,22 +94,3 @@ This will build and test the package, which you can install in any environment w
Conda will automatically install all the dependencies needed to run the library.


Building from source
--------------------


CMake is used for compilation, you can compile and install everything with:

.. code-block:: shell
$ mkdir build && cd build
$ cmake -DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX ..
$ make all install
It is advisable to install the library in the conda environment, so that the python bindings are available. The environment variable ``$CONDA_PREFIX`` is set to the root of the conda environment.

After compilation, the python bindings will be available in the conda environment under the name ``libMobility``. See :ref:`usage` for more information.

The following variables are available to customize the compilation process:

- ``DOUBLEPRECISION``: If this variable is defined, libMobility is compiled in double precision (single by default).
12 changes: 11 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@
import os
import sys

try:
version = (
subprocess.check_output(["git", "describe", "--abbrev=0", "--tags"])
.strip()
.decode("utf-8")
)
except:
print("Failed to retrieve the current version, defaulting to 0")
version = "0"


class CMakeExtension(Extension):
def __init__(self, name, sourcedir=""):
Expand Down Expand Up @@ -50,7 +60,7 @@ def build_extension(self, ext):

setup(
name="libMobility",
version="0.1.0",
version=version,
packages=find_packages(),
ext_modules=[CMakeExtension("libMobility")],
cmdclass=dict(build_ext=CMakeBuild),
Expand Down
19 changes: 19 additions & 0 deletions solvers/DPStokes/extra/poly_fits.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,25 @@
/* Ryker Fish 2024. Helpers to compute values of c^{-1} from [1].
The ES kernel has a function c(beta) that provides a relationship between the hydrodynamic radius and the kernel
parameters alpha and beta. There is no closed form for c, but we can approximate c and c^{-1} with a polynomial fit.
We have rH = h*w*c(beta), where rH is the hydrodynamic radius, h is the grid spacing, and w is the width of the kernel.
Thus, we can write c^{-1}(rH/(h*w)) = beta.
References:
[1] Computing hydrodynamic interactions in confined doubly periodic geometries in linear time.
A. Hashemi et al. J. Chem. Phys. 158, 154101 (2023) https://doi.org/10.1063/5.0141371
*/

#include <vector>

namespace dpstokes_polys{

/* Evaluates a polynomial at x with coefficients in descending order, so the highest order coefficients
are at the start of polyCoeffs.
e.g. for a polynomial of order n, this computes
polyCoeffs[n+1] + polyCoeffs[n]*x + polyCoeffs[n-2]*x^2 + ... + polyCoeffs[0]*x^n
*/
double polyEval(std::vector<double> polyCoeffs, double x){

int order = polyCoeffs.size() - 1;
Expand All @@ -15,6 +33,7 @@ namespace dpstokes_polys{
return accumulator;
}

// Coefficients for the polynomial fit of c^{-1} from [1]
std::vector<double> cbetam_inv = {
4131643418.193291,
-10471683395.26777,
Expand Down
Loading

0 comments on commit 2b92689

Please sign in to comment.