How TVBO handles physical units across simulation components
TVBO uses SymPy’s units system to handle physical units automatically. This enables correct unit conversions across different components of a simulation experiment.
Overview
Physical quantities appear throughout simulations:
Component
Quantities with Units
Network
distances (mm, m), delays (ms, s), conduction speed (m/s)
Integrator
step size (ms), duration (s), time scale
Dynamics
time constants (ms), frequencies (Hz)
Monitors
sampling period (ms), frequencies (Hz)
This notebook demonstrates unit handling, starting with Networks.
1. Network Units
Networks have two unit attributes that define the coordinate system:
distance_unit: Unit for edge distances/lengths (default: "mm")
time_unit: Default time unit for delays (default: "ms")
TVBO correctly handles mixed units. The conduction speed unit doesn’t need to match the network’s distance/time units:
# Speed in m/s, distances in mm, output in msnet.conduction_speed = Parameter(name="v", value=3.0, unit="m/s")delays = net.compute_delays()print(f"With speed in m/s:\n{np.round(delays, 2)}")
With speed in m/s:
[[0. 0. 0.]
[0. 0. 0.]
[0. 0. 0.]]
# Override output unitdelays_seconds = net.compute_delays("s")print(f"Delays in seconds:\n{delays_seconds}")
# Network with distances in meters and time in secondsnet_si = Network.from_matrix( W, lengths=L /1000, # Convert mm to m distance_unit="m", time_unit="s")net_si.conduction_speed = Parameter(name="v", value=3.0, unit="m/s")delays_si = net_si.compute_delays()print(f"SI units - delays in seconds:\n{delays_si}")
SI units - delays in seconds:
[[0. 0. 0.]
[0. 0. 0.]
[0. 0. 0.]]
1.4 Supported Units
Any unit recognized by SymPy can be used:
Category
Examples
Length
mm, m, cm, km, um (micrometer)
Time
ms, s, us (microsecond), minute, hour
Speed
m/s, mm/ms, km/hour, etc.
# Example: centimeters and microsecondsnet_micro = Network.from_matrix( W, lengths=L *10, # mm to 0.1mm scale distance_unit="cm", time_unit="us")net_micro.conduction_speed = Parameter(name="v", value=3000.0, unit="m/s")delays_us = net_micro.compute_delays()print(f"Delays in microseconds:\n{np.round(delays_us, 2)}")
Number of edges: 2
Edge 0→1:
weight: 0.5
distance: 50.0 mm
delay: 16.67 ms
Edge 1→2:
weight: 0.8
distance: 30.0 mm
2. Integrator Units (Coming Soon)
The integrator’s step_size and duration will support unit-aware specification:
# Future API examplefrom tvbo.datamodel import Integratorintegrator = Integrator( method="heun", step_size=0.1, # value time_unit="ms", # unit for step_size duration=1000.0, # in time_unit)
3. Dynamics Units (Coming Soon)
Time constants and frequencies in dynamics models will be unit-aware:
# Future API examplefrom tvbo.datamodel import Parametertau = Parameter(name="tau", value=10.0, unit="ms") # time constantomega = Parameter(name="omega", value=10.0, unit="Hz") # frequency
4. Monitor Units (Coming Soon)
Sampling periods and frequencies will support units:
# Future API examplefrom tvbo.datamodel import Monitormonitor = Monitor( name="BOLD", period=2.0, period_unit="s", # TR in seconds)
Summary
Set distance_unit and time_unit on networks to define the unit system
compute_delays() automatically converts between units using SymPy
Edge parameters can include units for documentation and validation
Any SymPy-recognized unit string works (no hardcoded mappings)
Unit support will extend to Integrator, Dynamics, and Monitor components