def test_ConvergentDivergentConnectOptions(self): """Convergent/DivergentConnect with non-standard options and ensure that the option settings are properly restored before returning.""" nest.ResetKernel() copts = nest.sli_func( 'GetOptions', '/RandomConvergentConnect', litconv=True) dopts = nest.sli_func( 'GetOptions', '/RandomDivergentConnect', litconv=True) ncopts = dict((k, not v) for k, v in copts.items() if k != 'DefaultOptions') ndopts = dict((k, not v) for k, v in dopts.items() if k != 'DefaultOptions') n = nest.Create('iaf_neuron', 3) nest.RandomConvergentConnect(n, n, 1, options=ncopts) nest.RandomDivergentConnect(n, n, 1, options=ndopts) opts = nest.sli_func( 'GetOptions', '/RandomConvergentConnect', litconv=True) self.assertEqual(copts, opts) opts = nest.sli_func( 'GetOptions', '/RandomDivergentConnect', litconv=True) self.assertEqual(dopts, opts)
def spore_connection_test(self, resolution, interval, delay, exp_len, synapse_properties, times, values): nest.ResetKernel() nest.SetKernelStatus({"resolution": resolution}) nest.sli_func('InitSynapseUpdater', interval, delay) nest.CopyModel("spore_test_node", "test_tracing_node", {"test_name": "test_tracing_node"}) nodes = nest.Create("test_tracing_node", 2) synapse_properties["reward_transmitter"] = nodes[0] nest.CopyModel("synaptic_sampling_rewardgradient_synapse", "test_synapse") nest.SetDefaults("test_synapse", synapse_properties) nest.Connect([nodes[0]], [nodes[1]], "one_to_one", {"model": "test_synapse"}) conns = nest.GetConnections([nodes[0]], [nodes[1]], "test_synapse") nest.SetStatus(conns, {"recorder_interval": 100.0}) nest.Simulate(exp_len) results = nest.GetStatus( conns, ["recorder_times", "synaptic_parameter_values"]) self.assertAlmostEqual( np.sum((np.array(results[0][0]) - np.array(times))**2), 0.0) self.assertAlmostEqual( np.sum((np.array(results[0][1]) - np.array(values))**2), 0.0)
def test_ConnectOptions(self): """ConnectOptions""" nest.ResetKernel() copts = nest.sli_func('GetOptions', '/RandomConvergentConnect', litconv=True) dopts = nest.sli_func('GetOptions', '/RandomDivergentConnect', litconv=True) ncopts = dict([(k, not v) for k, v in copts.iteritems() if k != 'DefaultOptions']) ndopts = dict([(k, not v) for k, v in dopts.iteritems() if k != 'DefaultOptions']) n = nest.Create('iaf_neuron', 3) nest.RandomConvergentConnect(n, n, 1, options=ncopts) nest.RandomDivergentConnect(n, n, 1, options=ndopts) self.assertEqual( copts, nest.sli_func('GetOptions', '/RandomConvergentConnect', litconv=True)) self.assertEqual( dopts, nest.sli_func('GetOptions', '/RandomDivergentConnect', litconv=True))
def test_ConvergentDivergentConnectOptions(self): """Convergent/DivergentConnect with non-standard options and ensure that the option settings are properly restored before returning.""" nest.ResetKernel() copts = nest.sli_func('GetOptions', '/RandomConvergentConnect', litconv=True) dopts = nest.sli_func('GetOptions', '/RandomDivergentConnect', litconv=True) ncopts = dict( (k, not v) for k, v in copts.items() if k != 'DefaultOptions') ndopts = dict( (k, not v) for k, v in dopts.items() if k != 'DefaultOptions') n = nest.Create('iaf_neuron', 3) nest.RandomConvergentConnect(n, n, 1, options=ncopts) nest.RandomDivergentConnect(n, n, 1, options=ndopts) opts = nest.sli_func('GetOptions', '/RandomConvergentConnect', litconv=True) self.assertEqual(copts, opts) opts = nest.sli_func('GetOptions', '/RandomDivergentConnect', litconv=True) self.assertEqual(dopts, opts)
def spore_connection_test(self, p_sim, synapse_properties, target_values): nest.ResetKernel() nest.SetKernelStatus({"resolution": p_sim["resolution"]}) nest.sli_func('InitSynapseUpdater', p_sim["interval"], p_sim["delay"]) nest.CopyModel("spore_test_node", "test_tracing_node", {"test_name": "test_tracing_node"}) nodes = nest.Create("test_tracing_node", p_sim["num_synapses"]) synapse_properties["reward_transmitter"] = nodes[0] nest.CopyModel("synaptic_sampling_rewardgradient_synapse", "test_synapse") nest.SetDefaults("test_synapse", synapse_properties) nest.Connect([nodes[0]], nodes, "all_to_all", {"model": "test_synapse"}) conns = nest.GetConnections([nodes[0]], nodes, "test_synapse") syn_param = np.arange(0, 1, 1.0 / 100) nest.SetStatus(conns, [{"recorder_interval": 100.0, "synaptic_parameter": p} for p in syn_param]) frame = p_sim["frame"] num_syn = np.zeros(int(p_sim["exp_len"] / frame) + 1) for i, t in enumerate(np.arange(0, p_sim["exp_len"], frame)): nest.Simulate(frame) conns = nest.GetConnections([nodes[0]], nodes, "test_synapse") num_syn[i] = len(conns) self.assertAlmostEqual(np.sum((num_syn - np.array(target_values))**2), 0.0)
def spore_connection_test(self, resolution, interval, delay, exp_len): nest.ResetKernel() nest.SetKernelStatus({"resolution": resolution}) nest.sli_func('InitSynapseUpdater', interval, delay) nest.CopyModel("spore_test_node", "test_tracing_node", {"test_name": "test_tracing_node"}) nodes = nest.Create("test_tracing_node", 2) nest.CopyModel("spore_test_synapse", "test_synapse") nest.SetDefaults("test_synapse", {"weight_update_time": 100.0}) nest.Connect([nodes[0]], [nodes[1]], "one_to_one", {"model": "test_synapse"}) nest.Simulate(exp_len) conns = nest.GetConnections([nodes[0]], [nodes[1]], "test_synapse") results = nest.GetStatus(conns, ["recorder_times", "recorder_values"]) offset = 1.0 if (resolution <= 1.0) else resolution self.assertAlmostEqual( np.mean( np.abs(results[0][0] - np.arange(0.0, exp_len - offset, resolution))), 0.0) self.assertAlmostEqual( np.mean( np.abs(results[0][1] - np.arange(0.0, (exp_len - offset) / resolution))), 0.0)
def test_7_bad_property_error_reward_transmitter(self): nest.ResetKernel() nest.SetKernelStatus({"resolution": 1.0}) nest.sli_func('InitSynapseUpdater', 100, 100) nest.CopyModel("spore_test_node", "test_tracing_node", {"test_name": "test_tracing_node"}) nodes = nest.Create("test_tracing_node", 2) nest.CopyModel("synaptic_sampling_rewardgradient_synapse", "test_synapse") nest.SetDefaults("test_synapse", { "temperature": 0.0, "synaptic_parameter": 1.0 }) nest.Connect([nodes[0]], [nodes[1]], "one_to_one", {"model": "test_synapse"}) try: nest.Simulate(1000) self.fail("Expected exception of type NESTError, but got nothing") except Exception as e: self.assertEqual( type(e).__name__, "NESTError", "Expected exception of type NESTError, but got: '" + type(e).__name__ + "'")
def main(): RESOLUTION = s_to_ms(0.001) SIMULATION_TIME = s_to_ms(0.5) N_STEPS = int(SIMULATION_TIME / RESOLUTION) TRACE_LENGTH = N_STEPS + 1 nest.ResetKernel() nest.SetKernelStatus({"resolution": RESOLUTION}) nest.Install("sporemodule") nest.sli_func('InitSynapseUpdater', N_STEPS, 0) proxy = nest.Create("reward_in_proxy") nest.SetStatus(proxy, {'port_name': 'in', 'delay': 0.0}) nest.Simulate(SIMULATION_TIME) traces = nest.GetStatus(proxy, ("trace"))[0] for i, trace in enumerate(traces): assert len(trace) == TRACE_LENGTH # NEST-inherent delay of one timestep forces first value to be unchanged assert trace[0] == 0.0, "Buffer on NEST side is initialized with 0." assert trace[N_STEPS] == 0.0, "Unused value is zero" # [0.0, received values ..., 0.0], #elements = N_STEPS + 1 values = np.array(list(map(s_to_ms, trace[1:N_STEPS]))) expect = np.arange(0.0, SIMULATION_TIME, RESOLUTION)[:-1] + s_to_ms(float(i)) assert np.allclose(values, expect), "{}\n{}".format(values, expect)
def suite(): # MPI tests if HAVE_MPI: try: # Get the MPI command command = nest.sli_func( "mpirun", 2, "python", "test_sp/mpitest_issue_578_sp.py") print ("Executing test with command: " + command) command = command.split() call(command) except: print (sys.exc_info()[0]) print ("Test call with MPI ended in error") raise test_suite = unittest.TestSuite() test_suite.addTest(test_synaptic_elements.suite()) test_suite.addTest(test_conn_builder.suite()) test_suite.addTest(test_growth_curves.suite()) test_suite.addTest(test_sp_manager.suite()) test_suite.addTest(test_synaptic_elements.suite()) test_suite.addTest(test_disconnect.suite()) test_suite.addTest(test_disconnect_multiple.suite()) test_suite.addTest(test_enable_multithread.suite()) test_suite.addTest(test_get_sp_status.suite()) return test_suite
def suite(): if HAVE_MPI: try: mpitests = ["mpitest_issue_578_sp.py"] path = os.path.dirname(__file__) for test in mpitests: test = os.path.join(path, test) command = nest.sli_func("mpirun", 2, "python", test) print ("Executing test with command: " + command) command = command.split() my_env = os.environ.copy() try: my_env.pop("DELAY_PYNEST_INIT") except: pass call(command, env=my_env) except: print (sys.exc_info()[0]) print ("Test call with MPI ended in error") raise test_suite = unittest.TestSuite() test_suite.addTest(test_synaptic_elements.suite()) test_suite.addTest(test_conn_builder.suite()) test_suite.addTest(test_growth_curves.suite()) test_suite.addTest(test_sp_manager.suite()) test_suite.addTest(test_synaptic_elements.suite()) test_suite.addTest(test_disconnect.suite()) test_suite.addTest(test_disconnect_multiple.suite()) test_suite.addTest(test_enable_multithread.suite()) test_suite.addTest(test_get_sp_status.suite()) return test_suite
def testWithMPI(self): # Check that we can import mpi4py try: from mpi4py import MPI except ImportError: raise unittest.SkipTest("mpi4py required") directory = os.path.dirname(os.path.realpath(__file__)) scripts = ["test_connect_all_to_all.py", "test_connect_one_to_one.py", "test_connect_fixed_indegree.py", "test_connect_fixed_outdegree.py", "test_connect_fixed_total_number.py", "test_connect_pairwise_bernoulli.py" ] failing_tests = [] for script in scripts: test_script = os.path.join(directory, script) command = nest.sli_func("mpirun", 2, "nosetests", test_script) command = command.split() process = sp.Popen(command, stdout=sp.PIPE, stderr=sp.PIPE) stdout, stderr = process.communicate() retcode = process.returncode if retcode != 0: failing_tests.append(script) self.assertTrue(not failing_tests, 'The following tests failed when ' + 'executing with "mpirun -np 2 nosetests [script]": ' + ", ".join(failing_tests))
def suite(): # MPI tests if HAVE_MPI: try: # Get the MPI command command = nest.sli_func("mpirun", 2, "python", "test_sp/mpitest_issue_578_sp.py") print("Executing test with command: " + command) command = command.split() call(command) except: print(sys.exc_info()[0]) print("Test call with MPI ended in error") raise test_suite = unittest.TestSuite() test_suite.addTest(test_synaptic_elements.suite()) test_suite.addTest(test_conn_builder.suite()) test_suite.addTest(test_growth_curves.suite()) test_suite.addTest(test_sp_manager.suite()) test_suite.addTest(test_synaptic_elements.suite()) test_suite.addTest(test_disconnect.suite()) test_suite.addTest(test_disconnect_multiple.suite()) test_suite.addTest(test_enable_multithread.suite()) test_suite.addTest(test_get_sp_status.suite()) return test_suite
def memory(self): """ Use NEST's memory wrapper function to record used memory. """ mem = nest.sli_func('memory_thisjob') if isinstance(mem, dict): return mem['heap'] else: return mem
def connect_csa(cset, pre, post, syn_type): print "connecting using cset" if isinstance(pre, Population) and isinstance(post, Population): # contiguous IDs, so just pass first_id and size nest.sli_func("Connect_cg_i_i_i_i_D_l", self.cset, pre.first_id, pre.size, post.first_id, post.size, {'weight': 0, 'delay': 1}, # ignored if arity==0 syn_type) else: # PopulationViews or Assemblies # IDs may be non-contiguous, so need to pass entire arrays nest.sli_func("Connect_cg_a_a_D_l", self.cset, pre.all_cells, post.all_cells, {'weight': 0, 'delay': 1}, # ignored if arity==0 syn_type)
def test_ConnectOptions(self): """ConnectOptions""" nest.ResetKernel() copts = nest.sli_func('GetOptions', '/RandomConvergentConnect', litconv=True) dopts = nest.sli_func('GetOptions', '/RandomDivergentConnect', litconv=True) ncopts = dict([(k, not v) for k,v in copts.iteritems() if k != 'DefaultOptions']) ndopts = dict([(k, not v) for k,v in dopts.iteritems() if k != 'DefaultOptions']) n = nest.Create('iaf_neuron', 3) nest.RandomConvergentConnect(n, n, 1, options=ncopts) nest.RandomDivergentConnect (n, n, 1, options=ndopts) self.assertEqual(copts, nest.sli_func('GetOptions', '/RandomConvergentConnect', litconv=True)) self.assertEqual(dopts, nest.sli_func('GetOptions', '/RandomDivergentConnect', litconv=True))
def topology_func(slifunc, *args): """ Execute slifunc with args in topology namespace. See also: nest.sli_func """ # Execute function in topology namespace. # We need to pass the kwarg namespace as **{} instead of the usuual # way to keep Python 2.5 happy, see http://bugs.python.org/issue3473 return nest.sli_func(slifunc, *args, **{'namespace': 'topology'})
def memory(self): """ Use NEST's memory wrapper function to record used memory. """ try: mem = nest.ll_api.sli_func('memory_thisjob') except AttributeError: mem = nest.sli_func('memory_thisjob') if isinstance(mem, dict): return mem['heap'] else: return mem
def ComputePSPnorm(tauMem, CMem, tauSyn): """Compute the maximum of postsynaptic potential for a synaptic input current of unit amplitude (1 pA)""" a = (tauMem / tauSyn) b = (1.0 / tauSyn - 1.0 / tauMem) # time of maximum t_max = 1.0/b * ( -nest.sli_func('LambertWm1',-exp(-1.0/a)/a) - 1.0/a ) # maximum of PSP for current of unit amplitude return exp(1.0)/(tauSyn*CMem*b) * ((exp(-t_max/tauMem) - exp(-t_max/tauSyn)) / b - t_max*exp(-t_max/tauSyn))
def psp_height(tau_m, R_m, tau_syn): """ Calculate the height of the EPSP for a synaptic current with peak amplitude 1 nA. tau_m and tau_syn: ms R_m: Mohm """ a = (tau_m / tau_syn) b = (1.0 / tau_syn - 1.0 / tau_m) # time of maximum t_max = 1.0/b * (-nest.sli_func('LambertWm1', -exp(-1.0/a)/a) - 1.0/a) # height of PSP for current of amplitude 1 nA return 1/(tau_syn*tau_m*b/R_m) * ((exp(-t_max/tau_m) - exp(-t_max/tau_syn)) / b - t_max*exp(-t_max/tau_syn))
def ComputePSPnorm(tauMem, CMem, tauSyn): """Compute the maximum of postsynaptic potential for a synaptic input current of unit amplitude (1 pA)""" a = (tauMem / tauSyn) b = (1.0 / tauSyn - 1.0 / tauMem) # time of maximum t_max = 1.0 / b * (-nest.sli_func('LambertWm1', -exp(-1.0 / a) / a) - 1.0 / a) # maximum of PSP for current of unit amplitude return exp(1.0) / (tauSyn * CMem * b) * ( (exp(-t_max / tauMem) - exp(-t_max / tauSyn)) / b - t_max * exp(-t_max / tauSyn))
def compute_normalised_psr(cls, tauMem, R, tauSyn): """Compute the maximum of postsynaptic potential for a synaptic input current of unit amplitude (1 pA)""" a = float(tauMem / tauSyn) b = (1.0 / tauSyn - 1.0 / tauMem) # time of maximum t_max = 1.0 / b * \ (-nest.sli_func('LambertWm1', -exp(-1.0 / a) / a) - 1.0 / a) # maximum of PSP for current of unit amplitude return exp(1) / (tauSyn * tauMem * b / R) * ( (exp(-float(t_max / tauMem)) - exp(-float(t_max / tauSyn))) / b - t_max * exp(-float(t_max / tauSyn)))
def find_loc_pspmax(tau_s, tau_m): ''' This function finds the exact location of the maximum of the PSP caused by a single input spike. The location is obtained by setting the first derivative of the equation for the PSP (see `make_psp()`) to zero. The resulting equation can be expressed ain terms of a LambertW function. This function is implemented in nest as a .sli file. In order to access this function in pynest we called the function 'nest.sli_func()'. This function expects: Tau_s and Tau_m: the synaptic and membrane time constant (in sec) It returns the location of the maximum (in sec) ''' var = tau_m / tau_s lam = nest.sli_func('LambertWm1', -numpy.exp(-1 / var) / var) t_maxpsp = (-var * lam - 1) / var / (1 / tau_s - 1 / tau_m) * 1e-3 return t_maxpsp
The new implementation binds V_m to be smaller than 0. Rationale of the test: - all models should be close to the reference LSODAR when submitted to the same excitatory current. - for ``Delta_T = 0.``, ``a = 0.`` and ``b = 0.``, starting from ``w = 0.``, models should behave as the associated iaf model. This is tested both with spike input and direct current input. Details: The models are compared and we assess that the difference between the recorded variables and the reference is smaller than a given tolerance. """ HAVE_GSL = nest.sli_func("statusdict/have_gsl ::") path = os.path.abspath(os.path.dirname(__file__)) # --------------------------------------------------------------------------- # # Tolerances to compare LSODAR and NEST implementations # ------------------------- # # higher for the potential because of the divergence at spike times di_tolerances_lsodar = { "aeif_cond_alpha": {"V_m": 5e-4, "w": 1e-4}, "aeif_cond_exp": {"V_m": 5e-4, "w": 1e-4}, "aeif_psc_alpha": {"V_m": 5e-4, "w": 1e-4}, "aeif_psc_exp": {"V_m": 5e-4, "w": 1e-4}, "aeif_psc_delta": {"V_m": 5e-4, "w": 1e-4}, "aeif_cond_alpha_multisynapse": {"V_m": 5e-4, "w": 1e-4},
DisplacementDependentProbabilityConnector, IndexBasedProbabilityConnector, SmallWorldConnector, FromListConnector, FromFileConnector, CloneConnector, ArrayConnector, FixedTotalNumberConnector) from .random import NativeRNG, NEST_RDEV_TYPES logger = logging.getLogger("PyNN") if not nest.sli_func("statusdict/have_libneurosim ::"): print(("CSAConnector: libneurosim support not available in NEST.\n" + "Falling back on PyNN's default CSAConnector.\n" + "Please re-compile NEST using --with-libneurosim=PATH")) from pyNN.connectors import CSAConnector else: class CSAConnector(Connector): """ Use the Connection-Set Algebra (Djurfeldt, 2012) to connect cells. This is an optimized variant of CSAConnector, which iterates the connection-set on the C++ level in NEST.
def __init__(self): PyNestNode.__init__(self, total_simulation_time, pre_run_barrier=True) logger.info("Setting up NEST and installing SPORE") if nest_n_threads is None: import multiprocessing n_threads = int( 1.1 * (multiprocessing.cpu_count() - MPI.COMM_WORLD.Get_size())) logger.info("> n_threads = {} (autodetect)".format(n_threads)) else: n_threads = nest_n_threads logger.info("> n_threads = {} (fixed configuration)".format( nest_n_threads)) nest.SetKernelStatus({ "resolution": s_to_ms(network_node_time_step), "overwrite_files": True, "local_num_threads": n_threads }) nest.Install("sporemodule") logger.info("> Synaptic update interval: {}s".format( s_to_ms(synapse_update_interval))) nest.sli_func("InitSynapseUpdater", int(s_to_ms(synapse_update_interval)), int(s_to_ms(synapse_update_interval))) # initialize random values, see NEST documentation N_vp = nest.GetKernelStatus(["total_num_virtual_procs"])[0] nest.SetKernelStatus({"grng_seed": random_seed + N_vp}) nest.SetKernelStatus({ "rng_seeds": list(range(random_seed + N_vp + 1, random_seed + 2 * N_vp + 1)) }) # ------------- NETWORK CONSTRUCTION ------------- logger.info("Constructing network") nest.CopyModel("poisson_dbl_exp_neuron", "hidden_neuron", hidden_neuron_properties) nest.CopyModel("poisson_dbl_exp_neuron", "inhibitory_neuron", inhibitory_neuron_properties) nest.CopyModel("static_synapse", "e_to_i_synapse") nest.CopyModel("static_synapse", "i_to_e_synapse") nest.CopyModel("synaptic_sampling_rewardgradient_synapse", "reward_synapse") logger.info( "> Opening port and creating proxy for incoming reward signal") reward_in = nest.Create('reward_in_proxy') nest.SetStatus(reward_in, music_network_node_reward_in_port) synapse_properties["reward_transmitter"] = reward_in[0] nest.SetDefaults("reward_synapse", synapse_properties) logger.info( "> Opening port and creating proxy for incoming spike patterns") input_neurons = self._create_event_in_proxy( n_input_neurons, **music_network_node_pattern_in_port) logger.info("> Creating hidden neurons") hidden_neurons = nest.Create("hidden_neuron", n_hidden_neurons) up_neurons = nest.Create("hidden_neuron", n_up_neurons) down_neurons = nest.Create("hidden_neuron", n_down_neurons) logger.info("> Creating inhibitory neurons") inhibitory_neurons = nest.Create("inhibitory_neuron", n_inhibitory_neurons) logger.info( "> Establishing synaptic connection between input and hidden neurons" ) for i in range(n_max_connections_input_hidden): nest.Connect(input_neurons, hidden_neurons[:n_input_hidden], { "rule": "pairwise_bernoulli", "p": p_connection_input_hidden }, { "model": "reward_synapse", "synaptic_parameter": { "distribution": "normal", "mu": synapse_init_mean, "sigma": synapse_init_std } }) logger.info( "> Establishing synaptic connection between hidden and hidden neurons" ) for i in range(n_max_connections_hidden_hidden): nrns = hidden_neurons + up_neurons + down_neurons nest.Connect( nrns, nrns, { "rule": "pairwise_bernoulli", "p": p_connection_hidden_hidden, "autapses": False }, { "model": "reward_synapse", "synaptic_parameter": { "distribution": "normal", "mu": synapse_init_mean, "sigma": synapse_init_std } }) logger.info( "> Establishing synaptic connection between inhibitory neurons and hidden neurons" ) # Connect network to hidden neurons e_to_i_conspec = {"rule": "pairwise_bernoulli", "p": 0.575} e_to_i_synspec = { "model": "static_synapse", "weight": { "distribution": "normal_clipped", "mu": weight_mean_e_to_i, "sigma": weight_std_e_to_i, "low": 0.0 }, "delay": 1.0 } i_to_e_conspec = {"rule": "pairwise_bernoulli", "p": 0.600} i_to_e_synspec = { "model": "static_synapse", "weight": { "distribution": "normal_clipped", "mu": weight_mean_i_to_e, "sigma": weight_std_i_to_e, "high": 0.0 }, "receptor_type": 1, "delay": 1.0 } i_to_i_conspec = {"rule": "pairwise_bernoulli", "p": 0.550} i_to_i_synspec = { "model": "static_synapse", "weight": { "distribution": "normal_clipped", "mu": weight_mean_i_to_e, "sigma": weight_std_i_to_e, "high": 0.0 }, "receptor_type": 1, "delay": 1.0 } nest.Connect(hidden_neurons, inhibitory_neurons, e_to_i_conspec, e_to_i_synspec) nest.Connect(up_neurons, inhibitory_neurons, e_to_i_conspec, e_to_i_synspec) nest.Connect(down_neurons, inhibitory_neurons, e_to_i_conspec, e_to_i_synspec) nest.Connect(inhibitory_neurons, hidden_neurons, i_to_e_conspec, i_to_e_synspec) nest.Connect(inhibitory_neurons, up_neurons, i_to_e_conspec, i_to_e_synspec) nest.Connect(inhibitory_neurons, down_neurons, i_to_e_conspec, i_to_e_synspec) nest.Connect(inhibitory_neurons, inhibitory_neurons, i_to_i_conspec, i_to_i_synspec) logger.info( "> Opening ports for outgoing spikes; Establishing connection to hidden neurons" ) self._create_event_out_proxy(up_neurons + down_neurons, **music_network_node_activity_out_port)
except ImportError: haveCSA = False from pyNN import random from pyNN.connectors import ( Connector, AllToAllConnector, FixedProbabilityConnector, OneToOneConnector, FixedNumberPreConnector, FixedNumberPostConnector, DistanceDependentProbabilityConnector, DisplacementDependentProbabilityConnector, IndexBasedProbabilityConnector, SmallWorldConnector, FromListConnector, FromFileConnector, CloneConnector, ArrayConnector, FixedTotalNumberConnector) from .random import NativeRNG, NEST_RDEV_TYPES logger = logging.getLogger("PyNN") if not nest.sli_func("statusdict/have_libneurosim ::"): print(("CSAConnector: libneurosim support not available in NEST.\n" + "Falling back on PyNN's default CSAConnector.\n" + "Please re-compile NEST using --with-libneurosim=PATH")) from pyNN.connectors import CSAConnector else: class CSAConnector(Connector): """ Use the Connection-Set Algebra (Djurfeldt, 2012) to connect cells. This is an optimized variant of CSAConnector, which iterates the connection-set on the C++ level in NEST.
# 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/>. from scipy.integrate import quad import math import numpy from numpy import testing import pylab import unittest import nest from nest import raster_plot import time HAVE_OPENMP = nest.sli_func("is_threaded") class SynapticElementIntegrator(object): """ Generic class which describes how to compute the number of Synaptic Element based on Ca value Each derived class should overwrite the get_se(self, t) method """ def __init__(self, tau_ca=10000.0, beta_ca=0.001): """ Constructor :param tau_ca (float): time constant of Ca decay :param beta_ca (float): each spike increase Ca value by this value
import nest import unittest import numpy as np __author__ = 'naveau' try: from mpi4py import MPI except ImportError: # Test without MPI mpi_test = 0 else: # Test with MPI mpi_test = 1 mpi_test = nest.sli_func("statusdict/have_mpi ::") & mpi_test class TestDisconnectSingle(unittest.TestCase): def setUp(self): nest.ResetKernel() nest.set_verbosity('M_ERROR') self.num_procs = 1 if mpi_test: self.comm = MPI.COMM_WORLD self.rank = self.comm.Get_rank() assert(nest.Rank() == self.rank) self.num_procs = 2 self.exclude_synapse_model = [ 'stdp_dopamine_synapse',
# (at your option) any later version. # # 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 os import subprocess as sp import unittest import nest HAVE_MPI = nest.sli_func("statusdict/have_mpi ::") class TestConnectAllPatterns(unittest.TestCase): @unittest.skipIf(not HAVE_MPI, 'NEST was compiled without MPI') def testWithMPI(self): # Check that we can import mpi4py try: from mpi4py import MPI except ImportError: raise unittest.SkipTest("mpi4py required") directory = os.path.dirname(os.path.realpath(__file__)) scripts = ["test_connect_all_to_all.py", "test_connect_one_to_one.py", "test_connect_fixed_indegree.py",
def _RandomPopulationConnect(self, pre, post, n, param_dict, synapse_model='static_synapse'): '''...''' nest.sli_func('RandomPopulationConnectD', pre, post, n, param_dict, '/' + synapse_model, litconv=True)
# # 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/>. # This script tests the siegert_neuron in NEST. import nest import unittest import numpy as np HAVE_GSL = nest.sli_func("statusdict/have_gsl ::") @nest.check_stack @unittest.skipIf(not HAVE_GSL, 'GSL is not available') class SiegertNeuronTestCase(unittest.TestCase): """ Test siegert_neuron Details ------- Compares the rate of a Poisson-driven iaf_psc_delta neuron with the prediction from the siegert neuron. """ def setUp(self): # test parameter to compare analytic solution to simulation
def spore_connection_test(self, resolution, interval, delay, exp_len): spike_times_in = [10.0, 15.0, 20.0, 25.0, 50.0] spike_times_out = [40.0, 50.0, 60.0, 70.0] synapse_properties = {"weight_update_interval": 100.0, "temperature": 0.0, "synaptic_parameter": 1.0, "reward_transmitter": None, "learning_rate": 0.0001, "episode_length": 100.0, "max_param": 100.0, "min_param": -100.0, "max_param_change": 100.0, "integration_time": 10000.0} nest.ResetKernel() nest.SetKernelStatus({"resolution": resolution}) nest.sli_func("InitSynapseUpdater", interval, delay) nest.CopyModel("spore_test_node", "test_pulse_trace", {"test_name": "test_pulse_trace", "spike_times": np.array(spike_times_out), "weight": 1.0, "offset": -0.2}) # Create spike generators and connect gin = nest.Create("spike_generator", params={"spike_times": np.array(spike_times_in)}) nout = nest.Create("test_pulse_trace") nodes = nest.Create("test_pulse_trace", 1) nest.CopyModel("synaptic_sampling_rewardgradient_synapse", "test_synapse") synapse_properties["reward_transmitter"] = nodes[0] nest.SetDefaults("test_synapse", synapse_properties) nest.Connect([gin[0]], [nout[0]], "one_to_one", {"model": "test_synapse"}) conns = nest.GetConnections([gin[0]], [nout[0]], "test_synapse") nest.SetStatus(conns, {"recorder_interval": 100.0}) nest.Simulate(exp_len) results = nest.GetStatus(conns, ["recorder_times", "synaptic_parameter_values"]) times = [0.0, 100.0, 200.0, 300.0, 400.0, 500.0, 600.0, 700.0, 800.0, 900.0, 1000.0, 1100.0, 1200.0, 1300.0, 1400.0, 1500.0, 1600.0, 1700.0, 1800.0, 1900.0, 2000.0, 2100.0, 2200.0, 2300.0, 2400.0, 2500.0, 2600.0, 2700.0, 2800.0, 2900.0, 3000.0, 3100.0, 3200.0, 3300.0, 3400.0, 3500.0, 3600.0, 3700.0, 3800.0, 3900.0, 4000.0, 4100.0, 4200.0, 4300.0, 4400.0, 4500.0, 4600.0, 4700.0, 4800.0, 4900.0, 5000.0, 5100.0, 5200.0, 5300.0, 5400.0, 5500.0, 5600.0, 5700.0, 5800.0, 5900.0, 6000.0, 6100.0, 6200.0, 6300.0, 6400.0, 6500.0, 6600.0, 6700.0, 6800.0, 6900.0, 7000.0, 7100.0, 7200.0, 7300.0, 7400.0, 7500.0, 7600.0, 7700.0, 7800.0, 7900.0, 8000.0, 8100.0, 8200.0, 8300.0, 8400.0, 8500.0, 8600.0, 8700.0, 8800.0, 8900.0, 9000.0, 9100.0, 9200.0, 9300.0, 9400.0, 9500.0, 9600.0, 9700.0, 9800.0, 9900.0] values = [1.0, 1.1941197605580636, 1.5774259143750948, 2.0259103145644266, 2.4921365591257456, 2.9587360738461674, 3.4194121087993565, 3.871939771677826, 4.315590899450609, 4.750186736885722, 5.175749451568903, 5.592373948376652, 6.000180727410171, 6.399298555975304, 6.789858108361998, 7.171989640278706, 7.545822147382392, 7.911483069607812, 8.269098196118081, 8.618791643894623, 8.960685863254373, 9.29490165311173, 9.621558179666037, 9.940772996191743, 10.252662063078569, 10.557339767809804, 10.854918944765805, 11.14551089481294, 11.429225404665099, 11.706170766014766, 11.976453794434303, 12.240179848049316, 12.497452845986553, 12.748375286598817, 12.993048265469508, 13.231571493199345, 13.464043312977822, 13.690560717941914, 13.91121936832454, 14.126113608395242, 14.33533648319552, 14.53897975507124, 14.737133920004482, 14.929888223747206, 15.11733067775905, 15.299548074951568, 15.476626005241176, 15.64864887091307, 15.815699901798324, 15.97786117026638, 16.13521360603509, 16.287837010800473, 16.43581007268829, 16.579210380529563, 16.71811443796208, 16.852597677359963, 16.982734473593325, 17.10859815762, 17.230261029911343, 17.34779437371405, 17.461268468149946, 17.570752601155647, 17.67631508226397, 17.778023255228995, 17.875943510496594, 17.97014129752227, 18.06068113693813, 18.147626632570702, 18.23104048331149, 18.31098449484185, 18.38751959121408, 18.46070582629026, 18.530602395040663, 18.597267644703344, 18.66075908580651, 18.721133403055404, 18.778446466085196, 18.832753340081556, 18.884108296270426, 18.93256482227858, 18.978175632366465, 19.0209926775349, 19.061067155507057, 19.098449520587284, 19.133189493398152, 19.165336070497265, 19.194937533875176, 19.222041460335888, 19.24669473076129, 19.268943539260974, 19.288833402208706, 19.306409167166986, 19.321715021701, 19.33479450208325, 19.345690501890225, 19.35444528049237, 19.361100471438604, 19.365697090736695, 19.3682755450307, 19.368875639676705] self.assertAlmostEqual(np.sum((np.array(results[0][0]) - np.array(times))**2), 0.0) self.assertAlmostEqual(np.sum((np.array(results[0][1]) - np.array(values))**2), 0.0)
# 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/>. from scipy.integrate import quad import math import numpy from numpy import testing import pylab import unittest import nest from nest import raster_plot import time HAVE_OPENMP = nest.sli_func("is_threaded") class SynapticElementIntegrator(object): """ Generic class which describes how to compute the number of Synaptic Element based on Ca value Each derived class should overwrite the get_se(self, t) method """ def __init__(self, tau_ca=10000.0, beta_ca=0.001): """ Constructor :param tau_ca (float): time constant of Ca decay :param beta_ca (float): each spike increase Ca value by this value """
import nest import unittest import numpy as np __author__ = 'naveau' try: from mpi4py import MPI except ImportError: # Test without MPI mpi_test = 0 else: # Test with MPI mpi_test = 1 mpi_test = nest.sli_func("statusdict/have_mpi ::") & mpi_test class TestDisconnectSingle(unittest.TestCase): def setUp(self): nest.ResetKernel() nest.set_verbosity('M_ERROR') self.num_procs = 1 if mpi_test: self.comm = MPI.COMM_WORLD self.rank = self.comm.Get_rank() assert (nest.Rank() == self.rank) self.num_procs = 2 self.exclude_synapse_model = [ 'stdp_dopamine_synapse', 'stdp_dopamine_synapse_lbl',