コード例 #1
0
ファイル: nest_tools.py プロジェクト: n0c1urne/mnist-nest
 def from_file(cls, name):
     cores = nest.NumProcesses()
     total_times = []
     total_senders = []
     for rank in range(cores):
         filename = name + '.' + str(rank) + '.npy'
         data = np.load(filename)
         times = data.item().get('times')
         senders = data.item().get('senders')
         total_times.append(times)
         total_senders.append(senders)
     return SpikeRecording(np.concatenate(total_times),
                           np.concatenate(total_senders))
コード例 #2
0
 def simulate(self):
     if nest.NumProcesses() > 1:
         sys.exit("For simplicity, this example only works " +
                  "for a single process.")
     nest.EnableStructuralPlasticity()
     print("Starting simulation")
     sim_steps = numpy.arange(0, self.t_sim, self.record_interval)
     for i, step in enumerate(sim_steps):
         nest.Simulate(self.record_interval)
         self.record_ca()
         self.record_connectivity()
         if i % 20 == 0:
             print("Progress: " + str(i / 2) + "%")
     print("Simulation finished successfully")
コード例 #3
0
    def test_local_vps(self):
        num_procs = nest.NumProcesses()
        n_vp = 3 * num_procs
        nest.SetKernelStatus({'total_num_virtual_procs': n_vp})

        local_vps = list(nest.GetLocalVPs())

        # Use thread-vp mapping of neurons to check mapping in kernel
        nrns = nest.GetLocalNodeCollection(
            nest.Create('iaf_psc_delta', 2 * n_vp))

        for n in nrns:
            thrd = n.get('thread')
            vp = n.get('vp')
            assert vp == local_vps[thrd]
コード例 #4
0
ファイル: nest_tools.py プロジェクト: n0c1urne/mnist-nest
 def reset_nest(self):
     nest.ResetKernel()
     nest.SetKernelStatus({
         'resolution':
         params.dt,
         'print_time':
         True,
         'structural_plasticity_update_interval':
         int(params.msp_update_interval /
             params.dt),  # update interval for MSP in time steps
         'local_num_threads':
         1,
         'grng_seed':
         params.grng_seed,
         'rng_seeds':
         range(params.seed + 1, params.seed + 1 + nest.NumProcesses())
     })
コード例 #5
0
def main(config_file):
    nest.SetKernelStatus({"total_num_virtual_procs": comm.Get_size()})
    print nest.NumProcesses()
    print comm.Get_size()
    configure = config.from_json(config_file)
    io.setup_output_dir(configure)
    graph = PointGraph.from_config(configure,
                                   network_format=TabularNetwork_AI,
                                   property_schema=AIPropertySchema)

    graph.add_weight_function(fn.wmax)
    graph.add_weight_function(fn.gaussianLL)

    net = PointNetwork.from_config(configure, graph)
    net.run(configure['run']['duration'])

    assert (spike_files_equal(configure['output']['spikes_ascii'],
                              'expected/spikes.txt'))
コード例 #6
0
def test_consistent_local_vps():
    """
    Test local_vps field of kernel status.

    This test ensures that the PyNEST-generated local_vps information
    agrees with the thread-VP mappings in the kernel.
    """
    num_procs = nest.NumProcesses()
    n_vp = 3 * num_procs
    nest.SetKernelStatus({'total_num_virtual_procs': n_vp})

    local_vps = list(nest.GetLocalVPs())

    # Use thread-vp mapping of neurons to check mapping in kernel
    nrns = nest.GetLocalNodeCollection(nest.Create('iaf_psc_delta', 2 * n_vp))

    vp_direct = list(nrns.vp)
    vp_indirect = [local_vps[t] for t in nrns.thread]
    assert vp_direct == vp_indirect
コード例 #7
0
def main_pynest(parameters):
    P = parameters
    assert P.sim_name == "pynest"
    timer = Timer()
    import nest
    timer.mark("import")

    nest.SetKernelStatus({"resolution": 0.1})
    timer.mark("setup")

    p = nest.Create("iaf_psc_alpha", n=P.n, params={"I_e": 1000.0})
    timer.mark("build")

    # todo: add recording and data retrieval
    nest.Simulate(P.sim_time)
    timer.mark("run")

    mpi_rank = nest.Rank()
    num_processes = nest.NumProcesses()

    data = P.as_dict()
    data.update(num_processes=num_processes, timings=timer.marks)
    return mpi_rank, data
コード例 #8
0
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
"""
Functions for logging, writing and reading from file.

"""
import nest

from bmtk.simulator.core.io_tools import IOUtils

# Want users to be able to use NEST whether or not it is compiled in parallel mode or not, which means checking if
# the method nest.SyncPRocesses (aka MPI Barrier) exists. If it doesn't try getting barrier from mpi4py
rank = nest.Rank()
n_nodes = nest.NumProcesses()
try:
    barrier = nest.SyncProcesses
except AttributeError as exc:
    try:
        from mpi4py import MPI
        barrier = MPI.COMM_WORLD.Barrier
    except:
        # Barrier is just an empty function, no problem if running on one core.
        barrier = lambda: None


class NestIOUtils(IOUtils):
    def __init__(self):
        super(NestIOUtils, self).__init__()
        self.mpi_rank = rank
