diff --git a/core/connection.py b/core/connection.py index df44ba9..0709b8a 100644 --- a/core/connection.py +++ b/core/connection.py @@ -4,7 +4,7 @@ import numpy as np -class Connection(): +class Connection: """TODO""" def __init__(self, source, destination, transmitter, name="Connection"): @@ -48,13 +48,13 @@ def set_target(self, target): """TODO""" self.target_state_vector = target - def transmitt(self, gid, ammount): + def transmit(self, gid, amount): """TODO""" self.targeted_transmit(self.destination, self.target_state_vector, gid, - ammount) + amount) def targeted_transmit(self, destination, target_state_vector, gid, - ammount): + amount): """TODO""" pass diff --git a/core/device.py b/core/device.py index f3e0b1c..152f6e6 100644 --- a/core/device.py +++ b/core/device.py @@ -3,7 +3,7 @@ """TODO""" -class Device(): +class Device: """TODO""" unique_id_count = 0 diff --git a/core/logger.py b/core/logger.py index 51035f4..e17138e 100644 --- a/core/logger.py +++ b/core/logger.py @@ -22,7 +22,7 @@ def __lt__(self, other): return self.value < other.value -class Logger(): +class Logger: """TODO""" def __init__(self, filename, rank, console_out=LogMessageType.PROGRESS, @@ -43,7 +43,7 @@ def __init__(self, filename, rank, console_out=LogMessageType.PROGRESS, print("Can't open logger output file.") raise - self.notification("Logger started on Rank %d" % (self.rank)) + self.notification("Logger started on Rank %d" % self.rank) def msg(self, message, msg_type=LogMessageType.NOTIFICATION, global_msg=False): diff --git a/core/mc_neuron_group.py b/core/mc_neuron_group.py index fe12cb8..cfff15f 100644 --- a/core/mc_neuron_group.py +++ b/core/mc_neuron_group.py @@ -14,3 +14,6 @@ def __init__(self, n, m, mode=NodeDistributionMode.AUTO): if self.evolve_locally: self.num_compartments = m self.group_name = "McNeuronGroup" + + def evolve(self): + pass diff --git a/core/monitor.py b/core/monitor.py index 94a3cdf..5cd1f8c 100644 --- a/core/monitor.py +++ b/core/monitor.py @@ -21,7 +21,7 @@ def __init__(self, filename): self.outfile = open(self.filename, 'wb') except OSError: core.logger.error("Can't open output file %s." - % (self.filename)) + % self.filename) raise def flush(self): diff --git a/core/spike_delay.py b/core/spike_delay.py index def15ac..37cae1b 100644 --- a/core/spike_delay.py +++ b/core/spike_delay.py @@ -3,7 +3,7 @@ """TODO""" -class SpikeDelay(): +class SpikeDelay: """TODO""" def __init__(self, delay): diff --git a/core/spiking_group.py b/core/spiking_group.py index 791f712..15d6d6c 100644 --- a/core/spiking_group.py +++ b/core/spiking_group.py @@ -53,7 +53,7 @@ def __init__(self, n, mode=NodeDistributionMode.AUTO): frac = self._calculate_rank_size(0) / simulation_min_distributed_size if mode == NodeDistributionMode.AUTO: - if frac >= 0 and frac < 1: + if 0 <= frac < 1: mode = NodeDistributionMode.BLOCKLOCK else: mode = NodeDistributionMode.ROUNDROBIN @@ -83,8 +83,7 @@ def _calculate_rank_size(self, rank=-1): else: comrank = self._mpi_rank - if (comrank >= self._locked_rank - and comrank < self._locked_rank + self._locked_range): + if self._locked_rank <= comrank < self._locked_rank + self._locked_range: if comrank - self._locked_rank >= self.size % self._locked_range: return self.size // self._locked_range else: @@ -100,7 +99,7 @@ def _lock_range(self, rank_fraction): self._locked_range = 1 core.logger.notification( "%s :: Group will run on single rank only (RANKLOCK)" - % (self.group_name)) + % self.group_name) else: free_ranks = self._mpi_size - SpikingGroup.last_locked_rank self._locked_range = int(rank_fraction * self._mpi_size + 0.5) @@ -112,7 +111,7 @@ def _lock_range(self, rank_fraction): core.logger.msg( "%s :: Not enough free ranks for RANGELOCK. Starting to " "fill at zero again ..." - % (self.group_name)) + % self.group_name) rank = self._mpi_rank self.evolve_locally = ((rank >= self._locked_rank) and diff --git a/core/system.py b/core/system.py index 61373f4..948fdb3 100644 --- a/core/system.py +++ b/core/system.py @@ -6,13 +6,28 @@ import numpy as np from mpi4py import MPI -from spaghetti.logger import LogMessageType -from spaghetti.spaghetti_definitions import (spaghetti_mindelay, - spaghetti_timestep) -from spaghetti.sync_buffer import SyncBuffer +from core.logger import LogMessageType +from core.core_definitions import (simulation_mindelay, simulation_timestep) +from core.sync_buffer import SyncBuffer -class System(): +def _progress_bar(fraction): + """TODO""" + bar = "" + division = 4 + percent = 100 * fraction + for i in range(100//division): + if i < percent // division: + bar += '=' + elif i == percent // division: + bar += '>' + else: + bar += ' ' + + print('[%s] %d%%\r' % (bar, percent), end='') + + +class System: """TODO""" def __init__(self, mpicomm, logger, directory, simulation_name, quiet): @@ -41,7 +56,7 @@ def __init__(self, mpicomm, logger, directory, simulation_name, quiet): logger.notification("Starting Spaghetti Kernel") logger.msg("Simulation timestep is set to %.2es" - % (spaghetti_timestep), LogMessageType.SETTINGS) + % simulation_timestep, LogMessageType.SETTINGS) if self._mpi_size > 0 and (self._mpi_size & (self._mpi_size - 1)): self._logger.msg("The number of processes is not a power of " @@ -53,21 +68,6 @@ def _step(self): """TODO""" self._clock += 1 - def _progress_bar(self, fraction, clock): - """TODO""" - bar = "" - division = 4 - percent = 100 * fraction - for i in range(100//division): - if i < percent // division: - bar += '=' - elif i == percent // division: - bar += '>' - else: - bar += ' ' - - print('[%s] %d%%\r' % (bar, percent), end='') - def _run(self, start_time, stop_time, total_time, checking=False): """TODO""" if self.get_total_neurons() == 0: @@ -76,7 +76,7 @@ def _run(self, start_time, stop_time, total_time, checking=False): run_time = (stop_time - self._clock) * spaghetti_timestep self._logger.notification("Simulation triggered (run time = %.2fs) ..." - % (run_time)) + % run_time) if self._clock == 0: self._logger.msg("On this rank: neurons %d, synapses %d" @@ -106,7 +106,7 @@ def _run(self, start_time, stop_time, total_time, checking=False): or self._clock == stop_time - 1)): fraction = ((self._clock - start_time + 1) * spaghetti_timestep / total_time) - self._progress_bar(fraction, self._clock) + _progress_bar(fraction) # Evolve neuron groups self._evolve() @@ -134,7 +134,7 @@ def _run(self, start_time, stop_time, total_time, checking=False): elapsed = time.process_time() - t_sim_start self._logger.notification("Simulation finished. Elapsed wall time " - "%.2fs" % (elapsed)) + "%.2fs" % elapsed) return True @@ -159,8 +159,7 @@ def _execute_checkers(self): """TODO""" for i, checker in enumerate(self._checkers): if not checker.execute(): - self._logger.warning("Checker %d triggered abort of simulation" - % (i)) + self._logger.warning("Checker %d triggered abort of simulation" % i) return False return True @@ -265,7 +264,7 @@ def set_master_seed(self, seed=None): seed_multiplier = 257 self.rank_master_seed = seed_multiplier * seed * (self._mpi_rank + 1) self._logger.msg("Seeding this rank with master seed %d" % - (self.rank_master_seed), LogMessageType.NOTIFICATION) + self.rank_master_seed, LogMessageType.NOTIFICATION) self.rng = np.random.RandomState(seed=self.rank_master_seed) def get_seed(self): diff --git a/core/trace.py b/core/trace.py index 54b390d..2d2e335 100644 --- a/core/trace.py +++ b/core/trace.py @@ -4,7 +4,7 @@ import numpy as np -class Trace(): +class Trace: """TODO""" def __init__(self, size): diff --git a/core/trace_2d.py b/core/trace_2d.py index fb3fc41..626d844 100644 --- a/core/trace_2d.py +++ b/core/trace_2d.py @@ -4,7 +4,7 @@ import numpy as np -class Trace2D(): +class Trace2D: """TODO""" def __init__(self, size): diff --git a/core/voltage_monitor.py b/core/voltage_monitor.py index aa80bc7..c57896b 100644 --- a/core/voltage_monitor.py +++ b/core/voltage_monitor.py @@ -43,7 +43,7 @@ def __init__(self, source, uid, filename, stepsize=simulation_timestep, if self.uid < self.source.get_post_size(): core.kernel.register_device(self) self.outfile.write("# Recording from neuron %d\n".encode() - % (self.gid)) + % self.gid) def execute(self): """TODO""" @@ -72,7 +72,7 @@ def _set_stop_time(self, duration): """TODO""" if duration < 0: core.logger.warning("Warning: Negative stop times not" - " supported -- ingoring.") + " supported -- ignoring.") else: self.stop_time = (core.kernel.get_clock() + duration / simulation_timestep) diff --git a/models/mc_lif_group.py b/models/mc_lif_group.py index eb2c744..13e7d2c 100644 --- a/models/mc_lif_group.py +++ b/models/mc_lif_group.py @@ -37,7 +37,7 @@ def spike_condition(mem, slope, v_thr, c1=0.4, c2=0.5): else: return 0 - class Soma(): + class Soma: """TODO""" def __init__(self, size, branch, nrn, params={}): @@ -123,7 +123,7 @@ def check_thresholds(self): self.mem[i] = self.v_rest self.ref[i] -= 1 - class Branch(): + class Branch: """TODO""" def __init__(self, size, nrn, params={}): diff --git a/models/poisson_pattern_group.py b/models/poisson_pattern_group.py index 48699c4..b05ef67 100644 --- a/models/poisson_pattern_group.py +++ b/models/poisson_pattern_group.py @@ -54,7 +54,7 @@ def evolve(self): self.pattern_end = clock + self.timesteps_delay + \ self.timesteps_pattern - if clock >= self.pattern_start and clock < self.pattern_end: + if self.pattern_start <= clock < self.pattern_end: for assembly, idx_inactive_neurons in zip( self.active_assemblies, self.idc_inactive_neurons):