Skip to main content

Optimization tools for The Virtual Brain

Project description

TVB-Optim

Tests Ruff Python 3.11+ PyPI version

JAX-based framework for brain network simulation and gradient-based optimization.

Documentation | Get Started | Network Dynamics

Key Features

  • Gradient-based optimization: Fit thousands of parameters using automatic differentiation through the entire simulation pipeline
  • Performance: JAX-powered with seamless GPU/TPU scaling
  • Flexible & extensible: Build models with Network Dynamics, a composable framework for whole-brain modeling. Existing TVB workflows supported via TVB-O.
  • Intuitive parameter control: Mark values for optimization with Parameter(). Define exploration spaces with Axes for automatic parallel evaluation via JAX vmap/pmap.

Installation

Requires Python 3.11 or above

# Using uv (recommended)
uv pip install tvboptim

# Using pip
pip install tvboptim

Quick Example

import jax.numpy as jnp
from tvboptim.experimental.network_dynamics import Network, solve, prepare
from tvboptim.experimental.network_dynamics.dynamics.tvb import ReducedWongWang
from tvboptim.experimental.network_dynamics.coupling import LinearCoupling
from tvboptim.experimental.network_dynamics.graph import DenseDelayGraph
from tvboptim.observations.tvb_monitors import Bold
from tvboptim.observations import compute_fc, rmse
from tvboptim.optim import OptaxOptimizer
import optax

# Build brain network model
network = Network(
    dynamics=ReducedWongWang(),
    coupling={'delayed': LinearCoupling(incoming_states="S", G=0.5)},
    graph=DenseDelayGraph(weights, delays)
)

# Run simulation
result = solve(network, Heun(), t0=0.0, t1=60_000.0, dt=1.0)

# Optimize coupling strength to match empirical functional connectivity
simulator, params = prepare(network, Heun(), t0=0.0, t1=60_000.0, dt=1.0)
bold_monitor = Bold(history=result, period=720.0)

def loss(params):
    predicted_fc = compute_fc(bold_monitor(simulator(params)))
    return rmse(predicted_fc, target_fc)

opt = OptaxOptimizer(loss, optax.adam(learning_rate=0.03))
final_params, history = opt.run(params, max_steps=50)

See the full example with visualization in the documentation.

Documentation

How It Works

Functional Composition: Models are composable functions that can be inspected, modified, and extended. Build complexity incrementally by wrapping functions.

End-to-End Differentiability: Compute gradients through the full pipeline: neural dynamics → hemodynamic models → empirical observables.

Interoperability: Convert existing TVB simulations to JAX-compatible functions via the TVB-O framework.

Contributing

We welcome contributions and questions from the community!

Contact

Questions or want to collaborate? Reach out:

  • marius.pille[at]bih-charite.de

Citation

If you use TVB-Optim in your research, please cite:

@article{2025tvboptim,
  title={Fast and Easy Whole-Brain Network Model Parameter Estimation with Automatic Differentiation},
  author={Pille, Marius and Martin, Leon and Richter, Emilius and Perdikis, Dionysios and Schirner, Michael and Ritter, Petra},
  journal={bioRxiv},
  year={2025},
  doi={10.1101/2025.11.18.689003}
}

Copyright © 2025 Charité Universitätsmedizin Berlin

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

tvboptim-0.2.1.tar.gz (118.8 kB view details)

Uploaded Source

Built Distribution

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

tvboptim-0.2.1-py3-none-any.whl (148.5 kB view details)

Uploaded Python 3

File details

Details for the file tvboptim-0.2.1.tar.gz.

File metadata

  • Download URL: tvboptim-0.2.1.tar.gz
  • Upload date:
  • Size: 118.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for tvboptim-0.2.1.tar.gz
Algorithm Hash digest
SHA256 90fa76fb4388ab6cc4946fd5257bbe94eaa843dec209657fa73def2796bb5046
MD5 c8c2415e7436bce30e0f8bc070f7faa0
BLAKE2b-256 35a8f1cfeeee35af3a764fb7aabb6d4eb48f2271d1d72f27a9bbe98f08532410

See more details on using hashes here.

Provenance

The following attestation bundles were made for tvboptim-0.2.1.tar.gz:

Publisher: publish-pypi.yml on virtual-twin/tvboptim

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tvboptim-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: tvboptim-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 148.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for tvboptim-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 46b8a77b8b2cac6b661d4a7a5961077362985953e98ab2ffbfec98746d067e5f
MD5 1138e29b498310643152fa748d4eb759
BLAKE2b-256 36a97899c8348688e04b6255b5c42865316f2bedd96f7ad41449c4620f6b14fb

See more details on using hashes here.

Provenance

The following attestation bundles were made for tvboptim-0.2.1-py3-none-any.whl:

Publisher: publish-pypi.yml on virtual-twin/tvboptim

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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