def prepare_simulation(self):
        nest.ResetKernel()
        nest.set_verbosity('M_ERROR')

####################################################################################
# We set global kernel parameters. Here we define the resolution
# for the simulation, which is also the time resolution for the update
# of the synaptic elements.

        nest.SetKernelStatus(
            {
                'resolution': self.dt
            }
        )


####################################################################################
# Set Structural Plasticity synaptic update interval which is how often
# the connectivity will be updated inside the network. It is important
# to notice that synaptic elements and connections change on different
# time scales.

        nest.SetStructuralPlasticityStatus({
            'structural_plasticity_update_interval': self.update_interval,
        })


####################################################################################
# Now we define Structural Plasticity synapses. In this example we create
# two synapse models, one for excitatory and one for inhibitory synapses.
# Then we define that excitatory synapses can only be created between a
# pre-synaptic element called `Axon_ex` and a post synaptic element
# called `Den_ex`. In a similar manner, synaptic elements for inhibitory
# synapses are defined.

        nest.CopyModel('static_synapse', 'synapse_ex')
        nest.SetDefaults('synapse_ex', {'weight': self.psc_e, 'delay': 1.0})
        nest.CopyModel('static_synapse', 'synapse_in')
        nest.SetDefaults('synapse_in', {'weight': self.psc_i, 'delay': 1.0})
        nest.SetStructuralPlasticityStatus({
            'structural_plasticity_synapses': {
                'synapse_ex': {
                    'model': 'synapse_ex',
                    'post_synaptic_element': 'Den_ex',
                    'pre_synaptic_element': 'Axon_ex',
                },
                'synapse_in': {
                    'model': 'synapse_in',
                    'post_synaptic_element': 'Den_in',
                    'pre_synaptic_element': 'Axon_in',
                },
            }
        })
예제 #2
0
 def load_sp_state(self):
     if nest.Rank() != 0:
         return
     f = open('sp_status_.bin', 'r')
     var = f.read()
     print str(var)
     status = ast.literal_eval(var)
     nest.SetStructuralPlasticityStatus(status)
     f.close()
예제 #3
0
class TestGetStructuralPlasticityStatus(unittest.TestCase):
    neuron_model = 'iaf_psc_alpha'
    nest.CopyModel('static_synapse', 'synapse_ex')
    nest.SetDefaults('synapse_ex', {'weight': 1.0, 'delay': 1.0})
    nest.SetStructuralPlasticityStatus({
        'structural_plasticity_synapses': {
            'synapse_ex': {
                'model': 'synapse_ex',
                'post_synaptic_element': 'Den_ex',
                'pre_synaptic_element': 'Axon_ex',
            },
        }
    })

    growth_curve = {
        'growth_curve': "gaussian",
        'growth_rate': 0.0001,  # (elements/ms)
        'continuous': False,
        'eta': 0.0,  # Ca2+
        'eps': 0.05
    }

    '''
    Now we assign the growth curves to the corresponding synaptic
    elements
    '''
    synaptic_elements = {
        'Den_ex': growth_curve,
        'Den_in': growth_curve,
        'Axon_ex': growth_curve,
    }
    nodes = nest.Create(neuron_model,
                        2,
                        {'synaptic_elements': synaptic_elements}
                        )
    all = nest.GetStructuralPlasticityStatus()
    print(all)
    assert ('structural_plasticity_synapses' in all)
    assert ('syn1' in all['structural_plasticity_synapses'])
    assert ('structural_plasticity_update_interval' in all)
    assert (all['structural_plasticity_update_interval'] == 1000)

    sp_synapses = nest.GetStructuralPlasticityStatus(
        'structural_plasticity_synapses'
    )
    print(sp_synapses)
    syn = sp_synapses['syn1']
    assert ('pre_synaptic_element' in syn)
    assert ('post_synaptic_element' in syn)
    assert (syn['pre_synaptic_element'] == 'Axon_ex')
    assert (syn['post_synaptic_element'] == 'Den_ex')

    sp_interval = nest.GetStructuralPlasticityStatus(
        'structural_plasticity_update_interval'
    )
    print(sp_interval)
    assert (sp_interval == 1000)
