Skip to main content

SSMS is a package collecting simulators and training data generators for cognitive science, neuroscience, and approximate bayesian computation

Project description

SSMS (Sequential Sampling Model Simulators)

DOI PyPI PyPI_dl GitHub pull requests Python Version Run tests Ruff License: MIT codecov

Python Package to collect simulators for Sequential Sampling Models.

Find the package documentation here.

Quick Start

The ssms package serves two purposes.

  1. Easy access to fast simulators of sequential sampling models
  2. Support infrastructure to construct training data for various approaches to likelihood / posterior amortization

A number of tutorial notebooks are available under the /notebooks directory.

Installation

pip install ssm-simulators

Recommended: Install via conda-forge for full parallel support:

conda install -c conda-forge ssm-simulators

[!NOTE] Parallel Execution Requirements:

For multi-threaded simulation (n_threads > 1), the package requires:

  • OpenMP: For parallel loop execution
  • GSL (GNU Scientific Library): For validated random number generation

conda-forge users: Both dependencies are automatically included.

pip users: Install system dependencies first:

# macOS
brew install libomp gsl

# Ubuntu/Debian
sudo apt-get install libgomp-dev libgsl-dev

Then reinstall: pip install --force-reinstall ssm-simulators

Without these dependencies, the package works in single-threaded mode using NumPy.

[!NOTE] Building from source or developing this package requires a C compiler (such as GCC). On Linux, you can install GCC with:

sudo apt-get install build-essential

Most users installing from PyPI wheels do not need to install GCC.

Parallel Execution Details

When using n_threads > 1, the package uses GSL's validated Ziggurat algorithm for Gaussian random number generation, ensuring statistically correct simulations.

Thread Limit: The maximum supported number of threads is 256 (compile-time limit). Requesting more threads will raise a ValueError. This limit exists because per-thread random number generator states are allocated as static arrays for performance.

from ssms.basic_simulators import simulator

# Single-threaded (uses NumPy RNG)
result = simulator.simulator(model='ddm', theta=theta, n_samples=10000, n_threads=1)

# Multi-threaded (uses GSL Ziggurat RNG, requires OpenMP + GSL)
result = simulator.simulator(model='ddm', theta=theta, n_samples=10000, n_threads=8)

Check your installation's parallel capabilities:

from cssm._openmp_status import print_status
print_status()

Command Line Interface

The package exposes a command-line tool, generate, for creating training data from a YAML configuration file.

generate --config-path <path/to/config.yaml> --output <output/directory> [--log-level INFO]
  • --config-path: Path to your YAML configuration file (optional, uses default if not provided).
  • --output: Directory where generated data will be saved (required).
  • --n-files: (Optional) Number of data files to generate. Default is 1 file.
  • --estimator-type: (Optional) Likelihood estimator type (kde or pyddm). Overrides YAML config if specified.
  • --log-level: (Optional) Set the logging level (DEBUG, INFO, WARNING, ERROR, CRITICAL). Default is WARNING.

Below is a sample YAML configuration you can use with the generate command:

MODEL: 'ddm'
GENERATOR_APPROACH: 'lan'

PIPELINE:
  N_PARAMETER_SETS: 100
  N_SUBRUNS: 20

SIMULATOR:
  N_SAMPLES: 2000
  DELTA_T: 0.001

TRAINING:
  N_SAMPLES_PER_PARAM: 200

ESTIMATOR:
  TYPE: 'kde'  # Options: 'kde' (default) or 'pyddm'

Configuration file parameter details follow.

Top-Level Parameters:

Option Definition
MODEL The type of model you want to simulate (e.g., ddm, angle, levy)
GENERATOR_APPROACH Type of generator used to generate data (lan or cpn)

PIPELINE Section:

Option Definition
N_PARAMETER_SETS Number of parameter vectors that are used for training
N_SUBRUNS Number of repetitions of each call to generate data

SIMULATOR Section:

Option Definition
N_SAMPLES Number of samples a simulation run should entail for a given parameter set
DELTA_T Time discretization step used in numerical simulation of the model. Interval between updates of evidence-accumulation.

TRAINING Section:

Option Definition
N_SAMPLES_PER_PARAM Number of times the kernel density estimate (KDE) is evaluated after creating the KDE from simulations of each set of model parameters

ESTIMATOR Section:

Option Definition
TYPE Likelihood estimator type: kde (default) or pyddm

To make your own configuration file, you can copy the example above into a new .yaml file and modify it with your preferences.

