Jaxley

repository·main·Indexed 42 days ago

https://github.com/jaxleyverse/jaxley

A differentiable simulator for biophysical neuron models built on JAX. Jaxley enables high-performance, gradient-based optimization of neural dynamics across CPU, GPU, and TPU hardware. It supports single- and multi-compartment Hodgkin-Huxley models, as well as simplified models like LIF and Izhikevich neurons. Key features include automatic differentiation, JIT-compilation, and a backward-Euler solver for numerical stability in multi-compartment simulations.

Tokens
27.5K
Snippets
88
Records
101
Agent score
53%

What's inside Jaxley

  1. What is Jaxley?

    main

    Jaxley is a differentiable simulator for biophysical neuron models built on the JAX library. It is designed for gradient-based optimization of large parameter sets and supports multicompartment neurons. Key technical features include:

    • Automatic Differentiation: Enables gradient-based optimization of thousands of parameters.
    • Hardware Agnostic: Runs on CPU, GPU, or TPU without code changes.
    • JIT-Compilation: Leverages JAX's jit for high-performance execution.
    • Parameter Sharing: Provides mechanisms for elegant parameter management across models.
  2. Explore the Jaxley API modules

    main

    Jaxley provides a structured API for modeling neural systems, organized into several functional modules:

    • Modules: Core structural components like Compartment, Branch, Cell, and Network.
    • Simulation: Tools for numerical integration and dynamic state management via jaxley.integrate and jaxley.utils.dynamics.
    • Morphologies: Functions for handling morphology data, including reading SWC files (read_swc), calculating distances (distance_direct, distance_pathwise), and modifying structures (morph_delete, morph_connect).
    • Channels: Ion channel models such as HH (Hodgkin-Huxley), Izhikevich, Rate, Fire, and specific ion types like Na, K, Leak, Km, CaL, and CaT.
    • Pumps: Ion pump models including CaPump, CaFaradayConcentrationChange, and CaNernstReversal.
    • Synapses: Synaptic models such as IonotropicSynapse and various rate/conductance-based synapses (TanhRateSynapse, TanhConductanceSynapse).
    • Connectivity: Methods for establishing connections between components, including connect, connectivity_matrix_connect, fully_connect, and sparse_connect.
    • Optimization: Transformation tools for optimization tasks (e.g., SigmoidTransform, LogisticTransform, AffineTransform) and TypeOptimizer.
    • Graph Backend: Utilities for graph-based representations of compartments and morphologies, including to_swc_graph, build_compartment_graph, and visualization tools.
  3. Supported biophysical neuron models in Jaxley

    main

    Jaxley is designed for biophysical, Hodgkin-Huxley-type models and their networks. It provides high flexibility and accuracy for:

    • Single-compartment (point neuron) Hodgkin-Huxley models
    • Multi-compartment Hodgkin-Huxley models

    Key capabilities for biophysical models include:

    • Adding new channel models.
    • Using various synapse types (e.g., conductance-based, tanh).
    • Inserting different channel types into specific branches or compartments within a single cell.
    • Simulating complex ion dynamics such as diffusion and pumps.

    Jaxley implements a backward-Euler solver to ensure stable numerical solutions for multi-compartment neurons, similar to the NEURON simulator but built using JAX.

  4. Supported simplified neuron models in Jaxley

    main

    Jaxley supports the simulation of simplified neuron models and their networks, including:

    • Leaky-integrate-and-fire (LIF) neurons
    • Izhikevich neurons
    • Rate-based neurons

    Limitation Note: For LIF and Izhikevich models, Jaxley does not currently support surrogate gradient descent. This means these specific models cannot be used for efficient training that relies on backpropagating through discontinuous spikes.

  5. Getting started with Jaxley tutorials

    main

    Jaxley provides a series of step-by-step tutorials designed to guide you through the core concepts and usage of the library. It is recommended to follow these tutorials in order to build a foundational understanding of the framework.

    Recommended Learning Path:

    1. Morph Neurons: Learn about neuron morphology.
    2. Small Network: Understand how to construct and manage small-scale neural networks.
    3. JIT and Vmap: Learn how to leverage JAX transformations like jit and vmap within the Jaxley ecosystem.
    4. Channel and Synapse Models: Explore detailed modeling of ion channels and synaptic connections.
    5. Gradient Descent: Understand how to apply optimization techniques to your models.
  6. Install the most recent stable version of Jaxley

    main

    Install the stable version of Jaxley with CPU support using pip.

    If you require GPU support, you must install JAX with GPU support separately following the instructions in the JAX GitHub repository. For NVIDIA GPUs, you can install the CUDA-enabled version of JAX using the command below after installing Jaxley.

    pip install jaxley
    
    # For NVIDIA GPU support (install JAX with CUDA)
    pip install -U "jax[cuda13]"
  7. Build the Sphinx documentation

    main

    To build the Sphinx documentation, use make html followed by a local HTTP server to view the output. This process executes all Jupyter notebooks found in the repository, collects their outputs, and incorporates them into the generated documentation.

    make html && python -m http.server --directory _build/html
  8. Install Jaxley

    main

    Install jaxley via PyPI for default CPU support. If you require GPU support, you must first install JAX with the appropriate CUDA support for your hardware (e.g., NVIDIA GPUs) before or alongside installing jaxley.

    # Install Jaxley with CPU support
    pip install jaxley
    
    # Example: Install JAX with CUDA 13 support for NVIDIA GPUs
    pip install -U "jax[cuda13]"
  9. Build the documentation locally

    main

    To preview the documentation locally, navigate to the mkdocs/ directory and run the jupyter nbconvert command to transform tutorials into markdown, followed by the mkdocs serve command to start a local web server.

    jupyter nbconvert --to markdown ../docs/tutorials/*.ipynb --output-dir docs/tutorial/
    mkdocs serve
  10. Deploy the documentation to GitHub Pages

    main

    To update the hosted documentation on GitHub, navigate to the mkdocs/ directory and run the jupyter nbconvert command to process tutorials, then use mkdocs gh-deploy to push the built site to GitHub Pages.

    jupyter nbconvert --to markdown ../docs/tutorials/*.ipynb --output-dir docs/tutorial/
    mkdocs gh-deploy
  11. Install Jaxley from source

    main

    To install Jaxley in editable mode from the source repository, clone the repository and use pip install -e ..

    Requirement: You must use pip >= 21.3 to support editable installations using pyproject.toml.

    git clone https://github.com/jaxleyverse/jaxley.git
    cd jaxley
    pip install -e .