Skip to main content

Python implementation of Fast Stokesian Dynamics methods.

Project description

jfsd: a Python implementation of Fast Stokesian Dynamics with Jax

This repository contains a Python implementation of the Fast Stokesian Dynamics methods (A. Fiore, J. Swan, 2019, https://www.cambridge.org/core/journals/journal-of-fluid-mechanics/article/abs/fast-stokesian-dynamics/970BD1B80B43E21CD355C7BAD4644D46) which leverages the library JAX to just-in-time compile and run on GPU the simulation. The accuracy of hydrodynamic interactions can be scaled down in order to obtain Rotne-Prager-Yamakawa (up to 2-body effects, and no lubrication) or Brownian Dynamics (only 1-body effects). Boundary conditions can be switch from periodic to open, and the average height of asperities on particles can be specified, enabling simulations of rough colloids.

Installation Guide

Pre-requisites:

  • CUDA (tested with version 11.8): Download
  • cuDNN (tested with 8.6 for CUDA 11): Download
  • Python ≥ 3.9

Installation Options

You can install JFSD in two ways:

  1. Via pip (Stable Release):
    The latest stable version of JFSD can be installed directly from PyPI:

    pip install jfsd
    

    Note: This may not include the latest developments in the main branch.

  2. From Source (Latest Development Version):

    1 - Clone the repository

    git clone https://github.com/torrewk/Python-Jax-Fast-Stokesian-Dynamics.git
    cd Python-Jax-Fast-Stokesian-Dynamics
    

    2 - Create and activate a virtual environment

    python3 -m venv .venv
    source .venv/bin/activate
    

    3 - Install the required JAX library

    pip install jaxlib==0.4.17+cuda11.cudnn86 -f https://storage.googleapis.com/jax-releases/jax_cuda_releases.html
    

    4 - Install JFSD and dependencies

    pip install ".[test]"
    

    5 - Reboot the environment (needed for pytest to work)

    deactivate && source .venv/bin/activate
    

    6 - Run unit tests to verify the installation

    pytest tests/test_class.py
    

For the latest updates and bug fixes, using the source installation is recommended.

How to Run Simulations

1 - Create a configuration .toml in files/ (use "files/example_configuration.toml" as reference)

2a - Run the main code, from the project directory, via:

jfsd -c files/<your_config_file.toml> -o <directory_name_for_output>

Replace <your_config_file.toml> with the name of the file created in step (1), and <directory_name_for_output> with the name of the folder where you want to store the trajetory data.

2b - To provide initial particle positions to jfsd, run it via:

jfsd -c files/<your_config_file.toml> -s <initial_particle_positions.npy> -o <directory_name_for_output>

Replace <initial_particle_positions.npy> with the name of your initial configuration, and modify <your_config_file.toml> to accept initial positions from file (instead of randomly creating it, see 'example_configuration.toml'). Note that this file must be a numpy array of shape (Np, 3), with Np the number of particles.

Analyzing Trajectory Data

During the simulation, the particles trajectories,velocities, and stresslets are saved in a numpy array of shape (Ns, Np, Nc), with Ns the number of frames stored, Np the number of particles and Nc the number of d.o.f. (3 for trajectories, 6 for velocities, 5 for stresslets). Lengths in the simulation are expressed in units of the particles radius a, and momenta in units of γa, with unity mass for each particle.

Common/Known Issues

"Unable to load cuPTI"

This issue can occur if the PATH or LD_LIBRARY_PATH environment variables are not set correctly to include your CUDA installation, especially the cuPTI (CUDA Profiling Tools Interface) library, which JAX requires.

To solve this (temporarily), add the following line to your environment:

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda/extras/CUPTI/lib64

For a permanent solution, edit the .bashrc file in your home directory:

echo 'export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda/extras/CUPTI/lib64' >> ~/.bashrc

and apply the changes:

source ~/.bashrc

Note that, if cuda is installed in a different location than '/usr/local/', you need to modify the lines above accordingly.

Acknowledgment

The authors acknowledge the Dutch Research Council (NWO) for funding through OCENW.KLEIN.354, as well as the International Fine Particle Research Institute (IFPRI) for funding through collaboration grant CRR-118-01.

We developed JFSD as a way to give back to the fluid dynamics community, whose contributions have shaped our own research. We hope this implementation helps keep the Fast Stokesian Dynamics framework accessible for future studies, continuing the legacy of Fiore and Swan’s excellent algorithms.

We are also grateful to Luca Leone, Athanasios Machas, and Dimos Aslanis for their valuable insights, which improved our understanding of FSD, Google JAX, and the user/developer experience, respectively.

License

This project is licensed under the Apache License, Version 2.0. See the LICENSE file for the full terms and conditions. For a concise summary, refer to LICENSE_SHORT.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

jfsd-0.2.1.tar.gz (250.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

jfsd-0.2.1-py3-none-any.whl (95.4 kB view details)

Uploaded Python 3

File details

Details for the file jfsd-0.2.1.tar.gz.

File metadata

  • Download URL: jfsd-0.2.1.tar.gz
  • Upload date:
  • Size: 250.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for jfsd-0.2.1.tar.gz
Algorithm Hash digest
SHA256 fa0bcc9fbb0d8c6ec6880f5c485c9ce68b6c966f56384ac3bcd45084a0c6146e
MD5 efd2192d6c8a1cd407cae5520a6d58a6
BLAKE2b-256 5c2705d38ed124c0a67af33da9e7ee1058912adc9b39fed316e3246dbc466ae8

See more details on using hashes here.

File details

Details for the file jfsd-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: jfsd-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 95.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for jfsd-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 cb6dc5953891e3f8cb90e216cca0c12efadc4827c540f235afd5e6870b8258fd
MD5 9fb018b372aa776b4796ee2342704ed7
BLAKE2b-256 ea90d371f01f191b5191205c5d7edc6af9175f9b6b8a1a0d20b1f0867de27b51

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page