If you are using uv (see below), you can use the uv run command to run generate from the command line

This will generate training data according to your configuration and save it in the specified output directory.

Key Features

Custom Parameter Transforms

Register custom transformations to apply model-specific modifications to sampled parameters:

from ssms import register_transform_function
import numpy as np

# Register a custom transform
def exponential_drift(theta: dict) -> dict:
    if 'v' in theta:
        theta['v'] = np.exp(theta['v'])
    return theta

register_transform_function("exp_v", exponential_drift)

# Use in model configuration
model_config = {
    "name": "my_model",
    "params": ["v", "a", "z", "t"],
    "param_bounds": [...],
    "parameter_transforms": [
        {"type": "exp_v"}  # Your custom transform
    ]
}

Tutorial

Check the basic tutorial in our documentation.

Advanced: Dependency Management with uv

We use uv for fast and efficient dependency management. To get started:

  1. Install uv:
curl -LsSf https://astral.sh/uv/install.sh | sh
  1. Install dependencies (including development):
uv sync --all-groups  # Installs all dependency groups

Building Cython Extensions from Source

For development or to rebuild with different settings:

# Clean environment and sync
rm -rf .venv && uv sync

# Rebuild Cython extensions (editable install)
uv pip install --python .venv/bin/python -e . --reinstall

Important: Always use uv pip install --python .venv/bin/python to ensure extensions are built for the correct Python version in your virtual environment.

Contributing

We welcome contributions from the community! Whether you want to add a new model, improve documentation, or fix bugs, your help is appreciated.

Contributing New Models

Want to add your own sequential sampling model to the package? Check out our comprehensive guide:

📖 Contributing New Models Tutorial

This guide walks you through three levels of contribution:

  • Level 1: Add boundary/drift variants (~15 min)
  • Level 2: Implement Python simulators (~20 min)
  • Level 3: Create high-performance Cython implementations (~30 min)

Other Contributions

For bug reports, feature requests, or general questions:

  • Open an issue on GitHub Issues
  • Check existing issues to avoid duplicates
  • Provide clear descriptions and reproducible examples

Cite ssm-simulators

Please use the this DOI to cite ssm-simulators: https://doi.org/10.5281/zenodo.17156205

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

ssm_simulators-0.12.1.tar.gz (2.4 MB view details)

Uploaded Source

Built Distributions

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

ssm_simulators-0.12.1-cp312-cp312-win_amd64.whl (3.6 MB view details)

Uploaded CPython 3.12Windows x86-64

ssm_simulators-0.12.1-cp312-cp312-musllinux_1_2_x86_64.whl (11.7 MB view details)

Uploaded CPython 3.12musllinux: musl 1.2+ x86-64

