Skip to content

Commit

Permalink
bugfix, further python 3.12 fix
Browse files Browse the repository at this point in the history
  • Loading branch information
gitmv committed Oct 6, 2024
1 parent bff6bd3 commit 1fefe55
Show file tree
Hide file tree
Showing 11 changed files with 66 additions and 45 deletions.
File renamed without changes.
3 changes: 2 additions & 1 deletion Exploration/HelperFunctions/Synapses_And_Weights.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ def get_combined_syn_mats(synapses, neuron_id=None, attr='W'):
shapes[key] = (base_src.height, base_src.width)
try:
syn_mat = eval('s.' + attr)
if type(syn_mat) is not bool:

if type(syn_mat)!=bool:
w = s.ignore_transpose_mode(syn_mat)
else:
w = syn_mat
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ def fast_forward(self, steps, Network_UI):
def initialize(self, Network_UI):

self.iteration_display_label=Network_UI.sidebar.add_widget(QLabel())
self.iteration_display_label.setMaximumHeight(10)
#self.iteration_display_label.setMaximumHeight(20)

font_metrics = QFontMetrics(self.iteration_display_label.font())
text_height = font_metrics.height()
self.iteration_display_label.setFixedHeight(text_height)

def start_pause_click(event):
Network_UI.pause = not Network_UI.pause
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def add_recorder_variables(self, neuron_group, Network_UI):
return

def initialize(self, Network_UI):
if Network_UI.network['TextActivator', 0] and Network_UI.network['TextGenerator', 0] is not None:
if Network_UI.network['TextActivator', 0] is not None and Network_UI.network['TextGenerator', 0] is not None:
self.reconstruction_tab = Network_UI.add_tab(title=self.title) #Network_UI.Next_Tab(self.title)

self.grid = QGridLayout()
Expand Down Expand Up @@ -70,7 +70,7 @@ def initialize(self, Network_UI):


def update(self, Network_UI):
if Network_UI.network['TextActivator', 0] is not None and self.reconstruction_tab.isVisible():
if Network_UI.network['TextActivator', 0] is not None and Network_UI.network['TextGenerator', 0] is not None and self.reconstruction_tab.isVisible():
group=Network_UI.selected_neuron_group()

'''
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,16 @@ def initialize(self, Network_UI):
def update(self, Network_UI):

if Network_UI.network['TextGenerator', 0] is not None and Network_UI.network['TextActivator', 0] is not None:
if Network_UI.network['TextActivator', 0].behavior_enabled:
inp_text = Network_UI.network['TextGenerator', 0].history[-self.text_length:]
if Network_UI.network['TextGenerator', 0].behavior_enabled and Network_UI.network['TextActivator', 0].behavior_enabled:
inp_text = Network_UI.network['TextGenerator', 0].get_str_history()[-self.text_length:]
else:
inp_text = 'deactivated'
inp_text=inp_text.replace('\n', '<break>')
self.inp_text_label.setText(inp_text)

if Network_UI.network['TextReconstructor', 0] is not None:
recon_text = Network_UI.network['TextReconstructor', 0].reconstruction_history[-self.text_length:]
recon_text=recon_text.replace('\n', '<break>')
self.recon_text_label.setText(recon_text)
'''
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,10 @@ def draw_neurons(self, painter, group, neuron_size=1, selected_neurons=None):

painter.setPen(0)

inactive = group.output <= 0
inactive = group.spike <= 0
active = np.invert(inactive)

for c in unique(color, axis=0):
for c in np.unique(color, axis=0):
mask = np.all(color == c[None,:], axis=1) * inactive #(color == c) np.all(a == b, axis=1)
painter.setBrush(pg.mkBrush(color=c))
for x, y in zip(group.buffer_posx[mask], group.buffer_posy[mask]):
Expand Down
2 changes: 1 addition & 1 deletion NetworkBehavior/Structure/Partition.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def partition(self, synapses, dst_group_masks): # todo:auto receptive field ext

syn_sub_groups.append(synapses.get_sub_synapse_group(src_mask, dst_mask))

print('partitioned into', len(syn_sub_groups), 'SynapseGroups')
print('partitioned into', len(syn_sub_groups), 'SynapseGroups', str(int(rf_x)), 'x', str(int(rf_y)), 'x', str(int(rf_z)))

# add sub Groups
for sg in syn_sub_groups:
Expand Down
9 changes: 7 additions & 2 deletions NetworkCore/Base_Attachable_Modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
from numpy.random import *
from numpy import *
from functools import wraps
import builtins

bool = builtins.bool

def lognormal_real_mean(mean=1.0, sigma=1.0, size=1):
mu = -np.power(sigma, 2) + np.log(mean)
Expand Down Expand Up @@ -40,7 +43,7 @@ def __init__(self, tag, network, behavior):
self.behavior = {}#behavior

if type(behavior) == list:
self.behavior = dict(zip(range(len(self.behavior)), self.behavior))
behavior = dict(zip(range(len(behavior)), behavior))

for k,b in behavior.items():
self.add_behavior(k, b, initialize=False)
Expand Down Expand Up @@ -266,4 +269,6 @@ def deactivate_behaviours(self, tag):

