- Timestamp:
- 10/30/11 15:45:23 (7 months ago)
- Location:
- trunk
- Files:
-
- 32 modified
-
src/brian/__init__.py (modified) (6 diffs)
-
src/brian/connectors.py (modified) (3 diffs)
-
src/brian/recording.py (modified) (1 diff)
-
src/common/__init__.py (modified) (1 diff)
-
src/common/control.py (modified) (1 diff)
-
src/common/populations.py (modified) (13 diffs)
-
src/common/projections.py (modified) (3 diffs)
-
src/connectors.py (modified) (14 diffs)
-
src/moose/__init__.py (modified) (6 diffs)
-
src/multisim.py (modified) (2 diffs)
-
src/nemo/__init__.py (modified) (8 diffs)
-
src/nemo/connectors.py (modified) (1 diff)
-
src/nemo/recording.py (modified) (1 diff)
-
src/nest/__init__.py (modified) (7 diffs)
-
src/nest/connectors.py (modified) (2 diffs)
-
src/nest/recording.py (modified) (3 diffs)
-
src/neuron/__init__.py (modified) (8 diffs)
-
src/neuron/connectors.py (modified) (2 diffs)
-
src/neuron/recording.py (modified) (1 diff)
-
src/pcsim/__init__.py (modified) (7 diffs)
-
src/pcsim/connectors.py (modified) (1 diff)
-
src/pcsim/recording.py (modified) (1 diff)
-
src/recording/__init__.py (modified) (4 diffs)
-
test/system/scenarios.py (modified) (8 diffs)
-
test/unittests/test_assembly.py (modified) (4 diffs)
-
test/unittests/test_basepopulation.py (modified) (12 diffs)
-
test/unittests/test_connectors.py (modified) (10 diffs)
-
test/unittests/test_population.py (modified) (5 diffs)
-
test/unittests/test_projection.py (modified) (1 diff)
-
test/unittests/test_recording.py (modified) (2 diffs)
-
test/unittests/test_simulation_control.py (modified) (2 diffs)
-
test/unittests/test_utility_functions.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/brian/__init__.py
r999 r1000 14 14 from pyNN.brian import simulator 15 15 from pyNN import common, recording, space, core, __doc__ 16 common.control.simulator = simulator17 recording.simulator = simulator18 16 from pyNN.random import * 19 17 from pyNN.recording import files … … 89 87 # ============================================================================== 90 88 91 get_time_step = common.get_time_step 92 get_min_delay = common.get_min_delay 93 get_max_delay = common.get_max_delay 94 num_processes = common.num_processes 95 rank = common.rank 89 get_current_time, get_time_step, get_min_delay, get_max_delay, \ 90 num_processes, rank = common.control.build_state_queries(simulator) 96 91 97 92 # ============================================================================== … … 99 94 # neurons. 100 95 # ============================================================================== 96 97 class Assembly(common.Assembly): 98 _simulator = simulator 99 100 101 class PopulationView(common.PopulationView): 102 _simulator = simulator 103 assembly_class = Assembly 104 105 def _get_view(self, selector, label=None): 106 return PopulationView(self, selector, label) 107 101 108 102 109 class Population(common.Population, common.BasePopulation): … … 105 112 term intended to include layers, columns, nuclei, etc., of cells. 106 113 """ 114 _simulator = simulator 107 115 recorder_class = Recorder 116 assembly_class = Assembly 117 118 def _get_view(self, selector, label=None): 119 return PopulationView(self, selector, label) 108 120 109 121 def _create_cells(self, cellclass, cellparams=None, n=1): … … 187 199 188 200 189 PopulationView = common.PopulationView190 Assembly = common.Assembly191 192 201 class Projection(common.Projection): 193 202 """ … … 196 205 parameters of those connections, including of plasticity mechanisms. 197 206 """ 207 _simulator = simulator 198 208 199 209 def __init__(self, presynaptic_population, postsynaptic_population, method, -
trunk/src/brian/connectors.py
r998 r1000 10 10 from pyNN.random import RandomDistribution 11 11 import numpy 12 from pyNN import random, common,core12 from pyNN import core 13 13 from pyNN.connectors import AllToAllConnector, \ 14 14 ProbabilisticConnector, \ … … 24 24 WeightGenerator, \ 25 25 DelayGenerator, \ 26 ProbaGenerator 26 ProbaGenerator, Connector 27 from pyNN.brian import simulator 28 29 Connector._simulator = simulator 30 27 31 28 32 class FastProbabilisticConnector(ProbabilisticConnector): … … 125 129 raise Exception('Expression for weights or delays is not supported for OneToOneConnector !') 126 130 weights_generator = WeightGenerator(self.weights, local, projection, self.safe) 127 delays_generator = DelayGenerator(self.delays, local, self.safe)131 delays_generator = DelayGenerator(self.delays, local, kernel=projection._simulator.state, safe=self.safe) 128 132 weights = weights_generator.get(N) 129 133 delays = delays_generator.get(N) -
trunk/src/brian/recording.py
r978 r1000 21 21 class Recorder(recording.Recorder): 22 22 """Encapsulates data and functions related to recording model variables.""" 23 _simulator = simulator 23 24 24 25 def __init__(self, variable, population=None, file=None): -
trunk/src/common/__init__.py
r999 r1000 49 49 50 50 from populations import IDMixin, BasePopulation, Population, PopulationView, Assembly, is_conductance 51 from projections import Projection, check_weight, check_delay,DEFAULT_WEIGHT51 from projections import Projection, check_weight, DEFAULT_WEIGHT 52 52 from procedural_api import build_create, build_connect, set, build_record, initialize 53 from control import setup, end, run, reset, get_current_time, get_time_step, \ 54 get_min_delay, get_max_delay, num_processes, rank 53 from control import setup -
trunk/src/common/control.py
r999 r1000 40 40 raise NotImplementedError 41 41 42 def reset(): 43 """ 44 Reset the time to zero, neuron membrane potentials and synaptic weights to 45 their initial values, and delete any recorded data. The network structure 46 is not changed, nor is the specification of which neurons to record from. 47 """ 48 simulator.reset() 42 def build_reset(simulator): 43 def reset(): 44 """ 45 Reset the time to zero, neuron membrane potentials and synaptic weights to 46 their initial values, and delete any recorded data. The network structure 47 is not changed, nor is the specification of which neurons to record from. 48 """ 49 simulator.reset() 50 return reset 49 51 50 def get_current_time(): 51 """Return the current time in the simulation.""" 52 return simulator.state.t 53 54 def get_time_step(): 55 """Return the integration time step.""" 56 return simulator.state.dt 57 58 def get_min_delay(): 59 """Return the minimum allowed synaptic delay.""" 60 return simulator.state.min_delay 61 62 def get_max_delay(): 63 """Return the maximum allowed synaptic delay.""" 64 return simulator.state.max_delay 65 66 def num_processes(): 67 """Return the number of MPI processes.""" 68 return simulator.state.num_processes 69 70 def rank(): 71 """Return the MPI rank of the current node.""" 72 return simulator.state.mpi_rank 52 def build_state_queries(simulator): 53 def get_current_time(): 54 """Return the current time in the simulation.""" 55 return simulator.state.t 56 57 def get_time_step(): 58 """Return the integration time step.""" 59 return simulator.state.dt 60 61 def get_min_delay(): 62 """Return the minimum allowed synaptic delay.""" 63 return simulator.state.min_delay 64 65 def get_max_delay(): 66 """Return the maximum allowed synaptic delay.""" 67 return simulator.state.max_delay 68 69 def num_processes(): 70 """Return the number of MPI processes.""" 71 return simulator.state.num_processes 72 73 def rank(): 74 """Return the MPI rank of the current node.""" 75 return simulator.state.mpi_rank 76 77 return get_current_time, get_time_step, get_min_delay, get_max_delay, num_processes, rank -
trunk/src/common/populations.py
r999 r1000 166 166 return self.all_cells[index] 167 167 elif isinstance(index, (slice, list, numpy.ndarray)): 168 return PopulationView(self,index)168 return self._get_view(index) 169 169 elif isinstance(index, tuple): 170 return PopulationView(self,list(index))170 return self._get_view(list(index)) 171 171 else: 172 172 raise TypeError("indices must be integers, slices, lists, arrays or tuples, not %s" % type(index).__name__) … … 206 206 """ 207 207 assert isinstance(other, BasePopulation) 208 return Assembly(self, other)208 return self.assembly_class(self, other) 209 209 210 210 def _get_cell_position(self, id): … … 248 248 logger.debug("The %d cells recorded have indices %s" % (n, indices)) 249 249 logger.debug("%s.sample(%s)", self.label, n) 250 return PopulationView(self,indices)250 return self._get_view(indices) 251 251 252 252 def get(self, parameter_name, gather=False): … … 262 262 values = [getattr(cell, parameter_name) for cell in self] # list or array? 263 263 264 if gather == True and control.num_processes()> 1:265 all_values = { control.rank(): values }266 all_indices = { control.rank(): self.local_cells.tolist()}264 if gather == True and self._simulator.state.num_processes > 1: 265 all_values = { self._simulator.state.mpi_rank: values } 266 all_indices = { self._simulator.state.mpi_rank: self.local_cells.tolist()} 267 267 all_values = recording.gather_dict(all_values) 268 268 all_indices = recording.gather_dict(all_indices) 269 if control.rank()== 0:269 if self._simulator.state.mpi_rank == 0: 270 270 values = reduce(operator.add, all_values.values()) 271 271 indices = reduce(operator.add, all_indices.values()) … … 582 582 spike_counts = self.recorders['spikes'].count(gather, self.record_filter) 583 583 total_spikes = sum(spike_counts.values()) 584 if control.rank()== 0 or not gather: # should maybe use allgather, and get the numbers on all nodes584 if self._simulator.state.mpi_rank == 0 or not gather: # should maybe use allgather, and get the numbers on all nodes 585 585 if len(spike_counts) > 0: 586 586 return float(total_spikes)/len(spike_counts) … … 610 610 result[:,0] = cells 611 611 result[:,1:4] = self.positions.T 612 if control.rank()== 0:612 if self._simulator.state.mpi_rank == 0: 613 613 file.write(result, {'population' : self.label}) 614 614 file.close() … … 707 707 (order in the Population), counting only cells on the local MPI node. 708 708 """ 709 if control.num_processes()> 1:709 if self._simulator.state.num_processes > 1: 710 710 return self.local_cells.tolist().index(id) # probably very slow 711 711 #return numpy.nonzero(self.local_cells == id)[0][0] # possibly faster? … … 1098 1098 pindices = boundaries[1:].searchsorted(indices, side='right') 1099 1099 views = (self.populations[i][indices[pindices==i] - boundaries[i]] for i in numpy.unique(pindices)) 1100 return Assembly(*views)1100 return self.__class__(*views) 1101 1101 else: 1102 1102 raise TypeError("indices must be integers, slices, lists, arrays, not %s" % type(index).__name__) … … 1110 1110 """ 1111 1111 if isinstance(other, BasePopulation): 1112 return Assembly(*(self.populations + [other]))1112 return self.__class__(*(self.populations + [other])) 1113 1113 elif isinstance(other, Assembly): 1114 return Assembly(*(self.populations + other.populations))1114 return self.__class__(*(self.populations + other.populations)) 1115 1115 else: 1116 1116 raise TypeError("can only add a Population or another Assembly to an Assembly") … … 1203 1203 result[:,0] = cells 1204 1204 result[:,1:4] = self.positions.T 1205 if control.rank()== 0:1205 if self._simulator.state.mpi_rank == 0: 1206 1206 file.write(result, {'assembly' : self.label}) 1207 1207 file.close() … … 1249 1249 spike_counts = self.get_spike_counts() 1250 1250 total_spikes = sum(spike_counts.values()) 1251 if control.rank() == 0 or not gather: # should maybe use allgather, and get the numbers on all nodes1251 if self._simulator.state.mpi_rank() == 0 or not gather: # should maybe use allgather, and get the numbers on all nodes 1252 1252 return float(total_spikes)/len(spike_counts) 1253 1253 else: … … 1301 1301 'last_id' : self.last_id} 1302 1302 1303 metadata['dt'] = control.simulator.state.dt # note that this has to run on all nodes (at least for NEST)1303 metadata['dt'] = self._simulator.state.dt # note that this has to run on all nodes (at least for NEST) 1304 1304 data = numpy.zeros(format) 1305 1305 for pop in filenames.keys(): 1306 1306 if filenames[pop][1] is True: 1307 1307 name = filenames[pop][0] 1308 if gather==False and control.simulator.state.num_processes > 1:1309 name += '.%d' % control.simulator.state.mpi_rank1308 if gather==False and self._simulator.state.num_processes > 1: 1309 name += '.%d' % self._simulator.state.mpi_rank 1310 1310 p_file = files.NumpyBinaryFile(name, mode='r') 1311 1311 tmp_data = p_file.read() … … 1318 1318 1319 1319 if isinstance(file, basestring): 1320 if gather==False and control.simulator.state.num_processes > 1:1321 file += '.%d' % control.simulator.state.mpi_rank1320 if gather==False and self._simulator.state.num_processes > 1: 1321 file += '.%d' % self._simulator.state.mpi_rank 1322 1322 file = files.StandardTextFile(file, mode='w') 1323 1323 1324 if control.simulator.state.mpi_rank == 0 or gather == False:1324 if self._simulator.state.mpi_rank == 0 or gather == False: 1325 1325 file.write(data, metadata) 1326 1326 file.close() -
trunk/src/common/projections.py
r999 r1000 13 13 from pyNN.recording import files 14 14 from populations import BasePopulation, Assembly, is_conductance 15 from control import get_min_delay, get_max_delay, rank, num_processes16 15 17 16 logger = logging.getLogger("PyNN") … … 46 45 47 46 48 def check_delay(delay):49 if delay is None:50 delay = get_min_delay()51 # If the delay is too small , we have to throw an error52 if delay < get_min_delay() or delay > get_max_delay():53 raise errors.ConnectionError("delay (%s) is out of range [%s,%s]" % \54 (delay, get_min_delay(), get_max_delay()))55 return delay56 57 58 47 class Projection(object): 59 48 """ … … 301 290 all_lines = { rank(): lines } 302 291 all_lines = recording.gather_dict(all_lines) 303 if rank()== 0:292 if self._simulator.state.mpi_rank == 0: 304 293 lines = reduce(operator.add, all_lines.values()) 305 elif num_processes()> 1:306 file.rename('%s.%d' % (file.name, rank()))294 elif self._simulator.state.num_processes > 1: 295 file.rename('%s.%d' % (file.name, self._simulator.state.mpi_rank)) 307 296 308 297 logger.debug("--- Projection[%s].__saveConnections__() ---" % self.label) -
trunk/src/connectors.py
r999 r1000 178 178 """Generator for synaptic delays. %s""" % ConnectionAttributeGenerator.__doc__ 179 179 180 def __init__(self, source, local_mask, safe=True):180 def __init__(self, source, local_mask, kernel, safe=True): 181 181 ConnectionAttributeGenerator.__init__(self, source, local_mask, safe) 182 self.min_delay = common.get_min_delay()183 self. max_delay = common.get_max_delay()182 assert hasattr(kernel, "min_delay") 183 self.kernel = kernel 184 184 185 185 def check(self, delay): 186 all_negative = (delay<=self.max_delay).all() 187 all_positive = (delay>=self.min_delay).all()# If the delay is too small , we have to throw an error 186 min_delay = self.kernel.min_delay 187 max_delay = self.kernel.max_delay 188 all_negative = (delay<=max_delay).all() 189 all_positive = (delay>=min_delay).all()# If the delay is too small , we have to throw an error 188 190 if not (all_negative and all_positive): 189 raise errors.ConnectionError("delay (%s) is out of range [%s,%s]" % (delay, common.get_min_delay(), common.get_max_delay()))191 raise errors.ConnectionError("delay (%s) is out of range [%s,%s]" % (delay, min_delay, max_delay)) 190 192 return delay 191 193 … … 232 234 self.safe = safe 233 235 self.verbose = verbose 234 min_delay = common.get_min_delay()236 min_delay = self._simulator.state.min_delay 235 237 if delays is None: 236 238 self.delays = min_delay … … 252 254 def progression(self, count): 253 255 self.prog.update_amount(count) 254 if self.verbose and common.rank()== 0:256 if self.verbose and self._simulator.state.mpi_rank == 0: 255 257 print self.prog, "\r", 256 258 sys.stdout.flush() … … 293 295 self.N = projection.post.size 294 296 self.weights_generator = WeightGenerator(weights, self.local, projection, safe) 295 self.delays_generator = DelayGenerator(delays, self.local, safe)297 self.delays_generator = DelayGenerator(delays, self.local, kernel=projection._simulator.state, safe=safe) 296 298 self.probas_generator = ProbaGenerator(RandomDistribution('uniform', (0,1), rng=self.rng), self.local) 297 299 self._distance_matrix = None … … 468 470 proba_generator = ProbaGenerator(self.d_expression, connector.local) 469 471 self.progressbar(len(projection.pre)) 470 if ( common.num_processes()> 1) and (self.n_connections is not None):472 if (projection._simulator.state.num_processes > 1) and (self.n_connections is not None): 471 473 raise Exception("n_connections not implemented yet for this connector in parallel !") 472 474 … … 498 500 """ 499 501 # needs extending for dynamic synapses. 500 Connector.__init__(self, 0. , common.get_min_delay(), safe=safe, verbose=verbose)502 Connector.__init__(self, 0.0, self._simulator.state.min_delay, safe=safe, verbose=verbose) 501 503 self.conn_list = numpy.array(conn_list) 502 504 … … 550 552 distributed simulations. 551 553 """ 552 Connector.__init__(self, 0. , common.get_min_delay(), safe=safe, verbose=verbose)554 Connector.__init__(self, 0.0, self._simulator.state.min_delay, safe=safe, verbose=verbose) 553 555 554 556 if isinstance(file, basestring): … … 560 562 """Connect-up a Projection.""" 561 563 if self.distributed: 562 self.file.rename("%s.%d" % (self.file.name, common.rank()))564 self.file.rename("%s.%d" % (self.file.name, projection._simulator.state.mpi_rank)) 563 565 self.conn_list = self.file.read() 564 566 FromListConnector.connect(self, projection) … … 614 616 local = numpy.ones(len(projection.post), bool) 615 617 weights_generator = WeightGenerator(self.weights, local, projection, self.safe) 616 delays_generator = DelayGenerator(self.delays, local, self.safe)618 delays_generator = DelayGenerator(self.delays, local, kernel=projection._simulator.state, safe=self.safe) 617 619 distance_matrix = DistanceMatrix(projection.post.positions, self.space) 618 620 candidates = projection.post.all_cells … … 700 702 local = numpy.ones(len(projection.pre), bool) 701 703 weights_generator = WeightGenerator(self.weights, local, projection, self.safe) 702 delays_generator = DelayGenerator(self.delays, local, self.safe)704 delays_generator = DelayGenerator(self.delays, local, kernel=projection._simulator.state, safe=self.safe) 703 705 distance_matrix = DistanceMatrix(projection.pre.positions, self.space) 704 706 candidates = projection.pre.all_cells … … 767 769 raise Exception('Expression for weights or delays is not supported for OneToOneConnector !') 768 770 weights_generator = WeightGenerator(self.weights, local, projection, self.safe) 769 delays_generator = DelayGenerator(self.delays, local, self.safe)771 delays_generator = DelayGenerator(self.delays, local, kernel=projection._simulator.state, safe=self.safe) 770 772 weights = weights_generator.get(N) 771 773 delays = delays_generator.get(N) … … 871 873 self.rng = projection.rng 872 874 self.weights_generator = WeightGenerator(self.weights, local, projection, self.safe) 873 self.delays_generator = DelayGenerator(self.delays, local, self.safe)875 self.delays_generator = DelayGenerator(self.delays, local, kernel=projection._simulator.state, safe=self.safe) 874 876 self.probas_generator = ProbaGenerator(RandomDistribution('uniform',(0,1), rng=self.rng), local) 875 877 self.distance_matrix = DistanceMatrix(projection.post.positions, self.space, local) … … 893 895 """ 894 896 """ 895 min_delay = common.get_min_delay()897 min_delay = self._simulator.state.min_delay 896 898 Connector.__init__(self, None, None, safe=safe, verbose=verbose) 897 899 self.cset = cset … … 904 906 self.delays = delays 905 907 if delays is None: 906 self.delays = common.get_min_delay()908 self.delays = self._simulator.state.min_delay 907 909 else: 908 910 assert cset.arity == 2, 'must specify mask or connection-set with arity 2' -
trunk/src/moose/__init__.py
r999 r1000 17 17 from pyNN.moose import simulator 18 18 from pyNN import common, recording, core 19 common.control.simulator = simulator20 recording.simulator = simulator21 19 22 20 from pyNN.connectors import FixedProbabilityConnector, AllToAllConnector, OneToOneConnector … … 58 56 return get_current_time() 59 57 60 reset = common. reset58 reset = common.control.build_reset(simulator) 61 59 62 60 initialize = common.initialize … … 66 64 # ============================================================================== 67 65 68 get_current_time = common.get_current_time 69 get_time_step = common.get_time_step 70 get_min_delay = common.get_min_delay 71 get_max_delay = common.get_max_delay 72 num_processes = common.num_processes 73 rank = common.rank 66 get_current_time, get_time_step, get_min_delay, get_max_delay, \ 67 num_processes, rank = common.control.build_state_queries(simulator) 74 68 75 69 # ============================================================================== … … 78 72 # ============================================================================== 79 73 74 class Assembly(common.Assembly): 75 _simulator = simulator 76 77 78 class PopulationView(common.PopulationView): 79 _simulator = simulator 80 assembly_class = Assembly 81 82 def _get_view(self, selector, label=None): 83 return PopulationView(self, selector, label) 84 85 80 86 class Population(common.Population): 81 87 """ … … 83 89 term intended to include layers, columns, nuclei, etc., of cells. 84 90 """ 91 _simulator = simulator 85 92 recorder_class = Recorder 93 assembly_class = Assembly 94 95 def _get_view(self, selector, label=None): 96 return PopulationView(self, selector, label) 86 97 87 98 def _create_cells(self, cellclass, cellparams, n): … … 118 129 parameters of those connections, including of plasticity mechanisms. 119 130 """ 120 131 _simulator = simulator 121 132 nProj = 0 122 133 -
trunk/src/multisim.py
r999 r1000 8 8 9 9 from multiprocessing import Process, Queue 10 from pyNN import common, recording11 10 12 11 def run_simulation(network_model, sim, parameters, input_queue, output_queue): … … 17 16 """ 18 17 print "Running simulation with %s" % sim.__name__ 19 common.control.simulator = sim.simulator20 recording.simulator = sim.simulator21 18 network = network_model(sim, parameters) 22 19 print "Network constructed with %s." % sim.__name__ -
trunk/src/nemo/__init__.py
r999 r1000 14 14 from pyNN.nemo import simulator 15 15 from pyNN import common, recording, space, core, __doc__ 16 common.control.simulator = simulator17 recording.simulator = simulator18 16 from pyNN.random import * 19 17 from pyNN.recording import files … … 53 51 simulator.spikes_array_list = [] 54 52 simulator.recorder_lise = [] 55 return rank()53 return simulator.state.mpi_rank 56 54 57 55 def end(compatible_output=True): … … 64 62 electrodes.current_sources = [] 65 63 66 def get_current_time():67 """Return the current time in the simulation."""68 return simulator.state.t69 64 70 65 def run(simtime): 71 66 """Run the simulation for simtime ms.""" 72 67 simulator.state.run(simtime) 73 return get_current_time()68 return simulator.state.t 74 69 75 70 reset = simulator.reset … … 80 75 # ============================================================================== 81 76 82 get_time_step = common.get_time_step 83 get_min_delay = common.get_min_delay 84 get_max_delay = common.get_max_delay 85 num_processes = common.num_processes 86 rank = common.rank 77 get_current_time, get_time_step, get_min_delay, get_max_delay, \ 78 num_processes, rank = common.control.build_state_queries(simulator) 87 79 88 80 # ============================================================================== … … 91 83 # ============================================================================== 92 84 85 class Assembly(common.Assembly): 86 _simulator = simulator 87 88 89 class PopulationView(common.PopulationView): 90 _simulator = simulator 91 assembly_class = Assembly 92 93 def _get_view(self, selector, label=None): 94 return PopulationView(self, selector, label) 95 96 93 97 class Population(common.Population, common.BasePopulation): 94 98 """ … … 96 100 term intended to include layers, columns, nuclei, etc., of cells. 97 101 """ 102 _simulator = simulator 98 103 recorder_class = Recorder 104 assembly_class = Assembly 105 106 def _get_view(self, selector, label=None): 107 return PopulationView(self, selector, label) 99 108 100 109 def _create_cells(self, cellclass, cellparams=None, n=1): … … 135 144 def _set_initial_value_array(self, variable, value): 136 145 if not hasattr(value, "__len__"): 137 value = value*numpy.ones((len(self),)) 138 139 PopulationView = common.PopulationView 140 Assembly = common.Assembly 146 value = value*numpy.ones((len(self),)) 147 141 148 142 149 class Projection(common.Projection): … … 146 153 parameters of those connections, including of plasticity mechanisms. 147 154 """ 155 _simulator = simulator 148 156 149 157 def __init__(self, presynaptic_population, postsynaptic_population, method, -
trunk/src/nemo/connectors.py
r957 r1000 24 24 WeightGenerator, \ 25 25 DelayGenerator, \ 26 ProbaGenerator 26 ProbaGenerator, \ 27 Connector 28 from pyNN.nemo import simulator 29 30 Connector._simulator = simulator -
trunk/src/nemo/recording.py
r957 r1000 16 16 class Recorder(recording.Recorder): 17 17 """Encapsulates data and functions related to recording model variables.""" 18 _simulator = simulator 18 19 19 20 def __init__(self, variable, population=None, file=None): -
trunk/src/nest/__init__.py
r999 r1000 11 11 from pyNN.nest import simulator 12 12 from pyNN import common, recording, errors, space, __doc__ 13 common.control.simulator = simulator14 recording.simulator = simulator15 13 16 14 if recording.MPI and (nest.Rank() != recording.mpi_comm.rank): … … 154 152 return get_current_time() 155 153 156 reset = common. reset154 reset = common.control.build_reset(simulator) 157 155 158 156 initialize = common.initialize … … 162 160 # ============================================================================== 163 161 164 get_current_time = common.get_current_time 165 get_time_step = common.get_time_step 166 get_min_delay = common.get_min_delay 167 get_max_delay = common.get_max_delay 168 num_processes = common.num_processes 169 rank = common.rank 162 get_current_time, get_time_step, get_min_delay, get_max_delay, \ 163 num_processes, rank = common.control.build_state_queries(simulator) 164 170 165 171 166 # ============================================================================== … … 173 168 # neurons. 174 169 # ============================================================================== 170 171 class Assembly(common.Assembly): 172 _simulator = simulator 173 174 175 class PopulationView(common.PopulationView): 176 _simulator = simulator 177 assembly_class = Assembly 178 179 def _get_view(self, selector, label=None): 180 return PopulationView(self, selector, label) 181 175 182 176 183 class Population(common.Population): … … 179 186 term intended to include layers, columns, nuclei, etc., of cells. 180 187 """ 188 _simulator = simulator 181 189 recorder_class = Recorder 190 assembly_class = Assembly 191 192 def _get_view(self, selector, label=None): 193 return PopulationView(self, selector, label) 182 194 183 195 def _create_cells(self, cellclass, cellparams, n): … … 280 292 nest.SetStatus(self.local_cells.tolist(), variable, value) 281 293 282 PopulationView = common.PopulationView283 Assembly = common.Assembly284 285 294 286 295 class Projection(common.Projection): … … 290 299 parameters of those connections, including of plasticity mechanisms. 291 300 """ 292 301 _simulator = simulator 293 302 nProj = 0 294 303 -
trunk/src/nest/connectors.py
r998 r1000 13 13 FromListConnector, FromFileConnector, WeightGenerator, \ 14 14 DelayGenerator, ProbaGenerator, DistanceMatrix, CSAConnector 15 from pyNN. common import rank, num_processes15 from pyNN.nest import simulator 16 16 import numpy 17 17 from pyNN.space import Space 18 19 Connector._simulator = simulator 18 20 19 21 … … 35 37 self.local_long[idx] = True 36 38 self.weights_generator = WeightGenerator(weights, self.local_long, projection, safe) 37 self.delays_generator = DelayGenerator(delays, self.local_long, safe)39 self.delays_generator = DelayGenerator(delays, self.local_long, kernel=projection._simulator.state, safe=safe) 38 40 self.probas_generator = ProbaGenerator(random.RandomDistribution('uniform',(0,1), rng=self.rng), self.local_long) 39 41 self.distance_matrix = DistanceMatrix(projection.pre.positions, self.space, self.local) -
trunk/src/nest/recording.py
r991 r1000 5 5 import warnings 6 6 import nest 7 from pyNN import recording, common,errors7 from pyNN import recording, errors 8 8 from pyNN.nest import simulator 9 9 … … 31 31 device_parameters = {"withgid": True, "withtime": True} 32 32 if self.type is 'multimeter': 33 device_parameters["interval"] = common.get_time_step()33 device_parameters["interval"] = simulator.state.dt 34 34 else: 35 35 device_parameters["precise_times"] = True … … 237 237 class Recorder(recording.Recorder): 238 238 """Encapsulates data and functions related to recording model variables.""" 239 239 _simulator = simulator 240 240 scale_factors = {'spikes': 1, 241 241 'v': 1, -
trunk/src/neuron/__init__.py
r999 r1000 12 12 from pyNN.random import * 13 13 from pyNN.neuron import simulator 14 from pyNN import common, core, recording as base_recording, space, __doc__ 15 common.control.simulator = simulator 16 base_recording.simulator = simulator 14 from pyNN import common, core, space, __doc__ 17 15 18 16 from pyNN.neuron.standardmodels.cells import * … … 83 81 return get_current_time() 84 82 85 reset = common. reset83 reset = common.control.build_reset(simulator) 86 84 87 85 initialize = common.initialize … … 91 89 # ============================================================================== 92 90 93 get_current_time = common.get_current_time 94 get_time_step = common.get_time_step 95 get_min_delay = common.get_min_delay 96 get_max_delay = common.get_max_delay 97 num_processes = common.num_processes 98 rank = common.rank 91 get_current_time, get_time_step, get_min_delay, get_max_delay, \ 92 num_processes, rank = common.control.build_state_queries(simulator) 99 93 100 94 … … 104 98 # ============================================================================== 105 99 100 class Assembly(common.Assembly): 101 _simulator = simulator 102 103 104 class PopulationView(common.PopulationView): 105 _simulator = simulator 106 assembly_class = Assembly 107 108 def _get_view(self, selector, label=None): 109 return PopulationView(self, selector, label) 110 111 106 112 class Population(common.Population): 107 113 """ … … 109 115 term intended to include layers, columns, nuclei, etc., of cells. 110 116 """ 117 _simulator = simulator 111 118 recorder_class = Recorder 119 assembly_class = Assembly 112 120 113 121 def __init__(self, size, cellclass, cellparams=None, structure=None, … … 116 124 common.Population.__init__(self, size, cellclass, cellparams, structure, label) 117 125 simulator.initializer.register(self) 126 127 def _get_view(self, selector, label=None): 128 return PopulationView(self, selector, label) 118 129 119 130 def _create_cells(self, cellclass, cellparams, n): … … 157 168 158 169 159 PopulationView = common.PopulationView160 Assembly = common.Assembly161 162 170 class Projection(common.Projection): 163 171 """ … … 166 174 parameters of those connections, including of plasticity mechanisms. 167 175 """ 168 176 _simulator = simulator 169 177 nProj = 0 170 178 -
trunk/src/neuron/connectors.py
r957 r1000 8 8 """ 9 9 10 from pyNN.neuron import simulator 10 11 from pyNN.connectors import AllToAllConnector, \ 11 12 OneToOneConnector, \ … … 17 18 FixedNumberPostConnector, \ 18 19 SmallWorldConnector, \ 19 CSAConnector 20 CSAConnector, \ 21 Connector 20 22 21 22 23 23 Connector._simulator = simulator -
trunk/src/neuron/recording.py
r957 r1000 17 17 class Recorder(recording.Recorder): 18 18 """Encapsulates data and functions related to recording model variables.""" 19 19 _simulator = simulator 20 20 21 def _record(self, new_ids): 21 22 """Add the cells in `new_ids` to the set of recorded cells.""" -
trunk/src/pcsim/__init__.py
r999 r1000 22 22 from pyNN import common, recording, errors, space, core, __doc__ 23 23 from pyNN.pcsim import simulator 24 common.control.simulator = simulator25 recording.simulator = simulator26 24 import os.path 27 25 import types … … 206 204 return simulator.state.t 207 205 208 reset = common. reset206 reset = common.control.build_reset(simulator) 209 207 210 208 initialize = common.initialize 211 209 212 get_current_time = common.get_current_time 213 get_time_step = common.get_time_step 214 get_min_delay = common.get_min_delay 215 get_max_delay = common.get_max_delay 216 num_processes = common.num_processes 217 rank = common.rank 210 get_current_time, get_time_step, get_min_delay, get_max_delay, \ 211 num_processes, rank = common.control.build_state_queries(simulator) 218 212 219 213 … … 222 216 # neurons. 223 217 # ============================================================================== 218 219 class Assembly(common.Assembly): 220 _simulator = simulator 221 222 223 class PopulationView(common.PopulationView): 224 _simulator = simulator 225 assembly_class = Assembly 226 227 def _get_view(self, selector, label=None): 228 return PopulationView(self, selector, label) 229 224 230 225 231 class Population(common.Population): … … 228 234 term intended to include layers, columns, nuclei, etc., of cells. 229 235 """ 236 _simulator = simulator 230 237 recorder_class = Recorder 238 assembly_class = Assembly 231 239 232 240 def __init__(self, size, cellclass, cellparams=None, structure=None, … … 234 242 __doc__ = common.Population.__doc__ 235 243 common.Population.__init__(self, size, cellclass, cellparams, structure, label) 244 245 def _get_view(self, selector, label=None): 246 return PopulationView(self, selector, label) 236 247 237 248 def _create_cells(self, cellclass, cellparams, n): … … 406 417 obj = simulator.net.object(self.pcsim_population[i]) 407 418 if obj: apply( obj, methodname, (), arguments) 408 409 PopulationView = common.PopulationView 410 Assembly = common.Assembly 419 411 420 412 421 class Projection(common.Projection, WDManager): … … 416 425 parameters of those connections, including of plasticity mechanisms. 417 426 """ 418 427 _simulator = simulator 419 428 nProj = 0 420 429 synapse_target_ids = { 'excitatory': 1, 'inhibitory': 2 } -
trunk/src/pcsim/connectors.py
r957 r1000 16 16 FixedNumberPreConnector, \ 17 17 FixedNumberPostConnector, \ 18 SmallWorldConnector 18 SmallWorldConnector, \ 19 Connector 20 from pyNN.pcsim import simulator 19 21 20 22 21 22 23 Connector._simulator = simulator -
trunk/src/pcsim/recording.py
r957 r1000 13 13 class Recorder(recording.Recorder): 14 14 """Encapsulates data and functions related to recording model variables.""" 15 _simulator = simulator 15 16 16 17 fieldnames = {'v': 'Vm', -
trunk/src/recording/__init__.py
r957 r1000 144 144 filename = file 145 145 #rename_existing(filename) 146 if gather==False and s imulator.state.num_processes > 1:147 filename += '.%d' % s imulator.state.mpi_rank146 if gather==False and self._simulator.state.num_processes > 1: 147 filename += '.%d' % self._simulator.state.mpi_rank 148 148 else: 149 149 filename = file.name … … 155 155 metadata = self.metadata 156 156 logger.debug("data has size %s" % str(data.size)) 157 if s imulator.state.mpi_rank == 0 or gather == False:157 if self._simulator.state.mpi_rank == 0 or gather == False: 158 158 if compatible_output: 159 159 data = self._make_compatible(data) … … 178 178 'label': self.population.label, 179 179 }) 180 metadata['dt'] = s imulator.state.dt # note that this has to run on all nodes (at least for NEST)180 metadata['dt'] = self._simulator.state.dt # note that this has to run on all nodes (at least for NEST) 181 181 if not hasattr(self, '_data_size'): 182 182 self.get() … … 229 229 else: 230 230 raise Exception("Only implemented for spikes.") 231 if gather and s imulator.state.num_processes > 1:231 if gather and self._simulator.state.num_processes > 1: 232 232 N = gather_dict(N) 233 233 return N -
trunk/test/system/scenarios.py
r998 r1000 5 5 import numpy 6 6 from pyNN.utility import init_logging, assert_arrays_equal, assert_arrays_almost_equal, sort_by_column 7 8 9 def set_simulator(sim):10 common.simulator = sim.simulator11 recording.simulator = sim.simulator12 7 13 8 … … 28 23 Balanced network of integrate-and-fire neurons. 29 24 """ 30 set_simulator(sim)31 25 cell_params = { 32 26 'tau_m': 20.0, 'tau_syn_E': 5.0, 'tau_syn_I': 10.0, 'v_rest': -60.0, … … 95 89 API. 96 90 """ 97 set_simulator(sim)98 91 cell_params = { 99 92 'tau_m': 10.0, 'tau_syn_E': 2.0, 'tau_syn_I': 5.0, 'v_rest': -60.0, … … 155 148 once (except neuron[0], which never reaches threshold). 156 149 """ 157 set_simulator(sim)158 150 n = 100 159 151 t_start = 25.0 … … 203 195 connections should be potentiated more. 204 196 """ 205 set_simulator(sim)206 197 207 198 init_logging(logfile=None, debug=True) … … 301 292 pylab.rcParams['interactive'] = interactive 302 293 303 set_simulator(sim)304 294 sim.setup(timestep=dt) 305 295 … … 410 400 @register(exclude=['pcsim', 'moose']) 411 401 def test_EIF_cond_alpha_isfa_ista(sim): 412 set_simulator(sim)413 402 sim.setup(timestep=0.01, min_delay=0.1, max_delay=4.0) 414 403 ifcell = sim.create(sim.EIF_cond_alpha_isfa_ista, … … 452 441 from pyNN.utility import init_logging 453 442 init_logging(logfile=None, debug=True) 454 set_simulator(sim)455 443 dt = 0.1 456 444 tstop = 100.0 -
trunk/test/unittests/test_assembly.py
r999 r1000 7 7 8 8 9 class MockSimulator(object): 10 class MockState(object): 11 mpi_rank = 1 12 num_processes = 2 13 state = MockState() 14 9 15 def test_create_with_zero_populations(): 10 16 a = Assembly() … … 13 19 14 20 class MockPopulation(BasePopulation): 21 _simulator = MockSimulator 15 22 size = 10 16 local_cells = numpy.arange( 1,10,2)17 all_cells = numpy.arange( 10)18 _mask_local = numpy.arange( 10)%2 == 123 local_cells = numpy.arange(_simulator.state.mpi_rank,10,_simulator.state.num_processes) 24 all_cells = numpy.arange(size) 25 _mask_local = numpy.arange(size)%_simulator.state.num_processes == _simulator.state.mpi_rank 19 26 initialize = Mock() 20 27 positions = numpy.arange(3*size).reshape(3,size) … … 179 186 def test_save_positions(): 180 187 import os 181 orig_rank = common.rank182 common.rank = lambda:0188 Assembly._simulator = MockSimulator 189 Assembly._simulator.state.mpi_rank = 0 183 190 p1 = MockPopulation() 184 191 p2 = MockPopulation() … … 194 201 assert_equal(output_file.write.call_args[0][1], {'assembly': a.label}) 195 202 # arguably, the first column should contain indices, not ids. 196 common.rank = orig_rank203 del Assembly._simulator -
trunk/test/unittests/test_basepopulation.py
r999 r1000 1 1 from pyNN import common, errors, random, standardmodels, recording 2 from pyNN.common import populations , control2 from pyNN.common import populations 3 3 from nose.tools import assert_equal, assert_raises 4 4 import numpy … … 9 9 builtin_open = open 10 10 id_map = {'larry': 0, 'curly': 1, 'moe': 2, 'joe': 3, 'william': 4, 'jack': 5, 'averell': 6} 11 12 13 class MockSimulator(object): 14 class MockState(object): 15 mpi_rank = 1 16 num_processes = 3 17 state = MockState() 11 18 12 19 class MockStandardCell(standardmodels.StandardCellType): … … 19 26 20 27 class MockPopulation(populations.BasePopulation): 28 _simulator = MockSimulator 21 29 size = 13 22 30 all_cells = numpy.arange(100, 113) … … 27 35 celltype = MockStandardCell({}) 28 36 initial_values = {"foo": core.LazyArray(numpy.array((98, 100, 102)), shape=(3,))} 37 assembly_class = populations.Assembly 38 39 def _get_view(self, selector, label=None): 40 return populations.PopulationView(self, selector, label) 29 41 30 42 def id_to_index(self, id): … … 61 73 p = MockPopulation() 62 74 pv = p[3:9] 63 populations.PopulationView.assert_called_with(p, slice(3,9,None) )75 populations.PopulationView.assert_called_with(p, slice(3,9,None), None) 64 76 populations.PopulationView = orig_PV 65 77 … … 69 81 p = MockPopulation() 70 82 pv = p[range(3,9)] 71 populations.PopulationView.assert_called_with(p, range(3,9) )83 populations.PopulationView.assert_called_with(p, range(3,9), None) 72 84 populations.PopulationView = orig_PV 73 85 … … 77 89 p = MockPopulation() 78 90 pv = p[(3,5,7)] 79 populations.PopulationView.assert_called_with(p, [3,5,7] )91 populations.PopulationView.assert_called_with(p, [3,5,7], None) 80 92 populations.PopulationView = orig_PV 81 93 … … 175 187 176 188 def test_get_with_gather(): 177 np_orig = control.num_processes178 rank_orig = control.rank189 np_orig = MockPopulation._simulator.state.num_processes 190 rank_orig = MockPopulation._simulator.state.mpi_rank 179 191 gd_orig = recording.gather_dict 180 control.num_processes = lambda:2181 control.rank = lambda:0192 MockPopulation._simulator.state.num_processes = 2 193 MockPopulation._simulator.state.mpi_rank = 0 182 194 def mock_gather_dict(D): # really hacky 183 195 assert isinstance(D[0], list) … … 191 203 numpy.arange(10.0, 23.0)) 192 204 193 control.num_processes = np_orig194 control.rank = rank_orig205 MockPopulation._simulator.state.num_processes = np_orig 206 MockPopulation._simulator.state.mpi_rank = rank_orig 195 207 recording.gather_dict = gd_orig 196 208 … … 437 449 438 450 def test_meanSpikeCount(): 439 orig_rank = control.rank440 control.rank = lambda:0451 orig_rank = MockPopulation._simulator.state.mpi_rank 452 MockPopulation._simulator.state.mpi_rank = 0 441 453 p = MockPopulation() 442 454 p.recorders = {'spikes': Mock()} 443 455 p.recorders['spikes'].count = Mock(return_value={0: 2, 1: 5}) 444 456 assert_equal(p.meanSpikeCount(), 3.5) 445 control.rank = orig_rank457 MockPopulation._simulator.state.mpi_rank = orig_rank 446 458 447 459 def test_meanSpikeCount_on_slave_node(): 448 orig_rank = control.rank449 control.rank = lambda:1460 orig_rank = MockPopulation._simulator.state.mpi_rank 461 MockPopulation._simulator.state.mpi_rank = 1 450 462 p = MockPopulation() 451 463 p.recorders = {'spikes': Mock()} 452 464 p.recorders['spikes'].count = Mock(return_value={0: 2, 1: 5}) 453 465 assert p.meanSpikeCount() is numpy.NaN 454 control.rank = orig_rank466 MockPopulation._simulator.state.mpi_rank = orig_rank 455 467 456 468 def test_inject(): … … 469 481 def test_save_positions(): 470 482 import os 471 orig_rank = control.rank472 control.rank = lambda:0483 orig_rank = MockPopulation._simulator.state.mpi_rank 484 MockPopulation._simulator.state.mpi_rank = 0 473 485 p = MockPopulation() 474 486 p.all_cells = numpy.array([34, 45, 56, 67]) … … 480 492 assert_equal(output_file.write.call_args[0][1], {'population': p.label}) 481 493 # arguably, the first column should contain indices, not ids. 482 control.rank = orig_rank494 MockPopulation._simulator.state.mpi_rank = orig_rank -
trunk/test/unittests/test_connectors.py
r999 r1000 69 69 70 70 class MockProjection(object): 71 _simulator = MockSimulator 71 72 72 73 def __init__(self, pre, post): … … 102 103 103 104 105 def setup(): 106 connectors.Connector._simulator = MockSimulator 107 connectors.ConnectionAttributeGenerator._simulator = MockSimulator 108 109 def teardown(): 110 del connectors.Connector._simulator 111 del connectors.ConnectionAttributeGenerator._simulator 112 104 113 class TestOneToOneConnector(object): 105 114 106 115 def setup(self): 107 common.control.simulator = MockSimulator108 116 self.prj = MockProjection(MockPre(5), MockPost(numpy.array([0,1,0,1,0], dtype=bool))) 109 117 … … 129 137 130 138 def setup(self): 131 common.control.simulator = MockSimulator132 139 self.prj = MockProjection(MockPre(4), MockPost(numpy.array([0,1,0,1,0], dtype=bool))) 133 140 … … 182 189 C = connectors.AllToAllConnector(weights=0.1, delays=None) 183 190 assert_equal(C.weights, 0.1) 184 assert_equal(C.delays, common.get_min_delay())191 assert_equal(C.delays, C._simulator.state.min_delay) 185 192 assert C.safe 186 193 assert C.allow_self_connections … … 202 209 203 210 def setup(self): 204 common.control.simulator = MockSimulator205 211 self.prj = MockProjection(MockPre(4), 206 212 MockPost(numpy.array([0,1,0,1,0], dtype=bool))) … … 222 228 223 229 def setup(self): 224 common.control.simulator = MockSimulator225 230 self.prj = MockProjection(MockPre(4), 226 231 MockPost(numpy.array([0,1,0,1,0], dtype=bool))) … … 243 248 244 249 def setup(self): 245 common.control.simulator = MockSimulator246 250 self.prj = MockProjection(MockPre(4), 247 251 MockPost(numpy.array([0,1,0,1,0], dtype=bool))) … … 282 286 283 287 def setup(self): 284 common.control.simulator = MockSimulator285 288 self.prj = MockProjection(MockPre(4), 286 289 MockPost(numpy.array([0,1,0,1,0], dtype=bool))) … … 321 324 322 325 def setup(self): 323 common.control.simulator = MockSimulator324 326 self.prj = MockProjection(MockPre(4), 325 327 MockPost(numpy.array([0,1,0,1,0], dtype=bool))) … … 352 354 353 355 def setup(self): 354 common.control.simulator = MockSimulator355 356 self.prj = MockProjection(MockPre(4), 356 357 MockPost(numpy.array([0,1,0,1,0], dtype=bool))) -
trunk/test/unittests/test_population.py
r999 r1000 1 1 from pyNN import errors, random, standardmodels, space 2 from pyNN.common import control,populations2 from pyNN.common import populations 3 3 from nose.tools import assert_equal, assert_raises 4 4 import numpy … … 6 6 from pyNN.utility import assert_arrays_equal 7 7 8 9 class MockSimulator(object): 10 class MockState(object): 11 mpi_rank = 1 12 num_processes = 3 13 state = MockState() 8 14 9 15 class MockID(int, populations.IDMixin): … … 15 21 16 22 class MockPopulation(populations.Population): 23 _simulator = MockSimulator 17 24 recorder_class = Mock() 18 25 initialize = Mock() 26 27 def _get_view(self, selector, label=None): 28 return populations.PopulationView(self, selector, label) 19 29 20 30 def _create_cells(self, cellclass, cellparams, size): … … 107 117 108 118 def test_id_to_local_index(): 109 orig_np = control.num_processes110 control.num_processes = lambda:5119 orig_np = MockPopulation._simulator.state.num_processes 120 MockPopulation._simulator.state.num_processes = 5 111 121 p = MockPopulation(11, MockStandardCell) 112 122 # every 5th cell, starting with the 4th, is on this node. … … 114 124 assert_equal(p.id_to_local_index(p[8]), 1) 115 125 116 control.num_processes = lambda:1126 MockPopulation._simulator.state.num_processes = 1 117 127 # only one node 118 128 assert_equal(p.id_to_local_index(p[3]), 3) 119 129 assert_equal(p.id_to_local_index(p[8]), 8) 120 control.num_processes = orig_np130 MockPopulation._simulator.state.num_processes = orig_np 121 131 122 132 def test_id_to_local_index_with_invalid_id(): 123 orig_np = control.num_processes124 control.num_processes = lambda:5133 orig_np = MockPopulation._simulator.state.num_processes 134 MockPopulation._simulator.state.num_processes = 5 125 135 p = MockPopulation(11, MockStandardCell) 126 136 # every 5th cell, starting with the 4th, is on this node. 127 137 assert_raises(ValueError, p.id_to_local_index, p[0]) 128 control.num_processes = orig_np138 MockPopulation._simulator.state.num_processes = orig_np 129 139 130 140 # test structure property -
trunk/test/unittests/test_projection.py
r999 r1000 7 7 from pyNN.utility import assert_arrays_equal 8 8 9 orig_rank = common.rank 10 orig_np = common.num_processes 9 10 class MockSimulator(object): 11 class MockState(object): 12 mpi_rank = 1 13 num_processes = 3 14 state = MockState() 15 11 16 12 17 def setup(): 13 common. rank = lambda: 114 common.num_processes = lambda: 3 18 common.Projection._simulator = MockSimulator 19 15 20 16 21 def teardown(): 17 common.rank = orig_rank18 common.num_processes = orig_np22 del common.Projection._simulator 23 19 24 20 25 class MockStandardCell(standardmodels.StandardCellType): -
trunk/test/unittests/test_recording.py
r922 r1000 9 9 if MPI: 10 10 mpi_comm = recording.mpi_comm 11 12 def setup(): 13 recording.Recorder._simulator = MockSimulator(mpi_rank=0) 14 15 def teardown(): 16 del recording.Recorder._simulator 11 17 12 18 #def test_rename_existing(): … … 116 122 117 123 def test_write__with_filename__compatible_output__gather__onroot(): 118 recording.simulator = MockSimulator(mpi_rank=0)119 124 orig_metadata = recording.Recorder.metadata 120 125 recording.Recorder.metadata = {'a': 2, 'b':3} -
trunk/test/unittests/test_simulation_control.py
r999 r1000 32 32 33 33 def test_end(): 34 assert_raises(NotImplementedError, common. end)34 assert_raises(NotImplementedError, common.control.end) 35 35 36 36 def test_run(): 37 assert_raises(NotImplementedError, common. run, 10.0)37 assert_raises(NotImplementedError, common.control.run, 10.0) 38 38 39 39 def test_reset(): 40 common.control.simulator = MockSimulator() 41 common.reset() 42 assert common.control.simulator.reset_called 40 simulator = MockSimulator() 41 reset = common.control.build_reset(simulator) 42 reset() 43 assert simulator.reset_called 43 44 44 45 def test_initialize(): … … 46 47 common.initialize(p, 'v', -65.0) 47 48 assert p.initializations == [('v', -65.0)] 48 49 50 49 51 def test_current_time(): 50 common.control.simulator = MockSimulator() 51 common.get_current_time() 52 assert_equal(common.control.simulator.state.accesses, ['t']) 52 simulator = MockSimulator() 53 get_current_time, get_time_step, get_min_delay, get_max_delay, num_processes, rank = common.control.build_state_queries(simulator) 54 get_current_time() 55 assert_equal(simulator.state.accesses, ['t']) 53 56 54 57 def test_time_step(): 55 common.control.simulator = MockSimulator() 56 common.get_time_step() 57 assert_equal(common.control.simulator.state.accesses, ['dt']) 58 simulator = MockSimulator() 59 get_current_time, get_time_step, get_min_delay, get_max_delay, num_processes, rank = common.control.build_state_queries(simulator) 60 get_time_step() 61 assert_equal(simulator.state.accesses, ['dt']) 58 62 59 63 def test_min_delay(): 60 common.control.simulator = MockSimulator() 61 common.get_min_delay() 62 assert_equal(common.control.simulator.state.accesses, ['min_delay']) 64 simulator = MockSimulator() 65 get_current_time, get_time_step, get_min_delay, get_max_delay, num_processes, rank = common.control.build_state_queries(simulator) 66 get_min_delay() 67 assert_equal(simulator.state.accesses, ['min_delay']) 63 68 64 69 def test_max_delay(): 65 common.control.simulator = MockSimulator() 66 common.get_max_delay() 67 assert_equal(common.control.simulator.state.accesses, ['max_delay']) 70 simulator = MockSimulator() 71 get_current_time, get_time_step, get_min_delay, get_max_delay, num_processes, rank = common.control.build_state_queries(simulator) 72 get_max_delay() 73 assert_equal(simulator.state.accesses, ['max_delay']) 68 74 69 75 def test_num_processes(): 70 common.control.simulator = MockSimulator() 71 common.num_processes() 72 assert_equal(common.control.simulator.state.accesses, ['num_processes']) 76 simulator = MockSimulator() 77 get_current_time, get_time_step, get_min_delay, get_max_delay, num_processes, rank = common.control.build_state_queries(simulator) 78 num_processes() 79 assert_equal(simulator.state.accesses, ['num_processes']) 73 80 74 81 def test_rank(): 75 common.control.simulator = MockSimulator() 76 common.rank() 77 assert_equal(common.control.simulator.state.accesses, ['mpi_rank']) 82 simulator = MockSimulator() 83 get_current_time, get_time_step, get_min_delay, get_max_delay, num_processes, rank = common.control.build_state_queries(simulator) 84 rank() 85 assert_equal(simulator.state.accesses, ['mpi_rank']) -
trunk/test/unittests/test_utility_functions.py
r999 r1000 75 75 # need to check that a log message was created 76 76 assert_equal(4.3, common.check_weight(4.3, 'excitatory', is_conductance=None)) 77 78 def test_check_delay():79 assert_equal(common.check_delay(None), MIN_DELAY)80 assert_equal(common.check_delay(2*MIN_DELAY), 2*MIN_DELAY)81 assert_raises(errors.ConnectionError, common.check_delay, 0.5*MIN_DELAY)82 assert_raises(errors.ConnectionError, common.check_delay, 2.0*MAX_DELAY)
