Skip to content

Commit 29c61b3

Browse files
committed
run pre-commit
1 parent bc2ae20 commit 29c61b3

File tree

4 files changed

+80
-40
lines changed

4 files changed

+80
-40
lines changed

pynest/nest/versionchecker.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# -*- coding: utf-8 -*-
2+
#
3+
# versionchecker.py
4+
#
5+
# This file is part of NEST.
6+
#
7+
# Copyright (C) 2004 The NEST Initiative
8+
#
9+
# NEST is free software: you can redistribute it and/or modify
10+
# it under the terms of the GNU General Public License as published by
11+
# the Free Software Foundation, either version 2 of the License, or
12+
# (at your option) any later version.
13+
#
14+
# NEST is distributed in the hope that it will be useful,
15+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
# GNU General Public License for more details.
18+
#
19+
# You should have received a copy of the GNU General Public License
20+
# along with NEST. If not, see <http://www.gnu.org/licenses/>.
21+
22+
23+
"""
24+
Check that the Python compiletime and runtime versions match.
25+
26+
"""
27+
28+
v_major_mismatch = sys.version_info.major != 3
29+
v_minor_mismatch = sys.version_info.minor != 13
30+
if v_major_mismatch or v_minor_mismatch:
31+
msg = "Python runtime version does not match 'nest' compiletime version. " + "Please use Python 3.13."
32+
raise Exception(msg)

testsuite/pytests/test_sir_neuron.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,26 +31,27 @@ def test_single_neuron_dynamics(self, tau_m=1, simtime=5):
3131

3232
nest.ResetKernel()
3333

34-
print('Testing single neuron dynamics of sir_neuron model')
34+
print("Testing single neuron dynamics of sir_neuron model")
3535

36-
h_expected = [1.] * int((simtime - 1) * 10)
36+
h_expected = [1.0] * int((simtime - 1) * 10)
3737
# expected output S: 1 time step in initial 0 state, then it takes tau_m to update
3838
# to the infected state which happens with prob. 1, then it takes tau_m to updae
3939
# to recovered state which happens with prob 1.
40-
S_expected = ([0.] * int(1 + tau_m * 10) + [1.] * int(tau_m * 10)
41-
+ [2.] * int((simtime - 1) * 10 - 1 - 2 * 10 * tau_m))
40+
S_expected = (
41+
[0.0] * int(1 + tau_m * 10) + [1.0] * int(tau_m * 10) + [2.0] * int((simtime - 1) * 10 - 1 - 2 * 10 * tau_m)
42+
)
4243
# expected spike output: one spike one time step after neuron gets infected,
4344
# two spikes one time step after neuron leaves infectious state
4445
spikes_expected = [0.1 + tau_m + 0.1, 0.1 + 2 * tau_m + 0.1, 0.1 + 2 * tau_m + 0.1]
4546

46-
nrn = nest.Create('sir_neuron')
47+
nrn = nest.Create("sir_neuron")
4748
nrn.h = 1
4849
nrn.mu_sir = 1
4950
nrn.beta_sir = 1
5051
nrn.tau_m = 1
5152

5253
multi = nest.Create("multimeter", {"record_from": ["S", "h"], "interval": 0.1})
53-
spike_recorder = nest.Create('spike_recorder')
54+
spike_recorder = nest.Create("spike_recorder")
5455

5556
nest.Connect(multi, nrn)
5657
nest.Connect(nrn, spike_recorder)
@@ -59,7 +60,7 @@ def test_single_neuron_dynamics(self, tau_m=1, simtime=5):
5960

6061
S_recorded = multi.events["S"]
6162
h_recorded = multi.events["h"]
62-
spikes_recorded = spike_recorder.events['times']
63+
spikes_recorded = spike_recorder.events["times"]
6364

6465
assert np.allclose(h_expected, h_recorded)
6566
assert np.allclose(S_expected, S_recorded)
@@ -70,16 +71,17 @@ def test_propagation_of_infection(self, tau_m=1, simtime=5):
7071

7172
nest.ResetKernel()
7273

73-
print('Testing propagation of infection in sir_neuron model')
74+
print("Testing propagation of infection in sir_neuron model")
7475

75-
S_expected = ([0.] * int(1 + tau_m * 10) + [0.] * int(tau_m * 10)
76-
+ [1.] * int((simtime - 1) * 10 - 1 - 2 * 10 * tau_m))
76+
S_expected = (
77+
[0.0] * int(1 + tau_m * 10) + [0.0] * int(tau_m * 10) + [1.0] * int((simtime - 1) * 10 - 1 - 2 * 10 * tau_m)
78+
)
7779
# expected output S: 1 time step in initial 0 state, then it takes tau_m to update
7880
# neuron 1 to the infected state during which neuron 2 stays in the susceptible 0 state,
7981
# then it takes tau_m to update neuron 2 to the infected state
8082