ssm_simulators-0.12.1-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (11.7 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

ssm_simulators-0.12.1-cp312-cp312-macosx_11_0_arm64.whl (3.7 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

ssm_simulators-0.12.1-cp312-cp312-macosx_10_13_x86_64.whl (3.8 MB view details)

Uploaded CPython 3.12macOS 10.13+ x86-64

ssm_simulators-0.12.1-cp311-cp311-win_amd64.whl (3.6 MB view details)

Uploaded CPython 3.11Windows x86-64

ssm_simulators-0.12.1-cp311-cp311-musllinux_1_2_x86_64.whl (12.0 MB view details)

Uploaded CPython 3.11musllinux: musl 1.2+ x86-64

ssm_simulators-0.12.1-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (11.9 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

ssm_simulators-0.12.1-cp311-cp311-macosx_11_0_arm64.whl (3.7 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

ssm_simulators-0.12.1-cp311-cp311-macosx_10_9_x86_64.whl (3.8 MB view details)

Uploaded CPython 3.11macOS 10.9+ x86-64

File details

Details for the file ssm_simulators-0.12.1.tar.gz.

File metadata

  • Download URL: ssm_simulators-0.12.1.tar.gz
  • Upload date:
  • Size: 2.4 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for ssm_simulators-0.12.1.tar.gz
Algorithm Hash digest
SHA256 f49040d6a186daa51db98f73111e17b2edcfae1a39a9ce6a9d29176ba4cf4283
MD5 d00ab96c803a62efcf0b8352b2e533a3
BLAKE2b-256 22fcba8721d170a784feb0d98f96373d7f2ea5b2a648a06dafd17a7e6bb6a08a

See more details on using hashes here.

File details

Details for the file ssm_simulators-0.12.1-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for ssm_simulators-0.12.1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 41ffda275849b7915f3aa2fe6e1cc6fa5a1bbb440e68fb08594adfd687761441
MD5 32059fff3887ab4b5b3946971dd2bd77
BLAKE2b-256 02ef02f5000a4d9a7b71fdf750267d42963e1531a6b3e4f3c6059ab6985bc6bc

See more details on using hashes here.

File details

Details for the file ssm_simulators-0.12.1-cp312-cp312-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for ssm_simulators-0.12.1-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 b6894d2fa7548be027af3d3aca63e3bb2daae9b33fe4fe5c5d2c723f273040c8
MD5 2b1e29ad86e76e321a7167e676b9e72b
BLAKE2b-256 0f400864fdbeeea5d891bf8ce3325680cbc789994d389bf56d37d3449e0e86fc

See more details on using hashes here.

File details

Details for the file ssm_simulators-0.12.1-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for ssm_simulators-0.12.1-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 b646685d574092cfb833209e5fe338d65081287592a785227abfd84c6cf12cba
MD5 f25a87cd44bddd33a884d540ef041c8d
BLAKE2b-256 43c71ec09ec4e43c2698f12f6074d7f22534e255d879f0f4fe27bff025415710

See more details on using hashes here.

File details

Details for the file ssm_simulators-0.12.1-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for ssm_simulators-0.12.1-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b879fd7f4a9d226c1bdc6c76323022f7cc0da3db4dec17b8e132c18eca2ef50a
MD5 85e46f9dc7862ba50a027951f3f3d6d1
BLAKE2b-256 3efcb849377a70623a0e10adea628a2de05dff05d06d322d0bcff470dc028af9

See more details on using hashes here.

File details

Details for the file ssm_simulators-0.12.1-cp312-cp312-macosx_10_13_x86_64.whl.

File metadata

File hashes

Hashes for ssm_simulators-0.12.1-cp312-cp312-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 7db972d24e03798f8ff97e005ae553a8c9490bfe691f29c8ae3b639bb453962b
MD5 ae58ecc920cfd90577f2b9c10d594c5d
BLAKE2b-256 f6e99c6f165c92cdea603eabd8841e057bcf1820e28c0955e0e00061ae76958b

See more details on using hashes here.

File details

Details for the file ssm_simulators-0.12.1-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for ssm_simulators-0.12.1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 f7e6196b018458567240d7f320ce2e320a221703f16101236e2e935557e211e6
MD5 dd26a52e8cd496634273c58d44dd6b94
BLAKE2b-256 ef0d41e202d31c2b71f99508f49f963c58c89560a02921b935910a2b0836b693

See more details on using hashes here.

File details

Details for the file ssm_simulators-0.12.1-cp311-cp311-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for ssm_simulators-0.12.1-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 c8e3dbec6adff8c421b4329a2d5db8d08f202e7afe7237d0dd6161ee7f326f49
MD5 28d77f056fed51f26f306a2fb3d523b2
BLAKE2b-256 b81d0dcb48f7b33073b3a7dba01eac6d6a6f8b44152e308b8e7ebe424a99bf65

See more details on using hashes here.

File details

Details for the file ssm_simulators-0.12.1-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for ssm_simulators-0.12.1-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 f62caef94e5925c749d943727b1fec76075e74eaa2d96f031ec262f4714d3c25
MD5 7d77418863f59378680d0f40e6b58317
BLAKE2b-256 07cfaafcc6cc1334228ee6dd6f0eb3aba36e2a7553e44f5a988893da62c26fb3

See more details on using hashes here.

File details

Details for the file ssm_simulators-0.12.1-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for ssm_simulators-0.12.1-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 fc91f51233aab9240a854c00db21fc1e77c0052750b2efd858ef1b67f211ab92
MD5 ce0af8f17f5857e225fc59a89a138bfe
BLAKE2b-256 25f0349a516cf61b74869e0be4ebae3b041065cd00138124f542937e95bb4dec

See more details on using hashes here.

File details

Details for the file ssm_simulators-0.12.1-cp311-cp311-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for ssm_simulators-0.12.1-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 9ffc961c5e5c1779e76086d67a04715f9c314496a17e7c8e3d44724b5d907804
MD5 766255e2641bfeb58e2fa0c938462fc0
BLAKE2b-256 3fe41b6b201fd2d8cfcc3cf3e143ff2a396fda2c12d6b2b9ce5e927d77e6132c

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