A simulation framework for nonequilibrium statistical physics
Project description
Pydiffuser
Pydiffuser is a numerical simulation framework for nonequilibrium statistical physics based on JAX.
This package mainly aims:
- to share code to implement a numerical simulation on physical models written in various forms of stochastic differential equations.
- to revisit recent research highlights in non-equilibrium statistical physics.
- to reduce the repeated code on time-series data analysis, e.g., statistical analysis of single-particle trajectory for SPT experiments.
- to provide the skeleton of stochastic model simulation for anyone interested in stochastic processes.
Installation
Requirements
Python 3.10+, jax>=0.4.18
, and jaxlib>=0.4.18
.
From PyPI
$ pip install pydiffuser
If properly installed, you can run:
$ pydiffuser --version
pydiffuser, version 0.0.1
Quickstart
Pydiffuser provides various stochastic models that implement a numerical simulation based on the Monte Carlo method.
All Pydiffuser's models inherit an abstract class pydiffuser.models.BaseDiffusion
and initiate the simulation after a method generate
is called.
For the simplest case, you can produce a non-interacting Brownian motion at low Reynolds numbers as follows:
from pydiffuser.models import BrownianMotion
from pydiffuser.tracer import Ensemble, Trajectory
model = BrownianMotion()
ensemble: Ensemble = model.generate()
tracer: Trajectory = ensemble[0] # 0th particle
Relevant stochastic observables, such as mean-squared displacement $\left \langle \mathbf{r}^{2}(t) \right \rangle$ and normalized velocity autocorrelation function, can be calculated through the methods of Trajectory
and Ensemble
.
tamsd = tracer.get_mean_squared_displacement(lagtime=1, rolling=True)
eamsd = ensemble.get_mean_squared_displacement(lagtime=1, rolling=False)
eatamsd = ensemble.get_mean_squared_displacement(lagtime=1, rolling=True)
You can visualize the trajectory using matplotlib.
It is obtained by matplotlib.pyplot.plot(tracer.position_x1, tracer.position_x2)
.
CLI
List all stochastic models supported by Pydiffuser.
$ pydiffuser list
NAME MODEL CONFIG DIMENSION
abp ActiveBrownianParticle ActiveBrownianParticleConfig 2d
aoup ActiveOUParticle ActiveOUParticleConfig 1d, 2d, 3d
bm BrownianMotion BrownianMotionConfig 1d, 2d, 3d
levy LevyWalk LevyWalkConfig 1d, 2d, 3d
rtp RunAndTumbleParticle RunAndTumbleParticleConfig 1d, 2d, 3d
smoluchowski SmoluchowskiEquation SmoluchowskiEquationConfig 1d, 2d
Features
Observables
class pydiffuser.tracer.Trajectory
∈ class pydiffuser.tracer.Ensemble
get_increments
get_displacement_moment
get_mean_squared_displacement
get_cosine_moment
get_velocity_autocorrelation
get_real_time
The above methods are defined in both Trajectory
and Ensemble
to enhance transparency.
Using the methods of Trajectory
, the statistical analysis of single-particle trajectory can be accelerated.
Configuration
We introduce a configuration file to deal with extensive parameter manipulation.
For instance, see config.json
, which contains all parameters demanded to instantiate pydiffuser.ActiveBrownianParticle
.
Every JSON file of the configurations listed in CLI can be obtained as follows:
import pydiffuser as pyd
from pydiffuser.models import ActiveBrownianParticle, ActiveBrownianParticleConfig
config = ActiveBrownianParticleConfig()
config.to_json(json_path=<JSON_PATH>)
We suggest a research pipeline.
┌────┐ ┌─────────────────────┐ ┌───────────────┐ ┌──────────┐ ┌────────────┐
│JSON├──>──┤`BaseDiffusionConfig`├──>──┤`BaseDiffusion`├──>──┤`Ensemble`├──>──┤NPY | PICKLE│
└────┘ [1] └─────────────────────┘ [2] └───────────────┘ [3] └──────────┘ [4] └────────────┘
It can be automized as follows:
config = ActiveBrownianParticleConfig.from_json(json_path=<JSON_PATH>) # [1]
model = ActiveBrownianParticle.from_config(config=config) # [2]
ensemble = model.generate() # [3]
ensemble.to_npy(npy_path=<NPY_PATH>) # [4]
It is possible to save & load a picklable object through pydiffuser.save
and pydiffuser.load
.
MODEL_PATH = "model.pickle"
pyd.save(obj=model, pickle_path=MODEL_PATH) # <PICKLE_PATH> = MODEL_PATH
model = pyd.load(pickle_path=MODEL_PATH)
Related Works
Hyperdiffusion of Poissonian run-and-tumble particles in two dimensions
License
Citation
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pydiffuser-0.0.1.tar.gz
.
File metadata
- Download URL: pydiffuser-0.0.1.tar.gz
- Upload date:
- Size: 378.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.31.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c3c9191826e19e6e368bfd68ffada8ac049c2f946cc6f84782a5a2497936c406 |
|
MD5 | e8b90627d766b792cf3bd5b611424773 |
|
BLAKE2b-256 | dea4f51ddee6a07b4e3c13ae30c3d96686d5687f0b7040c4a518ec7287a8637b |
Provenance
File details
Details for the file pydiffuser-0.0.1-py3-none-any.whl
.
File metadata
- Download URL: pydiffuser-0.0.1-py3-none-any.whl
- Upload date:
- Size: 32.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.31.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c373cc8b68ba121aa57c3cfc24316c3b354b2329c2c6c59223acb4ebb9325a67 |
|
MD5 | ea0008145fa0e2e1e906f24eb097da86 |
|
BLAKE2b-256 | d71318835253eb557ddf66bc655f11bada94bd04ae631791b01ccb4321cb91c5 |