81-
nrn_1 = nest.Create('sir_neuron')
82-
nrn_2 = nest.Create('sir_neuron')
83+
nrn_1 = nest.Create("sir_neuron")
84+
nrn_2 = nest.Create("sir_neuron")
8385

8486
# infect nrn_1 at time 0.1ms + tau_m
8587
nrn_1.h = 1
@@ -100,7 +102,7 @@ def test_propagation_of_infection(self, tau_m=1, simtime=5):
100102
assert np.allclose(S_expected, S_recorded)
101103

102104

103-
if __name__ == '__main__':
105+
if __name__ == "__main__":
104106
test = TestSirNeuron()
105107
test.test_single_neuron_dynamics()
106108
test.test_propagation_of_infection()

testsuite/pytests/test_sirs_neuron.py

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,28 +35,31 @@ def test_single_neuron_dynamics(self):
3535

3636
nest.ResetKernel()
3737

38-
print('Testing single neuron dynamics of sirs_neuron model')
38+
print("Testing single neuron dynamics of sirs_neuron model")
3939

40-
h_expected = [1.] * int((simtime - 1) * 10)
40+
h_expected = [1.0] * int((simtime - 1) * 10)
4141
# expected output S: 1 time step in initial 0 state, then it takes tau_m to update
4242
# to the infected state which happens with prob. 1, then it takes tau_m to updae
4343
# to recovered state which happens with prob 1.
44-
S_expected = ([0.] * int(1 + tau_m * 10) + [1.] * int(tau_m * 10)
45-
+ [2.] * int(tau_m * 10)
46-
+ [0.] * int((simtime - 1) * 10 - 1 - 3 * 10 * tau_m))
44+
S_expected = (
45+
[0.0] * int(1 + tau_m * 10)
46+
+ [1.0] * int(tau_m * 10)
47+
+ [2.0] * int(tau_m * 10)
48+
+ [0.0] * int((simtime - 1) * 10 - 1 - 3 * 10 * tau_m)
49+
)
4750
# expected spike output: one spike one time step after neuron gets infected,
4851
# two spikes one time step after neuron leaves infectious state
4952
spikes_expected = [0.1 + tau_m + 0.1, 0.1 + 2 * tau_m + 0.1, 0.1 + 2 * tau_m + 0.1]
5053

51-
nrn = nest.Create('sirs_neuron')
54+
nrn = nest.Create("sirs_neuron")
5255
nrn.h = 1
5356
nrn.mu_sirs = 1
5457
nrn.beta_sirs = 1
5558
nrn.eta_sirs = 1
5659
nrn.tau_m = 1
5760

5861
multi = nest.Create("multimeter", {"record_from": ["S", "h"], "interval": 0.1})
59-
spike_recorder = nest.Create('spike_recorder')
62+
spike_recorder = nest.Create("spike_recorder")
6063

6164
nest.Connect(multi, nrn)
6265
nest.Connect(nrn, spike_recorder)
@@ -67,7 +70,7 @@ def test_single_neuron_dynamics(self):
6770
h_recorded = multi.events["h"]
6871
# since we only record the first (simtime - 1)ms for S and h,
6972
# also only record the first (simtime - 1)ms of spikes
70-
spikes_recorded = spike_recorder.events['times'][spike_recorder.events['times'] <= (simtime - 1)]
73+
spikes_recorded = spike_recorder.events["times"][spike_recorder.events["times"] <= (simtime - 1)]
7174

7275
assert np.allclose(h_expected, h_recorded)
7376
assert np.allclose(S_expected, S_recorded)
@@ -78,16 +81,17 @@ def test_propagation_of_infection(self, tau_m=1, simtime=5):
7881

7982
nest.ResetKernel()
8083

81-
print('Testing propagation of infection in sirs_neuron model')
84+
print("Testing propagation of infection in sirs_neuron model")
8285

83-
S_expected = ([0.] * int(1 + tau_m * 10) + [0.] * int(tau_m * 10)
84-
+ [1.] * int((simtime - 1) * 10 - 1 - 2 * 10 * tau_m))
86+
S_expected = (
87+
[0.0] * int(1 + tau_m * 10) + [0.0] * int(tau_m * 10) + [1.0] * int((simtime - 1) * 10 - 1 - 2 * 10 * tau_m)
88+
)
8589
# expected output S: 1 time step in initial 0 state, then it takes tau_m to update
8690
# neuron 1 to the infected state during which neuron 2 stays in the susceptible 0 state,
8791
# then it takes tau_m to update neuron 2 to the infected state
8892

89-
nrn_1 = nest.Create('sirs_neuron')
90-
nrn_2 = nest.Create('sirs_neuron')
93+
nrn_1 = nest.Create("sirs_neuron")
94+
nrn_2 = nest.Create("sirs_neuron")
9195

