Skip to main content

TVB-Optim

Tests Python 3.11+ PyPI version Documentation

Fast, differentiable, and parallel whole-brain simulation and inference in JAX.

Use the same brain network model code on CPUs and GPUs. Evaluate parameter ensembles in parallel and choose the inference strategy that fits your problem, from end-to-end automatic differentiation to simulation-based and evolutionary methods.

Why TVB-Optim?

  • Accelerated simulation: JIT-compile brain network models and run them on CPUs and GPUs.
  • Parallel inference: Batch parameter sets, stochastic realizations, and candidate populations with vmap, then distribute them across devices with pmap.
  • End-to-end automatic differentiation: Differentiate through dynamics, coupling, transmission delays, observation models, and summary statistics.
  • Inference-method agnostic: Use the same simulator for gradient descent, Bayesian and simulation-based inference, genetic algorithms, parameter sweeps, and ensemble analysis.
  • Composable whole-brain models: Combine neural dynamics, connectivity, delays, coupling, noise, external inputs, solvers, and observation models with Network Dynamics.
  • Structured parameter exploration: Mark trainable values with Parameter and express Cartesian, zipped, grouped, or sampled parameter spaces with Axes and Spaces. Existing TVB workflows are supported through TVB-O.

Installation

Requires Python 3.11 or above

# Using uv (recommended)
uv pip install tvboptim

# Using pip
pip install tvboptim

Quick Example

Fit the coupling strength of an 84-region whole-brain model to empirical fMRI functional connectivity:

Imports (expand to run)
import jax
import jax.numpy as jnp
import optax

from tvboptim.data import load_functional_connectivity, load_structural_connectivity
from tvboptim.experimental.network_dynamics import Network, prepare, solve
from tvboptim.experimental.network_dynamics.coupling import DelayedLinearCoupling
from tvboptim.experimental.network_dynamics.dynamics.tvb import ReducedWongWang
from tvboptim.experimental.network_dynamics.graph import DenseDelayGraph
from tvboptim.experimental.network_dynamics.noise import AdditiveNoise
from tvboptim.experimental.network_dynamics.solvers import BoundedSolver, Heun
from tvboptim.observations import compute_fc, rmse
from tvboptim.observations.tvb_monitors import Bold
from tvboptim.optim import OptaxOptimizer
from tvboptim.types import Parameter
# Bundled structural and functional connectivity for 84 brain regions.
weights, lengths, labels = load_structural_connectivity("dk_average")
weights = weights / jnp.max(weights)
target_fc = load_functional_connectivity("dk_average")

# Build a delayed whole-brain network from the structural connectome.
network = Network(
    dynamics=ReducedWongWang(),
    coupling={"delayed": DelayedLinearCoupling(source="S", G=0.5)},
    graph=DenseDelayGraph(
        weights=weights,
        delays=lengths / 3.0,
        region_labels=labels,
    ),
    noise=AdditiveNoise(sigma=0.01, key=jax.random.key(42)),
)

# Simulate once to initialize the delay history.
solver = BoundedSolver(Heun(), low=0.0, high=1.0)
result = solve(network, solver, t0=0.0, t1=60_000.0, dt=1.0)
network.update_history(result)

# Prepare a differentiable simulator and convert neural activity to BOLD.
simulator, params = prepare(network, solver, t0=0.0, t1=60_000.0, dt=1.0)
params.coupling.delayed.G = Parameter(0.5)
bold = Bold(history=result, period=720.0)

# Compare simulated and empirical functional connectivity.
def loss(params):
    predicted_fc = compute_fc(bold(simulator(params)))
    return rmse(predicted_fc, target_fc)

# Fit the global coupling strength with Adam.
optimizer = OptaxOptimizer(loss, optax.adam(learning_rate=0.03))
fitted_params, history = optimizer.run(params, max_steps=5)

For a complete 84-region model fitting empirical fMRI functional connectivity, see the whole-brain optimization workflow or run it in Google Colab.

Agent Skill

Teach your coding agent the API you actually have installed:

tvboptim skills install --agent claude-code --scope project

Agents then look up Network, Space, or GridAxis instead of guessing at them, and load only the part of the skill a task needs. The skill describes the version you have installed, so you spend less time correcting code written for an older release. See Agent Skill for the other clients, scopes, and the Python API.

Documentation

Contributing

We welcome contributions and questions from the community!

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 © 2026 Charité Universitätsmedizin Berlin

Metadata

Release files for tvboptim 0.5.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tvboptim 0.5.1
File Size Uploaded Provenance Actions
tvboptim-0.5.1.tar.gz 1.2 MB Without provenance Details for tvboptim-0.5.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for tvboptim 0.5.1
File Interpreter ABI Platform Actions
tvboptim-0.5.1-py3-none-any.whl Python 3 none any Details for tvboptim-0.5.1-py3-none-any.whl

Total release size: 2.5 MB

Release files / tvboptim-0.5.1.tar.gz

Download URL tvboptim-0.5.1.tar.gz
Size 1.2 MB
Tags Source
SHA-256 checksum
How to use checksums
60fb2457575e4812bbed67f1df45c770f2c1ce4677de9536ee74c6b0c0e6ae32
BLAKE2b-256 checksum
How to use checksums
1e9c426ed11eeeb93d7f6bbaaa41c1a456cc9c6e003e9b99c787570145ba08d4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / tvboptim-0.5.1-py3-none-any.whl

Download URL tvboptim-0.5.1-py3-none-any.whl
Size 1.3 MB
Tags Python 3
SHA-256 checksum
How to use checksums
3417a662ab54953f56ae3452ab9ea37a78ced63fe3acce1fd7078d901b926fbb
BLAKE2b-256 checksum
How to use checksums
5590e4822f868cde67cd121540d73a5a12face88574e5fef3dfa55d3ecd0fe97
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Security for tvboptim 0.5.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page