コード例 #9
0
ファイル: record_spikes.py プロジェクト: shixnya/bmtk
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
import os
import glob
import csv
import pandas as pd

from bmtk.utils.reports.spike_trains import SpikeTrains, sort_order, sort_order_lu
from bmtk.simulator.pointnet.io_tools import io
from bmtk.simulator.pointnet.nest_utils import nest_version

import nest

try:
    MPI_RANK = nest.Rank()
    N_HOSTS = nest.NumProcesses()

except Exception as e:
    MPI_RANK = 0
    N_HOSTS = 1


def create_spike_detector_nest2(label):
    return nest.Create("spike_detector", 1, {
        'label': label,
        'withtime': True,
        'withgid': True,
        'to_file': True
    })

コード例 #10
0
"""

import os
import subprocess as sp
import unittest
import nest
import numpy as np

try:
    from mpi4py import MPI
    HAVE_MPI4PY = True
except ImportError:
    HAVE_MPI4PY = False

HAVE_MPI = nest.ll_api.sli_func("statusdict/have_mpi ::")
MULTIPLE_PROCESSES = nest.NumProcesses() > 1


@unittest.skipIf(not HAVE_MPI4PY, 'mpi4py is not available')
class ConnectArraysMPICase(unittest.TestCase):
    """
    This TestCase uses mpi4py to collect and assert results from all
    processes, and is supposed to only be run with multiple processes.
    If running with nosetests or pytest, this TestCase is ignored when
    run with a single process, and called from TestConnectArraysMPI using
    multiple processes.
    """
    non_unique = np.array([1, 1, 3, 5, 4, 5, 9, 7, 2, 8], dtype=np.uint64)

    # The test class is instantiated by the unittest framework regardless of the value of
    # HAVE_MPI4PY, even though all tests will be skipped in case it is False. In this
コード例 #11
0
 def setUp(self):
     """Ensure NEST is run with correct number of MPI procs."""
     assert nest.NumProcesses() == self.req_num_mpi_procs
     nest.set_verbosity('M_ERROR')
     nest.ResetKernel()
コード例 #12
0
# connect noise generator to all neurons
nest.CopyModel('static_synapse_hom_w',
               'excitatory_input',
               {'weight': J_E,
                'delay': delay})
nest.Connect(noise, nodes, syn_spec='excitatory_input')

# connect all recorded E/I neurons to the respective detector
nest.Connect(nodes_E[:N_rec], spikes_E)
nest.Connect(nodes_I[:N_rec], spikes_I)

# Simulate -----------------------------------------------------

# Visualization of initial membrane potential and initial weight
# distribution only if we run on single MPI process
if nest.NumProcesses() == 1:

    pylab.figure()

    # membrane potential
    V_E = nest.GetStatus(nodes_E[:N_rec], 'V_m')
    V_I = nest.GetStatus(nodes_I[:N_rec], 'V_m')
    pylab.subplot(2, 1, 1)
    pylab.hist([V_E, V_I], bins=10)
    pylab.xlabel('Membrane potential V_m [mV]')
    pylab.legend(('Excitatory', 'Inibitory'))
    pylab.title('Initial distribution of membrane potentials')
    pylab.draw()

    # weight of excitatory connections
    w = nest.GetStatus(nest.GetConnections(nodes_E[:N_rec],
コード例 #13
0
#
# NEST is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with NEST.  If not, see <http://www.gnu.org/licenses/>.

import nest
import unittest

HAVE_GSL = nest.ll_api.sli_func('statusdict/have_gsl ::')


@unittest.skipIf(nest.NumProcesses() < 2, 'Requires >= 2 MPI process')
@unittest.skipIf(not HAVE_GSL, 'GSL is not available')
def test_simulation_completes():
    """
    Ensure that simulation of structural plasticity completes with MPI.

    This is a regression test for issue #576 concerning crashing simulations
    when running MPI-parallel.
    """

    nest.ResetKernel()
    nest.resolution = 0.1

    nest.EnableStructuralPlasticity()
    nest.structural_plasticity_update_interval = 1000.0
コード例 #14
0
#! ==============================

nest.ResetKernel()
nest.SetKernelStatus({'local_num_threads': 6})
nest.SetKernelStatus({'overwrite_files': True})
nest.SetKernelStatus({'resolution': resolution, 'print_time': True})

msd = 1457427778  #int(time.time())              # Master seed...
N_vp = nest.GetKernelStatus(['total_num_virtual_procs'
                             ])[0]  # Number of virtual processes...
pyrngs = [np.random.RandomState(s)
          for s in range(msd, msd + N_vp)]  # Seeding the Python RNGs
nest.SetKernelStatus({'grng_seed': msd + N_vp})  # Seeding the global RNG
nest.SetKernelStatus({'rng_seeds': range(msd + N_vp + 1, msd + 2 * N_vp + 1)
                      })  # Seeding the per-process RNGs
totMPIproc = nest.NumProcesses()

if loc_h == 0:
    print('Reading input files and setting parameters')
#! Setting Parameters
#! ==============================

# Network numbers
N_rows = 48
N_columns = 48
stencil = 4
ExtNeu = 400
ExtNeuF = float(ExtNeu)
simDuration = 10000.0
totConn = 1.5120
totConnPerMod = 0.9