예제 #4
0
    def prepare_simulation(self):
        nest.ResetKernel()
        nest.set_verbosity('M_ERROR')
        nest.SetKernelStatus({'resolution': self.dt, 'grng_seed': 0})

        nest.SetStructuralPlasticityStatus({
            'structural_plasticity_update_interval':
            self.update_interval,
        })
        self.get_mnist_data()
예제 #5
0
    def prepare_simulation(self):
        nest.ResetKernel()
        nest.set_verbosity('M_ERROR')
        nest.SetKernelStatus({'resolution': self.dt})
        '''
        Set Structural Plasticity synaptic update interval 
	'''
        nest.SetStructuralPlasticityStatus({
            'structural_plasticity_update_interval':
            self.update_interval,
        })
        '''
        Set Number of virtual processes. Remember SP does not work well with openMP right now, so calls must always be done using mpiexec
	'''
        nest.SetKernelStatus({'total_num_virtual_procs': 8})
        #nest.SetKernelStatus({'total_num_virtual_procs': 1})
        '''
        Now we define Structural Plasticity synapses. One for the inner inhibition of each region and one 
	static synaptic model for the DTI obtained connectivity data. 
        '''
        spsyn_names = ['synapse_in' + str(nam) for nam in range(self.regions)]
        nest.CopyModel('static_synapse', 'synapse_ex')
        nest.SetDefaults('synapse_ex', {
            'weight': self.psc_e * 10,
            'delay': 1.0
        })
        sps = {}
        for x in range(0, self.regions):
            nest.CopyModel('static_synapse', 'synapse_in' + str(x))
            nest.SetDefaults('synapse_in' + str(x), {
                'weight': self.psc_i * 1000,
                'delay': 1.0
            })
            sps[spsyn_names[x]] = {
                'model': 'synapse_in' + str(x),
                'post_synaptic_element': 'Den_in' + str(x),
                'pre_synaptic_element': 'Axon_in' + str(x),
            }

        nest.SetStructuralPlasticityStatus(
            {'structural_plasticity_synapses': sps})
예제 #6
0
	def simulate(self):
		if nest.Rank() == 0:
			self.send_num_regions()
		self.update_update_interval()
   
		nest.SetStructuralPlasticityStatus({'structural_plasticity_update_interval': self.update_interval, })

		self.update_growth_rate()
		self.update_eta()

		nest.Simulate(self.record_interval)
		
		self.record_ca()
		self.record_connectivity()
예제 #7
0
 def test_min_max_delay_using_default_delay(self):
     nest.ResetKernel()
     delay = 1.0
     syn_model = 'static_synapse'
     nest.SetStructuralPlasticityStatus({
         'structural_plasticity_synapses': {
             'syn1': {
                 'synapse_model': syn_model,
                 'pre_synaptic_element': 'SE1',
                 'post_synaptic_element': 'SE2',
             }
         }
     })
     self.assertLessEqual(nest.GetKernelStatus('min_delay'), delay)
     self.assertGreaterEqual(nest.GetKernelStatus('max_delay'), delay)
예제 #8
0
    def simulate(self):
        self.update_update_interval()

        nest.SetStructuralPlasticityStatus({
            'structural_plasticity_update_interval':
            self.update_interval,
        })

        self.update_growth_rate()
        self.update_eta()

        if nest.Rank() == 0:
            print("Start")
        nest.Simulate(self.record_interval)
        if nest.Rank() == 0:
            print("End")

        self.record_fr()
        self.record_connectivity()
