Note
Click here to download the full example code or to run this example in your browser via Binder
04. Use MPI backend for parallelization¶
This example demonstrates how to use the MPI backend for simulating dipoles using HNN-core.
The MPI backend allows running the simulation in parallel across neurons in the network even with a single trial. For this, you will need the MPI related software installed. Note that if you want to simulate in parallel across trials, the Joblib backend allows this without the need to install and configure MPI.
# Authors: Mainak Jas <mjas@mgh.harvard.edu>
# Blake Caldwell <blake_caldwell@brown.edu>
Let us import hnn_core
import os.path as op
import hnn_core
from hnn_core import simulate_dipole, jones_2009_model
Following the alpha example, we add a ~10 Hz “bursty” drive starting at 50 ms and continuing to the end of the simulation. Each burst consists of a pair (2) of spikes, spaced 10 ms apart. The occurrence of each burst is jittered by a random, normally distributed amount (20 ms standard deviation). We repeat the burst train 10 times, each time with unique randomization.
net = jones_2009_model()
weights_ampa = {'L2_pyramidal': 5.4e-5, 'L5_pyramidal': 5.4e-5}
net.add_bursty_drive(
'bursty', tstart=50., burst_rate=10, burst_std=20., numspikes=2,
spike_isi=10, n_drive_cells=10, location='distal',
weights_ampa=weights_ampa, event_seed=8)
Finally, to simulate we use the
MPIBackend
class. This will
start the simulation across the number of processors (cores) specified by
n_procs
using MPI. The 'mpiexec'
launcher is used from
openmpi
, which must be installed on the system
Out:
MPI will run over 2 processes
Running 1 trials...
numprocs=2
Loading custom mechanism files from /home/ryan/hnn-core/hnn_core/mod/x86_64/.libs/libnrnmech.so
Building the NEURON model
Loading custom mechanism files from /home/ryan/hnn-core/hnn_core/mod/x86_64/.libs/libnrnmech.so
[Done]
running trial 1 on 2 cores
Simulation time: 0.03 ms...
Simulation time: 10.0 ms...
Simulation time: 20.0 ms...
Simulation time: 30.0 ms...
Simulation time: 40.0 ms...
Simulation time: 50.0 ms...
Simulation time: 60.0 ms...
Simulation time: 70.0 ms...
Simulation time: 80.0 ms...
Simulation time: 90.0 ms...
Simulation time: 100.0 ms...
Simulation time: 110.0 ms...
Simulation time: 120.0 ms...
Simulation time: 130.0 ms...
Simulation time: 140.0 ms...
Simulation time: 150.0 ms...
Simulation time: 160.0 ms...
Simulation time: 170.0 ms...
Simulation time: 180.0 ms...
Simulation time: 190.0 ms...
Simulation time: 200.0 ms...
Simulation time: 210.0 ms...
Simulation time: 220.0 ms...
Simulation time: 230.0 ms...
Simulation time: 240.0 ms...
Simulation time: 250.0 ms...
Simulation time: 260.0 ms...
Simulation time: 270.0 ms...
Simulation time: 280.0 ms...
Simulation time: 290.0 ms...
Simulation time: 300.0 ms...
<Figure size 640x480 with 1 Axes>
Total running time of the script: ( 0 minutes 22.707 seconds)