def test_progressreporting(): ''' Tests whether calling for progress reporting works -- the actual output is not checked, only that something is printed to the correct output. ''' real_stdout = sys.stdout real_stderr = sys.stderr G = NeuronGroup(1, model=LazyStateUpdater()) net = Network(G) # Tests various ways to get a (textual) progress report string_output = StringIO() sys.stdout = string_output net.run(defaultclock.dt, report='text') assert(len(string_output.getvalue()) > 0) net.run(defaultclock.dt, report='print') string_output = StringIO() sys.stdout = string_output net.run(defaultclock.dt, report='stdout') assert(len(string_output.getvalue()) > 0) string_output = StringIO() sys.stdout = string_output string_err = StringIO() sys.stderr = string_err net.run(defaultclock.dt, report='stderr') assert(len(string_output.getvalue()) == 0 and len(string_err.getvalue()) > 0) net.run(defaultclock.dt, report=string_output) assert(len(string_output.getvalue()) > 0) net.run(defaultclock.dt, report='text', report_period=5*second) #explicitely construct a ProgressReporter string_output = StringIO() sys.stdout = string_output reporter = ProgressReporter('text') reporter.start() net.run(defaultclock.dt, report=reporter) assert(len(string_output.getvalue()) > 0) string_output = StringIO() sys.stdout = string_output string_err = StringIO() sys.stderr = string_err reporter = ProgressReporter('stderr') net.run(defaultclock.dt, report=reporter) assert(len(string_output.getvalue()) == 0 and len(string_err.getvalue()) > 0) # use MagicNetwork implicitly string_output = StringIO() sys.stdout = string_output run(defaultclock.dt, report='text', report_period=5*second) assert(len(string_output.getvalue()) > 0) sys.stdout = real_stdout sys.stderr = real_stderr
def test_progressreporting(): ''' Tests whether calling for progress reporting works -- the actual output is not checked, only that something is printed to the correct output. ''' real_stdout = sys.stdout real_stderr = sys.stderr G = NeuronGroup(1, model=LazyStateUpdater()) net = Network(G) # Tests various ways to get a (textual) progress report string_output = StringIO() sys.stdout = string_output net.run(defaultclock.dt, report='text') assert (len(string_output.getvalue()) > 0) net.run(defaultclock.dt, report='print') string_output = StringIO() sys.stdout = string_output net.run(defaultclock.dt, report='stdout') assert (len(string_output.getvalue()) > 0) string_output = StringIO() sys.stdout = string_output string_err = StringIO() sys.stderr = string_err net.run(defaultclock.dt, report='stderr') assert (len(string_output.getvalue()) == 0 and len(string_err.getvalue()) > 0) net.run(defaultclock.dt, report=string_output) assert (len(string_output.getvalue()) > 0) net.run(defaultclock.dt, report='text', report_period=5 * second) #explicitely construct a ProgressReporter string_output = StringIO() sys.stdout = string_output reporter = ProgressReporter('text') reporter.start() net.run(defaultclock.dt, report=reporter) assert (len(string_output.getvalue()) > 0) string_output = StringIO() sys.stdout = string_output string_err = StringIO() sys.stderr = string_err reporter = ProgressReporter('stderr') net.run(defaultclock.dt, report=reporter) assert (len(string_output.getvalue()) == 0 and len(string_err.getvalue()) > 0) # use MagicNetwork implicitly string_output = StringIO() sys.stdout = string_output run(defaultclock.dt, report='text', report_period=5 * second) assert (len(string_output.getvalue()) > 0) sys.stdout = real_stdout sys.stderr = real_stderr
synapses.connect(G_pre, G_post, rand(len(G_pre), len(G_post)) * gmax) stdp = ExponentialSTDP(synapses, tau_pre, tau_post, dA_pre, dA_post, wmax=gmax) M_pre = SpikeMonitor(G_pre) M_post = SpikeMonitor(G_post) MV_post = StateMonitor(G_post, 'V', record=True) G_post.V = Vr net = MagicNetwork() weights_before = array(synapses.W).copy() t_start = time.time() reporter = ProgressReporter('stderr') for i in range(repeats): reporter.equal_subtask(i, repeats) reinit_default_clock() # Reinitialise these by hand because we don't want to reinitialise the # spike and state monitors PG_start.reinit() PG_end.reinit() PG_all.reinit() G_pre.reinit() G_post.reinit() patgroup.reinit() net.run(total_duration, report=reporter) t_end = time.time() weights_after = array(synapses.W).copy()
synapses.connect(G_pre, G_post, rand(len(G_pre), len(G_post))*gmax) stdp = ExponentialSTDP(synapses, tau_pre, tau_post, dA_pre, dA_post, wmax=gmax) M_pre = SpikeMonitor(G_pre) M_post = SpikeMonitor(G_post) MV_post = StateMonitor(G_post, 'V', record=True) G_post.V = Vr net = MagicNetwork() weights_before = array(synapses.W).copy() t_start = time.time() reporter = ProgressReporter('stderr') for i in range(repeats): reporter.equal_subtask(i, repeats) reinit_default_clock() # Reinitialise these by hand because we don't want to reinitialise the # spike and state monitors PG_start.reinit() PG_end.reinit() PG_all.reinit() G_pre.reinit() G_post.reinit() patgroup.reinit() net.run(total_duration, report=reporter) t_end = time.time() weights_after = array(synapses.W).copy()