예제 #9
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 = {'model': syn_model, 'pre_synaptic_element': 'SE1', 'post_synaptic_element': 'SE2'}
                nest.SetStructuralPlasticityStatus({'structural_plasticity_synapses': {'syn1': syn_dict}})
                neurons = nest.Create('iaf_neuron', 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
예제 #10
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-")
    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.SetStructuralPlasticityStatus({
            '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.SetStructuralPlasticityStatus(
            {'structural_plasticity_synapses': {
                'synapseEE': synDictE,
            }})

        try:
            nest.Simulate(200 * 1000)
        except:
            print(sys.exc_info()[0])
            self.fail("Exception during simulation")
예제 #12
0
 def prepare_simulation(self):
     nest.ResetKernel()
     nest.set_verbosity('M_ERROR')
     '''
     We set global kernel parameters. Here we define the resolution
     for the simulation, which is also the time resolution for the update
     of the synaptic elements.
     '''
     nest.SetKernelStatus({'resolution': self.dt})
     '''
     Set Number of virtual processes. Remember SP does not work well with openMP right now, so calls must always be done using mpiexec
     '''
     nest.SetKernelStatus({'total_num_virtual_procs': self.comm.Get_size()})
     print("Total number of virtual processes set to: " +
           str(self.comm.Get_size()))
     '''
     Set Structural Plasticity synaptic update interval which is how often
     the connectivity will be updated inside the network. It is important
     to notice that synaptic elements and connections change on different
     time scales.
     '''
     nest.SetStructuralPlasticityStatus({
         'structural_plasticity_update_interval':
         self.update_interval,
     })
     '''
     Now we define Structural Plasticity synapses. In this example we create
     two synapse models, one for excitatory and one for inhibitory synapses.
     Then we define that excitatory synapses can only be created between a
     pre synaptic element called 'Axon_ex' and a post synaptic element
     called Den_ex. In a similar manner, synaptic elements for inhibitory
     synapses are defined.
     '''
     spsyn_names = ['synapse_in' + str(nam) for nam in range(self.regions)]
     spsyn_names_e = [
         'synapse_ex' + str(nam) for nam in range(self.regions)
     ]
     sps = {}
     for x in range(0, self.regions):
         nest.CopyModel('static_synapse', 'synapse_in' + str(x))
         nest.SetDefaults('synapse_in' + str(x), {
             'weight': self.psc_i,
             'delay': 1.0
         })
         nest.CopyModel('static_synapse', 'synapse_ex' + str(x))
         nest.SetDefaults('synapse_ex' + str(x), {
             'weight': self.psc_e,
             'delay': 1.0
         })
         sps[spsyn_names[x]] = {
             'model': 'synapse_in' + str(x),
             'post_synaptic_element': 'Den_in' + str(x),
             'pre_synaptic_element': 'Axon_in' + str(x),
         }
         sps[spsyn_names_e[x]] = {
             'model': 'synapse_ex' + str(x),
             'post_synaptic_element': 'Den_ex' + str(x),
             'pre_synaptic_element': 'Axon_ex' + str(x),
         }
     nest.SetStructuralPlasticityStatus(
         {'structural_plasticity_synapses': sps})
예제 #13
0
			}
		)
	'''
		Set Number of virtual processes. Remember SP does not work well with openMP right now, so calls must always be done using mpiexec
		'''
		nest.SetKernelStatus({'total_num_virtual_procs': self.comm.Get_size() })
		print( "Total number of virtual processes set to: " +str(self.comm.Get_size()))

		'''
		Set Structural Plasticity synaptic update interval which is how often
		the connectivity will be updated inside the network. It is important
		to notice that synaptic elements and connections change on different
		time scales.
		'''
		nest.SetStructuralPlasticityStatus({
			'structural_plasticity_update_interval': self.update_interval,
		})

		'''
		Now we define Structural Plasticity synapses. In this example we create
		two synapse models, one for excitatory and one for inhibitory synapses.
		Then we define that excitatory synapses can only be created between a
		pre synaptic element called 'Axon_ex' and a post synaptic element
		called Den_ex. In a similar manner, synaptic elements for inhibitory
		synapses are defined.
		'''
		spsyn_names=['synapse_in'+str(nam) for nam in range(self.regions)]
		spsyn_names_e=['synapse_ex'+str(nam) for nam in range(self.regions)]
		sps = {}
		for x in range(0,self.regions) :
			nest.CopyModel('static_synapse', 'synapse_in'+str(x))