def __setup(self, sim_time=500.):
        """Setup the simulation

        :sim_time: time for each simulation phase
        :file_prefix: output file prefix
        :returns: nothing

        """
        nest.ResetKernel()
        # http://www.nest-simulator.org/sli/setverbosity/
        nest.set_verbosity('M_INFO')
        nest.SetKernelStatus({
            'resolution': self.dt,
            'local_num_threads': 1,
            'overwrite_files': True
        })
        # Since I've patched NEST, this doesn't actually update connectivity
        # But, it's required to ensure that synaptic elements are connected
        # correctly when I form or delete new connections
        nest.EnableStructuralPlasticity()
        nest.CopyModel("iaf_cond_exp", "tif_neuronE")
        nest.SetDefaults('tif_neuronE', self.neuronDict)

        # do the bits
        self.__create_neurons()
        self.__get_optimal_activity()
        self.__grow_initial_elements()
        self.__return_activity_to_hom()
        self.__prepare_hypotheses()
Exemplo n.º 2
0
    def test_targets(self):
        nest.ResetKernel()
        nest.set_verbosity('M_ALL')
        # Testing with 2 MPI processes
        nest.SetKernelStatus({'resolution': 0.1, 'total_num_virtual_procs': 2})
        # Update the SP interval
        nest.EnableStructuralPlasticity()
        nest.SetKernelStatus({
            'structural_plasticity_update_interval': 1000.,
        })

        growth_curve = {
            'growth_curve': "gaussian",
            'growth_rate': 0.0001,  # Beta (elements/ms)
            'continuous': False,
            'eta': 0.1,
            'eps': 0.7,
        }
        structural_p_elements_E = {
            'Den_ex': growth_curve,
            'Den_in': growth_curve,
            'Axon_ex': growth_curve
        }
        neuronDict = {
            'V_m': -60.,
            't_ref': 5.0,
            'V_reset': -60.,
            'V_th': -50.,
            'C_m': 200.,
            'E_L': -60.,
            'g_L': 10.,
            'E_ex': 0.,
            'E_in': -80.,
            'tau_syn_ex': 5.,
            'tau_syn_in': 10.,
            'I_e': 220.
        }

        nest.SetDefaults("iaf_cond_exp", neuronDict)
        neuronsE = nest.Create('iaf_cond_exp', 1,
                               {'synaptic_elements': structural_p_elements_E})

        # synapses
        synDictE = {
            'synapse_model': 'static_synapse',
            'weight': 3.,
            'pre_synaptic_element': 'Axon_ex',
            'post_synaptic_element': 'Den_ex'
        }

        nest.SetKernelStatus(
            {'structural_plasticity_synapses': {
                'synapseEE': synDictE,
            }})

        try:
            nest.Simulate(200 * 1000)
        except Exception:
            print(sys.exc_info()[0])
            self.fail("Exception during simulation")
Exemplo n.º 3
0
 def test_multithread_enable(self):
     nest.ResetKernel()
     nest.local_num_threads = 2
     # Setting multiple threads when structural plasticity is enabled should
     # throw an exception
     with self.assertRaises(nest.kernel.NESTError):
         nest.EnableStructuralPlasticity()
Exemplo n.º 4
0
    def test_synapse_creation(self):
        for syn_model in nest.Models('synapses'):
            if syn_model not in self.exclude_synapse_model:
                nest.ResetKernel()
                syn_dict = {
                    'synapse_model': syn_model,
                    'pre_synaptic_element': 'SE1',
                    'post_synaptic_element': 'SE2'
                }
                nest.structural_plasticity_synapses = {'syn1': syn_dict}
                neurons = nest.Create('iaf_psc_alpha', 2, {
                    'synaptic_elements': {
                        'SE1': {'z': 10.0, 'growth_rate': 0.0},
                        'SE2': {'z': 10.0, 'growth_rate': 0.0}
                    }
                })
                nest.EnableStructuralPlasticity()
                nest.Simulate(10.0)
                status = nest.GetStatus(neurons, 'synaptic_elements')
                for st_neuron in status:
                    self.assertEqual(10, st_neuron['SE1']['z_connected'])
                    self.assertEqual(10, st_neuron['SE2']['z_connected'])

                self.assertEqual(
                    20, len(nest.GetConnections(neurons, neurons, syn_model)))
                break
Exemplo n.º 5
0
    def test_enable_multithread(self):

        nest.ResetKernel()
        nest.EnableStructuralPlasticity()
        # Setting multiple threads when structural plasticity is enabled should
        # throw an exception
        with self.assertRaises(nest.NESTError):
            nest.SetKernelStatus({'local_num_threads': 2})
