Skip to content

Commit

Permalink
Fix python code style issues; Fix bug in one testcase.
Browse files Browse the repository at this point in the history
  • Loading branch information
mhoff committed Apr 26, 2017
1 parent 462a6c6 commit 2469d60
Show file tree
Hide file tree
Showing 13 changed files with 35 additions and 115 deletions.
2 changes: 1 addition & 1 deletion examples/pattern_matching_showcase/experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
87 changes: 0 additions & 87 deletions examples/pattern_matching_showcase/python/__init__.py

This file was deleted.

3 changes: 0 additions & 3 deletions examples/pattern_matching_showcase/python/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@
# GLOBAL CONFIGURATION FILE
# ##########################################################

import os
import math
import logging
import time
import sys


Expand Down
3 changes: 1 addition & 2 deletions examples/pattern_matching_showcase/python/control_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import music
import numpy as np
from itertools import takewhile, dropwhile

import experiment_utils.reward as reward

Expand Down Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions examples/pattern_matching_showcase/python/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion examples/pattern_matching_showcase/python/network_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 0 additions & 2 deletions examples/pattern_matching_showcase/python/zmq_proxy_node.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
11 changes: 8 additions & 3 deletions unittests/test_dbl_exp_neuron.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']})

Expand Down Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion unittests/test_dbl_exp_neuron_rate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down
2 changes: 2 additions & 0 deletions unittests/test_garbage_collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down

0 comments on commit 2469d60

Please sign in to comment.