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.2.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.2-cp312-cp312-win_amd64.whl (3.6 MB view details)

Uploaded CPython 3.12Windows x86-64

ssm_simulators-0.12.2-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.2-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.2-cp312-cp312-macosx_11_0_arm64.whl (3.7 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

ssm_simulators-0.12.2-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.2-cp311-cp311-win_amd64.whl (3.6 MB view details)

Uploaded CPython 3.11Windows x86-64

ssm_simulators-0.12.2-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.2-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.2-cp311-cp311-macosx_11_0_arm64.whl (3.7 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

ssm_simulators-0.12.2-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.2.tar.gz.

File metadata

  • Download URL: ssm_simulators-0.12.2.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.2.tar.gz
Algorithm Hash digest
SHA256 a66839001d13cc53a88ae08e9b94d2a70d1988635c9c3aeda428c952314ab065
MD5 f1d3a064b55a246a46be03b45368fd08
BLAKE2b-256 4fbf4fef5a5d5f9450fc494ed67c5fbf5e26ee7ed8e959c93a2d09854c2d59dc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.12.2-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 d74c440746a8a97aee92d90f3a70bed47ba45b8647594496d9c83428218f11d4
MD5 884b640d31dbce84d7f09601286ad413
BLAKE2b-256 b764a1da3433b54a6478a18d372652d64cda2ffb219ad2e9ab87167bef45d94f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.12.2-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 55b3c82b9b17a994a041beb5ba5e4cd373ffaf9be9f03cc642213041388e44ea
MD5 228ea8b191bdbe15cdaa690580a34571
BLAKE2b-256 21e8b71969d582599ab5d008218c7e215d4d8df5c1aafeb82536fec1ccc66feb

See more details on using hashes here.

File details

Details for the file ssm_simulators-0.12.2-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.2-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 9ebb53c8151d5806c562a6868f6f5b7297a808ecf04d6c35c2f1f65f5ff5c7b2
MD5 7c329ded7cc12d414a26c52c2547918f
BLAKE2b-256 e0c801f6ecf128c78c0fbe2c56430119ec606849e1a6bf41193b5da7950fe5bb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.12.2-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 752558daf2393c82759743f2631d6a634145e65fdc4aa0e9257f2069efa09136
MD5 00d88025aa38b3132ecc6d20004bdbea
BLAKE2b-256 3db7883f582af5eabbf95d8fc960652f2bac23919e2f03fef9fe687558bb0195

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.12.2-cp312-cp312-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 b115c73880e01fed2f37266ed5a6ab63e036c4ed11a644914c135d5385b2d14b
MD5 d03c8db96e76f6db8939ad9aba5a7b63
BLAKE2b-256 b70f95ccfb331e0548d0cbe6a06c8333d2bdd626f97937adaa017d383fa26ba0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.12.2-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 d9bedf876789bd1a6ff48853317f47d0a05e7658ad073bc68bcad5dccd1a9360
MD5 a3ef651463d2e906dd887bdb74246c4e
BLAKE2b-256 d3314995d8f9dcb2ca1260112f333372feba3321305f29f2bd62e8514c7cf1c2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.12.2-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 54886b4b2fb81be676fd0dc17034cd1a17bdf66323c61bd7632bfff2a54a483b
MD5 d3480d992ab19b5ebc4514a5bbbfecd5
BLAKE2b-256 a7d62849b332b40e9092139b3b82a1f1681c0912bec99c26b47a59a0763d15c8

See more details on using hashes here.

File details

Details for the file ssm_simulators-0.12.2-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.2-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 d420b471882ef7a682889f5a0099f75789a5770d6e1f558e142a7882a3a07a75
MD5 9c453fb464d342ab62af1dba30f1b4a6
BLAKE2b-256 255abc2d0e176c0c7ce661a21423ccc72d4fa5fe88796b8c3c2ed4fdebc400bf

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.12.2-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7ee4d0852804ce3570e2d1ecef4916eeff90404a5065fc713cb85e360a947e72
MD5 22327d1b81050fecb64a4d099d9e00ba
BLAKE2b-256 7baa2b3affaef8986869a62e92ac5ac221d67d39beb56f23658f8e31b4c7ab20

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ssm_simulators-0.12.2-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 b603ad5003ae504a9db10df476e97025b88df779c20ff40a6cfc77220e9bf887
MD5 fb96db3ed95e628ada2f7d14a0fcd102
BLAKE2b-256 e1dec5a3bb98d58773110dd82e1c160302b9f8cd66d98e57182deb95e93de53e

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