pat12['/a/out/spike0', '/b/in/spike0'] = 1 pat12['/a/out/spike1', '/b/in/spike1'] = 1 pat12['/b/out/spike0', '/a/in/spike0'] = 1 pat12['/b/out/spike1', '/a/in/spike1'] = 1 man.connect(m1, m2, pat12, 0, 1) # To set the emulation to exit after executing a fixed number of steps, # start it as follows and remove the sleep statement: man.start(steps=steps) # man.start() # time.sleep(2) man.stop() return m1 # Set up logging: logger = setup_logger(screen=True, multiline=True) steps = 100 # Emulation 1 start_time = time.time() size = 2 m1 = emulate(size, steps) print('Simulation of size {} complete: Duration {} seconds'.format( size, time.time() - start_time)) # Emulation 2 # start_time = time.time() # size = 100 # emulate(size, steps) # print('Simulation of size {} complete: Duration {} seconds'.format( # size, time.time() - start_time)) # logger.info('all done')
l.log_error(str(e)) raise finally: #Closing the temp file closes and deletes it temp.close() #Return the output return str(out) #Basic sanity checks if __name__ == "__main__": from tools.logging import setup_logger setup_logger(screen=True, file_name='neurokernel.log', multiline=True) def _test_success(): print("HELLO WORLD") def _test_fail(): open("RANDOM_FILE", "r").read() print("This should succeed:") print(mpi_run(_test_success)) print("This should also succeed:") code = "\ndef func():" code += "\n print(\"HELLO AGAIN\")" print(mpi_run(code))
""" def run_step(self): super(MyModule, self).run_step() # Do something with input data: in_ports = self.interface.in_ports().to_tuples() self.log_info('input port data: '+str(self.pm[in_ports])) # Output random data: out_ports = self.interface.out_ports().to_tuples() self.pm[out_ports] = np.random.rand(len(out_ports)) self.log_info('output port data: '+str(self.pm[out_ports])) # Set up logging: logger = setup_logger(screen=True) # Set up emulation: man = BaseManager(get_random_port(), get_random_port(), get_random_port()) man.add_brok() m1_int_sel = '/a[0:5]'; m1_int_sel_in = '/a[0:2]'; m1_int_sel_out = '/a[2:5]' m2_int_sel = '/b[0:5]'; m2_int_sel_in = '/b[0:3]'; m2_int_sel_out = '/b[3:5]' m3_int_sel = '/c[0:4]'; m3_int_sel_in = '/c[0:2]'; m3_int_sel_out = '/c[2:4]' m1 = MyModule(m1_int_sel, m1_int_sel_in, m1_int_sel_out, np.zeros(5, dtype=np.float), ['interface', 'io', 'type'], man.port_data, man.port_ctrl, man.port_time, 'm1 ', False, True) man.add_mod(m1)
self.intercomm.isend(['stop'], dest, self._ctrl_tag) def quit(self): """ Tell the workers to quit. """ self.log_info('sending quit message') for dest in xrange(len(self)): self.intercomm.isend(['quit'], dest, self._ctrl_tag) if __name__ == '__main__': import neurokernel.mpi_relaunch import time setup_logger(screen=True, file_name='neurokernel.log', mpi_comm=MPI.COMM_WORLD, multiline=True) # Define a class whose constructor takes arguments so as to test # instantiation of the class by the manager: class MyWorker(Worker): def __init__(self, x, y, z=None, routing_table=None): super(MyWorker, self).__init__() name = MPI.Get_processor_name() self.log_info('I am process %d of %d on %s.' % (self.rank, self.size, name)) self.log_info('init args: %s, %s, %s' % (x, y, z)) man = WorkerManager() man.add(target=MyWorker, x=1, y=2, z=3) man.add(MyWorker, 3, 4, 5) man.add(MyWorker, 6, 7, 8)