def test_poisson(self, duration=10 * un.s, rate=100 * un.Hz, print_comparisons=False, dt=0.001, simulators=['nest', 'neuron'], build_mode='force', **kwargs): # @UnusedVariable @IgnorePep8 nineml_model = ninemlcatalog.load('input/Poisson', 'Poisson') build_args = {'neuron': {'build_mode': build_mode, 'external_currents': ['iSyn']}, 'nest': {'build_mode': build_mode}} initial_states = {'t_next': 0.0 * un.ms} for sim_name in simulators: meta_class = cell_metaclasses[sim_name] # Build celltype celltype = meta_class( nineml_model, name=nineml_model.name, **build_args[sim_name]) # Initialise simulator if sim_name == 'neuron': # Run NEURON simulation import neuron simulatorNEURON.clear(rng_seed=NEURON_RNG_SEED) neuron.h.dt = dt elif sim_name == 'nest': # Run NEST simulation # import nest # nest.ResetKernel() # nest.ResetNetwork() # nest.SetKernelStatus({'resolution': dt}) simulatorNEST.clear(rng_seed=NEST_RNG_SEED, dt=dt) else: assert False # Create and initialise cell cell = celltype(rate=rate) cell.record('spike_output') cell.set_state(initial_states) # Run simulation if sim_name == 'neuron': simulatorNEURON.run(duration.in_units(un.ms)) elif sim_name == 'nest': simulatorNEST.run(duration.in_units(un.ms)) else: assert False # Get recording spikes = cell.recording('spike_output') # Calculate the rate of the modelled process recorded_rate = pq.Quantity( len(spikes) / (spikes.t_stop - spikes.t_start), 'Hz') ref_rate = pq.Quantity(UnitHandlerNEST.to_pq_quantity(rate), 'Hz') rate_difference = abs(ref_rate - recorded_rate) if print_comparisons: print "Reference rate: {}".format(ref_rate) print "{} recorded rate: {}".format(sim_name, recorded_rate) print "{} difference: {}".format(sim_name, rate_difference) self.assertLess( rate_difference, 1.75 * pq.Hz, ("Recorded rate of {} poisson generator ({}) did not match " "desired ({}) within {}: difference {}".format( sim_name, recorded_rate, ref_rate, 1.75 * pq.Hz, recorded_rate - ref_rate)))
def simulate(self, duration, nest_rng_seed=12345, neuron_rng_seed=54321): """ Run and the simulation """ if self.simulate_nest: nest.ResetKernel() simulatorNEST.clear(rng_seed=nest_rng_seed, dt=self.dt) simulation_controller.set_delays(self.min_delay, self.max_delay, self.device_delay) if self.simulate_neuron: simulatorNEURON.clear(rng_seed=neuron_rng_seed) neuron.h.dt = self.dt for simulator in self.simulators: self._create_9ML(self.nineml_model, self.properties, simulator) if self.nest_ref is not None: self._create_NEST(self.nest_ref) if self.neuron_ref is not None: self._create_NEURON(self.neuron_ref) if self.simulate_nest: simulatorNEST.run(duration) if self.simulate_neuron: simulatorNEURON.run(duration) return self # return self so it can be chained with subsequent methods