9296
# infect nrn_1 at time 0.1ms + tau_m
9397
nrn_1.h = 1
@@ -108,7 +112,7 @@ def test_propagation_of_infection(self, tau_m=1, simtime=5):
108112
assert np.allclose(S_expected, S_recorded)
109113

110114

111-
if __name__ == '__main__':
115+
if __name__ == "__main__":
112116
test = TestSirNeuron()
113117
test.test_single_neuron_dynamics()
114118
test.test_propagation_of_infection()

testsuite/pytests/test_sis_neuron.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,26 +35,27 @@ def test_single_neuron_dynamics(self):
3535

3636
nest.ResetKernel()
3737

38-
print('Testing single neuron dynamics of sis_neuron model')
38+
print("Testing single neuron dynamics of sis_neuron model")
3939

40-
h_expected = [1.] * int((simtime - 1) * 10)
40+
h_expected = [1.0] * int((simtime - 1) * 10)
4141
# expected output S: 1 time step in initial 0 state, then it takes tau_m to update
4242
# to the infected state which happens with prob. 1, then it takes tau_m to updae
4343
# to recovered state which happens with prob 1.
44-
S_expected = ([0.] * int(1 + tau_m * 10) + [1.] * int(tau_m * 10)
45-
+ [0.] * int((simtime - 1) * 10 - 1 - 2 * 10 * tau_m))
44+
S_expected = (
45+
[0.0] * int(1 + tau_m * 10) + [1.0] * int(tau_m * 10) + [0.0] * int((simtime - 1) * 10 - 1 - 2 * 10 * tau_m)
46+
)
4647
# expected spike output: one spike one time step after neuron gets infected,
4748
# two spikes one time step after neuron leaves infectious state
4849
spikes_expected = [0.1 + tau_m + 0.1, 0.1 + 2 * tau_m + 0.1, 0.1 + 2 * tau_m + 0.1]
4950

50-
nrn = nest.Create('sis_neuron')
51+
nrn = nest.Create("sis_neuron")
5152
nrn.h = 1
5253
nrn.mu_sis = 1
5354
nrn.beta_sis = 1
5455
nrn.tau_m = 1
5556

5657
multi = nest.Create("multimeter", {"record_from": ["S", "h"], "interval": 0.1})
57-
spike_recorder = nest.Create('spike_recorder')
58+
spike_recorder = nest.Create("spike_recorder")
5859

5960
nest.Connect(multi, nrn)
6061
nest.Connect(nrn, spike_recorder)
@@ -65,7 +66,7 @@ def test_single_neuron_dynamics(self):
6566
h_recorded = multi.events["h"]
6667
# since we only record the first (simtime - 1)ms for S and h,
6768
# also only record the first (simtime - 1)ms of spikes
68-
spikes_recorded = spike_recorder.events['times'][spike_recorder.events['times'] <= (simtime - 1)]
69+
spikes_recorded = spike_recorder.events["times"][spike_recorder.events["times"] <= (simtime - 1)]
6970

7071
assert np.allclose(h_expected, h_recorded)
7172
assert np.allclose(S_expected, S_recorded)
@@ -76,16 +77,17 @@ def test_propagation_of_infection(self, tau_m=1, simtime=5):
7677

7778
nest.ResetKernel()
7879

79-
print('Testing propagation of infection in sis_neuron model')
80+
print("Testing propagation of infection in sis_neuron model")
8081

81-
S_expected = ([0.] * int(1 + tau_m * 10) + [0.] * int(tau_m * 10)
82-
+ [1.] * int((simtime - 1) * 10 - 1 - 2 * 10 * tau_m))
82+
S_expected = (
83+
[0.0] * int(1 + tau_m * 10) + [0.0] * int(tau_m * 10) + [1.0] * int((simtime - 1) * 10 - 1 - 2 * 10 * tau_m)
84+
)
8385
# expected output S: 1 time step in initial 0 state, then it takes tau_m to update
8486
# neuron 1 to the infected state during which neuron 2 stays in the susceptible 0 state,
8587
# then it takes tau_m to update neuron 2 to the infected state
8688

87-
nrn_1 = nest.Create('sis_neuron')
88-
nrn_2 = nest.Create('sis_neuron')
89+
nrn_1 = nest.Create("sis_neuron")
90+
nrn_2 = nest.Create("sis_neuron")
8991

9092
# infect nrn_1 at time 0.1ms + tau_m
9193
nrn_1.h = 1
@@ -106,7 +108,7 @@ def test_propagation_of_infection(self, tau_m=1, simtime=5):
106108
assert np.allclose(S_expected, S_recorded)
107109

108110

109-
if __name__ == '__main__':
111+
if __name__ == "__main__":
110112
test = TestSirNeuron()
111113
test.test_single_neuron_dynamics()
112114
test.test_propagation_of_infection()

0 commit comments

Comments
 (0)