@deprecated_warning("activate_behaviours function will be removed in coming versions. Please use activate_behaviors instead.")
def activate_behaviours(self,tag):
return self.activate_behaviors(tag)
return self.activate_behaviors(tag)

__all__ = ['lognormal_real_mean', 'lognormal_rm', 'uniform_gap', 'is_number', 'deprecated_warning', 'NetworkObjectBase'] # numpy functions are only accessible inside this file
20 changes: 8 additions & 12 deletions NetworkCore/Neuron_Group.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,28 +32,24 @@ def __init__(self, net, size, behavior, tag=None, color=None):
size = -1#will be overwritten by size-behavior

self.size = size
self.BaseNeuronGroup = self#used for subgroup reconstruction
self.afferent_synapses = {} #set by SynapseGroup
self.efferent_synapses = {}
self.mask = True#np.array([True for _ in range(size)]).astype(bool)#True#used for subgroup reconstruction
self.id = np.arange(self.size)

if color is not None:
self.color = color

super().__init__(tag, net, behavior)
self.add_tag('ng')

self.BaseNeuronGroup = self#used for subgroup reconstruction

if net is not None:
net.NeuronGroups.append(self)
for tag in self.tags:
if not hasattr(net, tag):
setattr(net, tag, self)

self.afferent_synapses = {} #set by SynapseGroup
self.efferent_synapses = {}

self.mask = True#np.array([True for _ in range(size)]).astype(bool)#True#used for subgroup reconstruction

self.id = np.arange(self.size)

if color is not None:
self.color = color

def synapses(self, mode, tag='All'):#afferent=0, efferent=1
if mode==afferent:
return self.afferent_synapses[tag]
Expand Down
2 changes: 2 additions & 0 deletions NetworkCore/Synapse_Group.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,3 +194,5 @@ def ignore_transpose_mode(self, W):# always returns DxS matrix
else:
return W



55 changes: 33 additions & 22 deletions test_pymoNNto.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,17 @@ def get_sample_network():

return My_Network, My_Neurons, My_Synapses, sm

def get_sample_network_list():
My_Network = Network()
My_Neurons = NeuronGroup(net=My_Network, tag='my_neurons', size=100, behavior=[
Counter(inc='[2#I]'),
Recorder('count')
])
My_Synapses = SynapseGroup(net=My_Network, src=My_Neurons, dst=My_Neurons, tag='GLUTAMATE')
sm = StorageManager('test', random_nr=False, print_msg=False)
My_Network.initialize(storage_manager=sm)

return My_Network, My_Neurons, My_Synapses, sm

def test_basics():
net = Network()
Expand Down Expand Up @@ -113,40 +124,40 @@ def test_behavior_and_tagging():

# basic network
set_genome({'I': 1})
My_Network, My_Neurons, My_Synapses, sm = get_sample_network()
for My_Network, My_Neurons, My_Synapses, sm in [get_sample_network(), get_sample_network_list()]:

My_Network.simulate_iterations(1000)
My_Network.simulate_iterations(1000)

My_Network.deactivate_behaviors('Counter')
My_Network.simulate_iterations(10)
My_Network.deactivate_behaviors('Counter')
My_Network.simulate_iterations(10)

My_Network.activate_behaviors('Counter')
My_Network.simulate_iterations(20)
My_Network.activate_behaviors('Counter')
My_Network.simulate_iterations(20)

My_Network.recording_off()
My_Network.simulate_iterations(30)
My_Network.recording_off()
My_Network.simulate_iterations(30)

assert My_Network.iteration == 1000+10+20+30
assert np.mean(My_Neurons.count) == 1000+20+30
assert My_Network.iteration == 1000+10+20+30
assert np.mean(My_Neurons.count) == 1000+20+30

assert My_Synapses.src == My_Neurons
assert My_Synapses.dst == My_Neurons
assert My_Synapses.src == My_Neurons
assert My_Synapses.dst == My_Neurons

assert My_Neurons.synapses(afferent, 'GLUTAMATE') == [My_Synapses]
assert My_Neurons.synapses(afferent, 'GLUTAMATE') == [My_Synapses]

assert len(My_Network.all_objects()) == 3
assert len(My_Network.all_objects()) == 3

#tagging system
assert My_Network['my_neurons'] == [My_Neurons]
assert len(My_Network['count', 0]) == My_Network.iteration-30
#tagging system
assert My_Network['my_neurons'] == [My_Neurons]
assert len(My_Network['count', 0]) == My_Network.iteration-30

My_Network.clear_recorder()
assert len(My_Neurons['count', 0]) == 0
My_Network.clear_recorder()
assert len(My_Neurons['count', 0]) == 0

assert My_Network.tag_shortcuts['my_neurons'] == My_Network['my_neurons']
assert My_Network.tag_shortcuts['my_neurons'] == My_Network['my_neurons']

if os.path.isdir(folder+'test/'):
shutil.rmtree(folder+'test/')
if os.path.isdir(folder+'test/'):
shutil.rmtree(folder+'test/')



Expand Down

0 comments on commit 1fefe55

Please sign in to comment.