Basin stability estimation for dynamical systems
Project description
pybasin
Basin stability estimation for dynamical systems
pybasin is a Python library for estimating basin stability in dynamical systems. Given an ODE and a sampling region, it integrates thousands of initial conditions, extracts time-series features, and clusters the resulting trajectories to determine what fraction of the phase space leads to each attractor. The library is a modern port of the MATLAB bSTAB toolbox, extended with GPU acceleration, automated feature extraction, and parameter studies.
Features
- Basin stability estimation with configurable sample counts and sampling strategies
- Multiple ODE solver backends --
TorchDiffEqSolver(default),JaxSolver(GPU-optimized, optional),TorchOdeSolver,ScipyParallelSolver - Automated feature extraction from trajectories (PyTorch-based, plus optional tsfresh and nolds)
- Unsupervised and supervised classification -- HDBSCAN clustering out of the box, or bring any scikit-learn estimator
- Parameter studies -- sweep ODE parameters and track how basin stability changes
- Visualization -- Matplotlib plotting included; interactive Dash/Plotly plotter available via
pybasin[interactive] - Disk caching -- solver results are cached with safetensors for fast reruns
- Full type annotations with
py.typedmarker
Installation
pip install pybasin
This installs the core library with TorchDiffEqSolver as the default backend. Optional extras unlock additional features:
| Extra | Command | Adds |
|---|---|---|
jax |
pip install pybasin[jax] |
JaxSolver -- fastest on GPU, event functions |
interactive |
pip install pybasin[interactive] |
Dash/Plotly interactive plotter |
tsfresh |
pip install pybasin[tsfresh] |
tsfresh feature extractor |
nolds |
pip install pybasin[nolds] |
Nonlinear dynamics features (Lyapunov, correlation dimension) |
torchode |
pip install pybasin[torchode] |
torchode solver (per-trajectory step sizes) |
all |
pip install pybasin[all] |
Everything above |
When JAX is installed and the ODE inherits from JaxODESystem, BasinStabilityEstimator automatically picks JaxSolver. If the ODE inherits from ODESystem (PyTorch), TorchDiffEqSolver is always the default.
Quick Start
Define an ODE, create a sampler, and run the estimator. Three objects are all you need:
import torch
from typing import TypedDict
from pybasin import BasinStabilityEstimator
from pybasin.ode_system import ODESystem
from pybasin.sampler import UniformRandomSampler
class DuffingParams(TypedDict):
delta: float
k3: float
A: float
class DuffingODE(ODESystem[DuffingParams]):
def ode(self, t: torch.Tensor, y: torch.Tensor) -> torch.Tensor:
x, x_dot = y[..., 0], y[..., 1]
delta, k3, A = self.params["delta"], self.params["k3"], self.params["A"]
return torch.stack([x_dot, -delta * x_dot - k3 * x**3 + A * torch.cos(t)], dim=-1)
ode = DuffingODE({"delta": 0.08, "k3": 1.0, "A": 0.2})
sampler = UniformRandomSampler(min_limits=[-1, -0.5], max_limits=[1, 1])
bse = BasinStabilityEstimator(ode_system=ode, sampler=sampler, n=5000)
basin_stability = bse.run()
print(basin_stability)
# {'attractor_0': 0.52, 'attractor_1': 0.48}
Solver, feature extractor, and clusterer all have defaults -- you only configure what you need to change. For the full tutorial, see the Quick Start guide.
Documentation
Full documentation: https://adrianwix.github.io/pybasin/
Covers installation extras, solver comparison, feature extraction, parameter studies, and the complete API reference.
Case Studies
Validated against the original MATLAB bSTAB implementation:
| Case Study | Description |
|---|---|
| Duffing Oscillator | Forced oscillator with bistability |
| Lorenz System | Classic chaotic attractor |
| Pendulum | Forced pendulum with bifurcations |
| Friction System | Mechanical system with friction |
| Rossler Network | Coupled oscillators synchronization |
Each case study lives under case_studies/ and can be run with:
uv run python -m case_studies.pendulum.main_pendulum_case1
Project Structure
root/
├── src/pybasin/ # Published library
├── src/zigode/ # Zig-compiled ODE solver (separate package)
├── thesis_utils/ # Thesis-specific plotting (not part of published package)
├── case_studies/ # Research case studies
├── tests/ # Unit and integration tests
├── docs/ # Documentation source (MkDocs)
├── benchmarks/ # Performance benchmarks
└── scripts/ # Helper scripts
Development
git clone https://github.com/adrianwix/pybasin.git
cd pyBasinWorkspace
uv sync --all-groups
This installs all dependencies (core + dev + docs + case studies + experiments) into a virtual environment managed by uv. Run the test suite and linters with:
uv run pytest # tests
sh scripts/ci.sh # ruff + pyright
For the full contributor workflow, see the Contributing guide.
Academic Context
pybasin is the main contribution of the bachelor thesis "Pybasin: A Python Toolbox for Basin Stability of Multi-Stable Dynamical Systems." It ports and extends the MATLAB bSTAB library with GPU acceleration, automated feature extraction, and modern Python packaging.
Citation
@software{pybasin2025,
author = {Wix, Adrian},
title = {Pybasin: A Python Toolbox for Basin Stability of Multi-Stable Dynamical Systems},
year = {2025},
url = {https://github.com/adrianwix/pybasin}
}
License
GPL-3.0 -- see LICENSE for details.
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pybasin-0.2.0.tar.gz.
File metadata
- Download URL: pybasin-0.2.0.tar.gz
- Upload date:
- Size: 164.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8abcc5dd7e31dc73e6770bd9af3bcaa16196342dfb164ea119038faa838ab716
|
|
| MD5 |
0a841ebd3deca83f8667512d7a265280
|
|
| BLAKE2b-256 |
bea928542f90b61ab8411bce3aaa16914d96398126be221ff608821c96549624
|
Provenance
The following attestation bundles were made for pybasin-0.2.0.tar.gz:
Publisher:
publish.yml on adrianwix/pybasin
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pybasin-0.2.0.tar.gz -
Subject digest:
8abcc5dd7e31dc73e6770bd9af3bcaa16196342dfb164ea119038faa838ab716 - Sigstore transparency entry: 1108310643
- Sigstore integration time:
-
Permalink:
adrianwix/pybasin@925877c9886642f818244ff52a558986b707cb27 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/adrianwix
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@925877c9886642f818244ff52a558986b707cb27 -
Trigger Event:
push
-
Statement type:
File details
Details for the file pybasin-0.2.0-py3-none-any.whl.
File metadata
- Download URL: pybasin-0.2.0-py3-none-any.whl
- Upload date:
- Size: 218.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2d96cf551084f79c0bd57872ce96bd8d641ed480492a0dcc567b8e54dca4116b
|
|
| MD5 |
0cf73a9cf70821fa2e38302127b7ebe1
|
|
| BLAKE2b-256 |
6d1793963b9285ab2478a03e8eaa6571c0efce326175ed65e295ebe0ddb26547
|
Provenance
The following attestation bundles were made for pybasin-0.2.0-py3-none-any.whl:
Publisher:
publish.yml on adrianwix/pybasin
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pybasin-0.2.0-py3-none-any.whl -
Subject digest:
2d96cf551084f79c0bd57872ce96bd8d641ed480492a0dcc567b8e54dca4116b - Sigstore transparency entry: 1108310645
- Sigstore integration time:
-
Permalink:
adrianwix/pybasin@925877c9886642f818244ff52a558986b707cb27 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/adrianwix
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@925877c9886642f818244ff52a558986b707cb27 -
Trigger Event:
push
-
Statement type: