parallel_run
core.Network.parallel_run(
method,=None,
networks=0,
number=-1,
max_processes=False,
measure_time=False,
sequential=False,
same_seed='',
annarchy_json=[],
visible_cores**args,
)
Allows to run multiple networks in parallel using multiprocessing.
If the networks
argument is provided as a list of Network objects, the given method will be executed for each of these networks.
If number
is given instead, the same number of networks will be created and the method is applied.
If number
is used, the created networks are not returned, you should return what you need to analyse.
Example:
= ann.PoissonPopulation(100, rates=10.0)
pop1 = ann.Population(100, ann.Izhikevich)
pop2 = ann.Projection(pop1, pop2, 'exc')
proj =5.0, probability=0.2)
proj.connect_fixed_probability(weights= ann.Monitor(pop2, 'spike')
m
compile()
ann.
def simulation(idx, net):
= 10. * idx
net.get(pop1).rates 1000.)
net.simulate(return net.get(m).raster_plot()
= ann.parallel_run(method=simulation, number = 3)
results
= results[0]
t1, n1 = results[1]
t2, n2 = results[2] t3, n3
Parameters
Name | Type | Description | Default |
---|---|---|---|
method | a Python method which will be executed for each network. This function must accept an integer as first argument (id of the simulation) and a Network object as second argument. | required | |
networks | list | a list of networks to simulate in parallel. | None |
number | int | the number of identical networks to run in parallel. | 0 |
max_processes | int | maximal number of processes to start concurrently (default: the available number of cores on the machine). | -1 |
measure_time | bool | if the total simulation time should be printed out. | False |
sequential | bool | if True, runs the simulations sequentially instead of in parallel (default: False). | False |
same_seed | bool | if True, all networks will use the same seed. If not, the seed will be randomly initialized with time(0) for each network (default). It has no influence when the networks argument is set (the seed has to be set individually for each network using net.set_seed() ), only when number is used. |
False |
annarchy_json | str | path to a different configuration file if needed (default ““). | '' |
visible_cores | list | a list of CPU core ids to simulate on (must have max_processes entries and max_processes must be != -1) | [] |
args | other named arguments you want to pass to the simulation method. | {} |
Returns
Name | Type | Description |
---|---|---|
list | a list of the values returned by each call to method . |