File: examples-multiprocessing_taskfarm.txt

package info (click to toggle)
brian 1.4.3-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, stretch
  • size: 23,436 kB
  • sloc: python: 68,707; cpp: 29,040; ansic: 5,182; sh: 111; makefile: 61
file content (45 lines) | stat: -rw-r--r-- 1,172 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
.. currentmodule:: brian

.. index::
   pair: example usage; plot
   pair: example usage; ylabel
   pair: example usage; xlabel
   pair: example usage; show

.. _example-multiprocessing_taskfarm:

Example: taskfarm (multiprocessing)
===================================

Uses the :func:`~brian.tools.taskfarm.run_tasks` function to run a task on
multiple CPUs and save the results to a
:class:`~brian.tools.datamanager.DataManager` object.

::

    from brian import *
    from brian.tools.datamanager import *
    from brian.tools.taskfarm import *
    
    def find_rate(k, report):
        eqs = '''
        dV/dt = (k-V)/(10*ms) : 1
        '''
        G = NeuronGroup(1000, eqs, reset=0, threshold=1)
        M = SpikeCounter(G)
        run(30*second, report=report)
        return (k, mean(M.count)/30)
    
    if __name__=='__main__':
        N = 20
        dataman = DataManager('taskfarmexample')
        if dataman.itemcount()<N:
            M = N-dataman.itemcount()
            run_tasks(dataman, find_rate, rand(M)*19+1)
        X, Y = zip(*dataman.values())
        plot(X, Y, '.')
        xlabel('k')
        ylabel('Firing rate (Hz)')
        show()