diff --git a/examples/pattern_matching_showcase/experiment.py b/examples/pattern_matching_showcase/experiment.py index 724240e..3bd5678 100755 --- a/examples/pattern_matching_showcase/experiment.py +++ b/examples/pattern_matching_showcase/experiment.py @@ -29,7 +29,7 @@ plotter = None exitcode = -1 -if not "TEST_MODE" in sys.argv[1:]: +if "TEST_MODE" not in sys.argv[1:]: # don't create plotter in test mode try: dev0 = open("/dev/null", "w") diff --git a/examples/pattern_matching_showcase/python/__init__.py b/examples/pattern_matching_showcase/python/__init__.py deleted file mode 100755 index b9c35f5..0000000 --- a/examples/pattern_matching_showcase/python/__init__.py +++ /dev/null @@ -1,87 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- - -import numpy as np - -import matplotlib.cm - -import snn_utils.plotter as plotter -import snn_utils.plotter.backends.mpl as mpl_plotter -import snn_utils.plotter.interface as interface -import snn_utils.plotter.plots as plots -from config import * -from snn_utils.comm.serializer import SERIALIZERS -from snn_utils.plotter import data_provider - - -def split_list(l, n_chunks): - n_elements_per_chunk = len(l) // n_chunks - for i in range(0, len(l), n_elements_per_chunk): - yield l[i:i + n_elements_per_chunk] - - -def configure_detail_plot(data_source): - p = plotter.PlotWindowBuilder(auto_vertical_padding=0.2) - - c1 = p.add_column(x_spines=True) - - pattern_colors = list(matplotlib.cm.plasma(np.linspace(0.2, 0.8, n_patterns))) - - c1.add_plot(plots.PhasePlot(data_source, 'pattern_id', n_patterns, label="Phase", y_pos=5, - common_line_style={'linewidth': 5}, - legend=["Pattern #{}".format(i + 1) for i in range(n_patterns)], - colors=pattern_colors, zero_is_value=False), height_ratio=0.5 - ) - - c1.add_plot(plots.SpikeTrainPlot(data_source, - [('pattern_in', i) for i in range(n_input_neurons)], - label='Input Activity (#neurons = {})'.format(n_input_neurons), - colors='black'), - height_ratio=1.5) - - c1.add_row_group([plots.SpikeTrainPlot(data_source, subset, colors=pattern_colors[i]) - for i, subset in enumerate(split_list([('activity_in', i) for i in range(n_hidden_neurons)], - n_patterns))], - vertical_padding_ratio=0.1, height_ratio=[0.5] * n_patterns, hlines=True, - label="Output Activity (#neurons = {})".format(n_hidden_neurons)) - - c1.add_plot(plots.AnalogSignalPlot(data_source, - ['activity_rate_{}'.format(i) for i in range(n_patterns)], label='Activity Rates', - legend=["Population #{}".format(i + 1) for i in range(n_patterns)], - colors=pattern_colors, - y_ticks=[], y_lim=(0.0, 1000.0 / hidden_neuron_properties['dead_time']))) - - c1.add_plot(plots.AnalogSignalPlot(data_source, - ['curr', 'mean'], 'Reward', ['Current', 'Average'], - y_lim=(0.0, 1.0), y_ticks=[])) - - return p - - -if __name__ == '__main__': - master = interface.Master() - - # data sources - data_source = data_provider.ProxyDataSource(sender=False) - - # subscriptions - comm = master.communicator() - - comm.add_subscriber(music_zmq_proxy_config['communication']['host'], - music_zmq_proxy_config['communication']['port'], - lambda delta: data_source.read_delta(delta), - deserialize=SERIALIZERS[music_zmq_proxy_config['communication']['format']].deserialize) - - mpl_plotter.configure_matplotlib() - window = mpl_plotter.MatplotlibWindow(configure_detail_plot(data_source), - data_source=data_source, - max_time_window=plotter_node_time_window) - - master.scheduler().add_handle(lambda: window.draw(), 0.3) - - master.scheduler().add_handle( - lambda: data_source.truncate(lower=data_source.get_max_time() - plotter_node_time_window) - if data_source.get_max_time() is not None else None, - 10000) - - master.mainloop() diff --git a/examples/pattern_matching_showcase/python/config.py b/examples/pattern_matching_showcase/python/config.py index 88cd4b9..d3b0bcb 100644 --- a/examples/pattern_matching_showcase/python/config.py +++ b/examples/pattern_matching_showcase/python/config.py @@ -23,10 +23,7 @@ # GLOBAL CONFIGURATION FILE # ########################################################## -import os -import math import logging -import time import sys diff --git a/examples/pattern_matching_showcase/python/control_node.py b/examples/pattern_matching_showcase/python/control_node.py index 7f7c46c..7a8dd4d 100755 --- a/examples/pattern_matching_showcase/python/control_node.py +++ b/examples/pattern_matching_showcase/python/control_node.py @@ -5,7 +5,6 @@ import music import numpy as np -from itertools import takewhile, dropwhile import experiment_utils.reward as reward @@ -92,7 +91,7 @@ def _run_single_cycle(self, curr_time): self._current_pattern_id = self._next_pattern[1] try: self._next_pattern = next(self._pattern_switch_gen) - except StopIteration as e: + except StopIteration: self._next_pattern = None if spike_rate_buffer_clear_on_phase_change: diff --git a/examples/pattern_matching_showcase/python/interface.py b/examples/pattern_matching_showcase/python/interface.py index b9c35f5..5809c7a 100755 --- a/examples/pattern_matching_showcase/python/interface.py +++ b/examples/pattern_matching_showcase/python/interface.py @@ -46,9 +46,9 @@ def configure_detail_plot(data_source): label="Output Activity (#neurons = {})".format(n_hidden_neurons)) c1.add_plot(plots.AnalogSignalPlot(data_source, - ['activity_rate_{}'.format(i) for i in range(n_patterns)], label='Activity Rates', + ['activity_rate_{}'.format(i) for i in range(n_patterns)], + label='Activity Rates', colors=pattern_colors, legend=["Population #{}".format(i + 1) for i in range(n_patterns)], - colors=pattern_colors, y_ticks=[], y_lim=(0.0, 1000.0 / hidden_neuron_properties['dead_time']))) c1.add_plot(plots.AnalogSignalPlot(data_source, diff --git a/examples/pattern_matching_showcase/python/network_node.py b/examples/pattern_matching_showcase/python/network_node.py index 732fae8..d5a62e1 100755 --- a/examples/pattern_matching_showcase/python/network_node.py +++ b/examples/pattern_matching_showcase/python/network_node.py @@ -5,7 +5,6 @@ from config import * import nest -import numpy as np from mpi4py import MPI from snn_utils.comm.music.node.nest import PyNestNode diff --git a/examples/pattern_matching_showcase/python/snn_utils/comm/music/__init__.py b/examples/pattern_matching_showcase/python/snn_utils/comm/music/__init__.py index 2e6b081..ea6b602 100644 --- a/examples/pattern_matching_showcase/python/snn_utils/comm/music/__init__.py +++ b/examples/pattern_matching_showcase/python/snn_utils/comm/music/__init__.py @@ -146,8 +146,8 @@ def buffer_event_input(self, n_buffers): def pre_cycle(self, curr_sim_time): for buffers, array_buffer in self._cont_array_buffers: - for i, buffer in enumerate(buffers): - buffer.append_value(curr_sim_time, array_buffer[i]) + for i, buffer_ in enumerate(buffers): + buffer_.append_value(curr_sim_time, array_buffer[i]) def post_cycle(self, curr_sim_time): pass @@ -165,11 +165,11 @@ def _create_event_buffer(self): return buffer.WindowedSpikeBuffer(self._time_window) def post_cycle(self, curr_sim_time): - for buffer in self._all_buffers: - buffer.update(curr_sim_time) + for buffer_ in self._all_buffers: + buffer_.update(curr_sim_time) class SingleStepBuffer(BaseBuffer): def post_cycle(self, curr_sim_time): - for buffer in self._all_buffers: - buffer.clear() + for buffer_ in self._all_buffers: + buffer_.clear() diff --git a/examples/pattern_matching_showcase/python/snn_utils/comm/zmq/__init__.py b/examples/pattern_matching_showcase/python/snn_utils/comm/zmq/__init__.py index 0a18e99..71aade6 100644 --- a/examples/pattern_matching_showcase/python/snn_utils/comm/zmq/__init__.py +++ b/examples/pattern_matching_showcase/python/snn_utils/comm/zmq/__init__.py @@ -56,18 +56,23 @@ def add_subscriber(self, host, port, callback, transport="tcp", prefix=u"", dese sock.setsockopt_string(zmq.SUBSCRIBE, prefix) if multipart: - def receive(): return sock.recv_multipart(zmq.NOBLOCK) + def receive(): + return sock.recv_multipart(zmq.NOBLOCK) else: - def receive(): return sock.recv(zmq.NOBLOCK) + def receive(): + return sock.recv(zmq.NOBLOCK) if deserialize is None: - def handle(): return callback(receive()) + def handle(): + return callback(receive()) else: if multipart: - def handle(): return callback([elem if i == 0 else deserialize(elem) - for i, elem in enumerate(receive())]) + def handle(): + return callback([elem if i == 0 else deserialize(elem) + for i, elem in enumerate(receive())]) else: - def handle(): return callback(deserialize(receive())) + def handle(): + return callback(deserialize(receive())) self._handler[sock] = handle self._poller.register(sock, zmq.POLLIN) diff --git a/examples/pattern_matching_showcase/python/snn_utils/plotter/data_provider.py b/examples/pattern_matching_showcase/python/snn_utils/plotter/data_provider.py index ac32cdf..717632b 100644 --- a/examples/pattern_matching_showcase/python/snn_utils/plotter/data_provider.py +++ b/examples/pattern_matching_showcase/python/snn_utils/plotter/data_provider.py @@ -49,7 +49,7 @@ def extend_weight_data(self, key, df): self._weight_map[key] = df.copy() else: self._weight_map[key] = df.copy() - #self._weight_map[key] = self._weight_map[key].append(df) + # self._weight_map[key] = self._weight_map[key].append(df) def get_cont_data(self, keys, time_window=None): return [self._map[key] for key in keys] diff --git a/examples/pattern_matching_showcase/python/zmq_proxy_node.py b/examples/pattern_matching_showcase/python/zmq_proxy_node.py index fb02f08..24998c4 100755 --- a/examples/pattern_matching_showcase/python/zmq_proxy_node.py +++ b/examples/pattern_matching_showcase/python/zmq_proxy_node.py @@ -1,8 +1,6 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -import time - import snn_utils.comm.music from config import * from snn_utils.comm.music.node import PyMusicNode diff --git a/unittests/test_dbl_exp_neuron.py b/unittests/test_dbl_exp_neuron.py index a4e5464..dd8ab5e 100755 --- a/unittests/test_dbl_exp_neuron.py +++ b/unittests/test_dbl_exp_neuron.py @@ -53,7 +53,9 @@ def test_spore_exp_poisson_neuron(self): I_e = -3.0 n = nest.Create('poisson_dbl_exp_neuron', params={ - 'tau_rise_exc': tau_rise_exc, 'tau_fall_exc': tau_fall_exc, 'tau_rise_inh': tau_rise_inh, 'tau_fall_inh': tau_fall_inh, 'I_e': I_e}) + 'tau_rise_exc': tau_rise_exc, 'tau_fall_exc': tau_fall_exc, + 'tau_rise_inh': tau_rise_inh, 'tau_fall_inh': tau_fall_inh, + 'I_e': I_e}) m = nest.Create('multimeter', params={'withtime': True, 'interval': 0.1, 'record_from': ['V_m']}) @@ -86,8 +88,11 @@ def test_spore_exp_poisson_neuron(self): u_rise_inh += w_inh u_fall_inh += w_inh - u_gd[int(t * (1.0 / delta_t))] = (tau_fall_exc / (tau_fall_exc - tau_rise_exc)) * (u_fall_exc - - u_rise_exc) + (tau_fall_inh / (tau_fall_inh - tau_rise_inh)) * (u_fall_inh - u_rise_inh) + I_e + u_gd[int(t * (1.0 / delta_t))] = ((tau_fall_exc / (tau_fall_exc - tau_rise_exc)) * + (u_fall_exc - u_rise_exc) + + (tau_fall_inh / (tau_fall_inh - tau_rise_inh)) * + (u_fall_inh - u_rise_inh) + + I_e) # simulate nest.Simulate(100) diff --git a/unittests/test_dbl_exp_neuron_rate.py b/unittests/test_dbl_exp_neuron_rate.py index a57781e..56183cb 100755 --- a/unittests/test_dbl_exp_neuron_rate.py +++ b/unittests/test_dbl_exp_neuron_rate.py @@ -39,7 +39,9 @@ def do_exp_poisson_neuron_rate_test(self, I_e, target_rate): tau_fall_inh = 10.0 n = nest.Create('poisson_dbl_exp_neuron', params={ - 'tau_rise_exc': tau_rise_exc, 'tau_fall_exc': tau_fall_exc, 'tau_rise_inh': tau_rise_inh, 'tau_fall_inh': tau_fall_inh, 'I_e': I_e}) + 'tau_rise_exc': tau_rise_exc, 'tau_fall_exc': tau_fall_exc, + 'tau_rise_inh': tau_rise_inh, 'tau_fall_inh': tau_fall_inh, + 'I_e': I_e}) m = nest.Create('spike_detector') diff --git a/unittests/test_garbage_collector.py b/unittests/test_garbage_collector.py index ee5e905..d1112d3 100644 --- a/unittests/test_garbage_collector.py +++ b/unittests/test_garbage_collector.py @@ -132,6 +132,8 @@ def test_garbage_collector_2(self): 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.] + self.spore_connection_test(p_sim, synapse_properties, target_values) + def test_garbage_collector_3(self): p_sim = {"resolution": 0.2, "interval": 500, "delay": 500, "exp_len": 5000.0, "num_synapses": 100, "frame": 30.0}