Exemplo n.º 6
0
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

    growth_curve = {
        'growth_curve': 'gaussian',
        'growth_rate': 0.0001,  # Beta (elements/ms)
        'continuous': False,
        'eta': 0.1,
        'eps': 0.7,
    }
    structural_p_elements_E = {
        'Den_ex': growth_curve,
        'Den_in': growth_curve,
        'Axon_ex': growth_curve
    }
    neuronDict = {
        'V_m': -60.,
        't_ref': 5.0,
        'V_reset': -60.,
        'V_th': -50.,
        'C_m': 200.,
        'E_L': -60.,
        'g_L': 10.,
        'E_ex': 0.,
        'E_in': -80.,
        'tau_syn_ex': 5.,
        'tau_syn_in': 10.,
        'I_e': 220.
    }

    nest.SetDefaults('iaf_cond_exp', neuronDict)
    neuronsE = nest.Create('iaf_cond_exp', 1,
                           {'synaptic_elements': structural_p_elements_E})

    synDictE = {
        'synapse_model': 'static_synapse',
        'weight': 3.,
        'pre_synaptic_element': 'Axon_ex',
        'post_synaptic_element': 'Den_ex'
    }
    nest.structural_plasticity_synapses = {'synapseEE': synDictE}

    nest.Simulate(200 * 1000)
Exemplo n.º 7
0
def run():
    vc = VirtualConnectome()
    vc.prepare_simulation()
    vc.create_nodes()
    vc.connect_external_input()
    nest.EnableStructuralPlasticity()
    while vc.get_quit_state() == False:
        while vc.get_pause_state() == False:
            vc.simulate()
            if nest.Rank() == 0:
                print 'iteration done'
            if vc.get_save_state() == True:
                vc.store_current_connections()
 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 and nest.Rank() == 0:
             print("Progress: " + str(i / 2) + "%")
     print("Simulation finished successfully")
Exemplo n.º 9
0
def run():
    i_counter = 1
    vc = VirtualConnectome()
    vc.prepare_simulation()
    vc.create_nodes()
    vc.connect_external_input()
    nest.EnableStructuralPlasticity()
    while vc.get_quit_state() == False:
        while vc.get_pause_state() == False:
            vc.simulate()
            if nest.Rank() == 0:
                print('Iteration ' + str(i_counter) + ' finished\n')
            i_counter = i_counter + 1
            if vc.get_save_state() == True:
                vc.store_current_connections()
Exemplo n.º 10
0
    def init():
        numproc = 1
        try:
            import nest
            nest.ResetKernel()
            # run for every process
            # same results every run
            nest.SetKernelStatus({"grng_seed": gv.seed})
            # numpy seed
            nest.EnableStructuralPlasticity()
            numproc = nest.GetKernelStatus(['total_num_virtual_procs'])[0]
        except ImportError:
            print(
                "Neural simulator Nest not found (import nest). Only able to run the simplified architecture."
            )

        np.random.seed(gv.seed)
        gv.pyrngs = [
            np.random.RandomState(s) for s in range(gv.seed, gv.seed + numproc)
        ]
Exemplo n.º 11
0
    def setup_simulation(self):
        """Set up simulation."""
        # Nest stuff
        nest.ResetKernel()
        # http://www.nest-simulator.org/sli/setverbosity/
        nest.set_verbosity('M_INFO')
        # unless using the cluster, just use 24 local threads
        # still gives out different spike files because they're different
        # virtual processes
        # Using 1 thread per core, and 24 MPI processes because I want 24
        # different firing rate files - if I don't use MPI, I only get one
        # firing rate file and I'm not sure how the 24 processes each will
        # write to it
        nest.SetKernelStatus({'resolution': self.dt, 'local_num_threads': 1})
        # Update the SP interval
        nest.EnableStructuralPlasticity()
        nest.SetStructuralPlasticityStatus({
            'structural_plasticity_update_interval':
            self.sp_update_interval,
        })

        self.__setup_neurons()
        self.__create_neurons()
        self.__setup_detectors()

        self.__setup_connections()
        self.__connect_neurons()

        self.__setup_files()

        current_simtime = (str(nest.GetKernelStatus()['time'] * 1000) + "msec")

        self.dump_ca_concentration()
        self.dump_synaptic_elements()
        self.dump_mean_synaptic_weights()
        self.dump_all_IE_weights("initial_setup-")
        self.dump_all_EE_weights("initial_setup-")
Exemplo n.º 12
0
np.save(direc + "global_seeds.npy", grng_seed)
np.save(direc + "thread_seeds.npy", rng_seeds)
np.save(direc + "numpy_seed.npy", numpy_seed)

np.random.seed(numpy_seed)

# Scaling of time
sim_steps = np.arange(1, 1 + par.cicles, 1) * par.pre_step
growth_time = sim_steps[-1]

np.save(direc + "sim_steps.npy", sim_steps)

nest.ResetKernel()

nest.EnableStructuralPlasticity()

nest.SetKernelStatus({"resolution": par.dt, "print_time": False})

nest.SetKernelStatus({
    'structural_plasticity_update_interval':
    int(par.MSP_update_interval /
        par.dt),  # update interval for MSP in time steps
    'total_num_virtual_procs':
    par.total_num_virtual_procs,
    'grng_seed':
    grng_seed,
    'rng_seeds':
    rng_seeds,
})