Re: [TVB] Scripting interface, setting up region-specific parameter values for a simulation

46 views
Skip to first unread message

WOODMAN Michael

unread,
May 17, 2021, 1:20:05 AM5/17/21
to tvb-...@googlegroups.com
Hi

The model parameters are NumPy arrays so if you set one to a vector with a length equal to the number of regions, each element is used as the parameter for the corresponding region. 

Cheers

Marmaduke

On 15 May 2021, at 21:55, NeuroLife <domin...@hotmail.com> wrote:

Hi,

I am very new to TVB and just started to explore how to use it through scripting. I tried to figure out how to set up a simulation where the different regions have different parameter values (with the same local model), as is possible through the GUI, but I have not found a way of doing it. 

I've been looking through the source code and the notebook tutorials and from what I can see there is not a model for each regions, but a model for the simulation object itself. So, either I am missing something or there must be another way of setting things up that allow more flexible settings. I would be grateful if anyone could point me toward a tutorial or a documentation source that could help me figure this out

Thank you.

--
You received this message because you are subscribed to the Google Groups "TVB Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tvb-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/tvb-users/534c3753-784d-499f-be19-627258814ba2n%40googlegroups.com.

NeuroLife

unread,
May 17, 2021, 1:31:04 PM5/17/21
to TVB Users
Hi,

Thank you. This is very helpful. I would have another question. Is there a straightforward way to run simulations in parallel (as it seems to do when running PSE from the GUI)? I would like to run multiple simulations at the same time instead of doing them consecutively, but I can't seem to find anything that would allow me to do that without diving into the threading library and learning how to do it manually.

Thank you.

WOODMAN Michael

unread,
May 18, 2021, 4:53:05 AM5/18/21
to tvb-...@googlegroups.com
Hi

TVB doesn't provide anything built into the library, since workflows vary (i.e. saving, plotting, etc), but the Python multiprocessing library doesn't require any diving, most of the coding is defining your simulation and results:

import numpy as np
from tvb.simulator.lab import *
from multiprocessing import Pool

def run_sim(a):
sim = simulator.Simulator(
connectivity=connectivity.Connectivity.from_file(),
coupling=coupling.Linear(a=np.r_[a])
)
sim.configure()
(t,y), = sim.run(simulation_length=1e2)
return y[-20:].std() # variance of steady state

# define parameter to sweep
a_values = np.exp(np.r_[-3:1:16j])

# use all CPUs to run run_sim on each value of a
with Pool() as pool:
results = pool.map(run_sim, a_values)

You may wish to use the joblib package if you're using Windows or in a Jupyter notebook. 

cheers,
Marmaduke

NeuroLife

unread,
May 18, 2021, 3:34:19 PM5/18/21
to TVB Users
Hi,

Thank you for your answer!
I managed to parallelize things by using the SimThread class in the utils file in the jupyter notebook examples folder, it is significantly faster than a sequential approach. Would the multiprocessor approach be even faster than the threading approach?

Thank you.

WOODMAN Michael

unread,
May 19, 2021, 3:44:49 AM5/19/21
to tvb-...@googlegroups.com
Hi

Yes, the multiprocessing solution should be faster especially for many cores. 

cheers,
Marmaduke

--
You received this message because you are subscribed to the Google Groups "TVB Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tvb-users+...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages