def simulation(dt, N, output_n): start_time = time.time() dur = 0.01 steps = int(np.round(dur / dt)) G = create_graph(N) print("Creating graph completed in {} seconds.".format(time.time() - start_time)) start_time = time.time() #comp_dict, conns = LPU.graph_to_dicts(G, remove_edge_id=False) fl_input_processor = StepInputProcessor( 'I', ['neuron_{}'.format(i) for i in range(N)], 20.0, 0.0, dur) #fl_output_processor = [FileOutputProcessor([('V', None), ('g', ['synapse_neuron_{}_to_neuron_1'.format(i) for i in range(N)])],# ('spike_state', None), ('g', None), ('E', None)], # 'neurodriver_output_{}.h5'.format(output_n), sample_interval=10, cache_length=2000)] fl_output_processor = [] # temporarily suppress generating output #fl_output_processor = [OutputRecorder([('spike_state', None), ('V', None), ('g', None), ('E', None)], dur, dt, sample_interval = 1)] lpu = LPU(dt, 'obj', G, device=args.gpu_dev, id='ge', input_processors=[fl_input_processor], output_processors=fl_output_processor, debug=args.debug, manager=False, print_timing=False, time_sync=False, extra_comps=[]) print("Instantiating LPU completed in {} seconds.".format(time.time() - start_time)) start_time1 = time.time() # LPU.run includes pre_run, run_steps and post_run lpu.run(steps=steps) execution_time = time.time() - start_time1 compile_and_execute_time = time.time() - start_time print("LPUs Compilation and Execution Completed in {} seconds.".format( compile_and_execute_time)) return compile_and_execute_time, execution_time
lpu = LPU(dt, 'obj', { 'graph': G, 'kwargs': { 'class_key': 'model' } }, device=0, id='test', input_processors=[input_processor], output_processors=[output_processor], debug=True, manager=False, print_timing=False, extra_comps=[ArrayInputProcessor]) lpu.run(steps=steps) s = np.zeros(steps, np.double) t = np.arange(0, dur, dt) for tk in spike_times: s += (scale / (ar - ad) * (np.exp(-ad * (t - tk) * 1000) - np.exp(-ar * (t - tk) * 1000))) * (t > tk) if np.abs(output_processor.output['g']['data'].reshape(-1) - s).max() < 1e-12: print('Test Passed') else: print('Test Failed')