def test_exceptions_regular_schedule(self): with self.assertRaisesRegex( RuntimeError, "tstart must a non-negative number, or None"): arb.regular_schedule(tstart=-1.) with self.assertRaisesRegex(RuntimeError, "dt must be a non-negative number"): arb.regular_schedule(dt=-0.1) with self.assertRaises(TypeError): arb.regular_schedule(dt=None) with self.assertRaises(TypeError): arb.regular_schedule(dt='dt') with self.assertRaisesRegex( RuntimeError, "tstop must a non-negative number, or None"): arb.regular_schedule(tstop='tstop')
def test_event_generator_regular_schedule(self): cm = arb.cell_local_label("tgt0") rs = arb.regular_schedule(2.0, 1., 100.) rg = arb.event_generator(cm, 3.14, rs) self.assertEqual(rg.target.label, "tgt0") self.assertEqual(rg.target.policy, arb.selection_policy.univalent) self.assertAlmostEqual(rg.weight, 3.14)
def test_event_generator_regular_schedule(self): cm = arb.cell_member(42, 3) rs = arb.regular_schedule(2.0, 1., 100.) rg = arb.event_generator(cm, 3.14, rs) self.assertEqual(rg.target.gid, 42) self.assertEqual(rg.target.index, 3) self.assertAlmostEqual(rg.weight, 3.14)
def event_generators(self, gid): sched_dt = 0.25 weight = 400 return [ A.event_generator((gid, 0), weight, A.regular_schedule(sched_dt)) for gid in range(0, self.num_cells()) ]
def run(dT, n_pairs=1, do_plots=False): recipe = single_recipe(dT, n_pairs) context = arbor.context() domains = arbor.partition_load_balance(recipe, context) sim = arbor.simulation(recipe, domains, context) sim.record(arbor.spike_recording.all) reg_sched = arbor.regular_schedule(0.1) handle_mem = sim.sample((0, 0), reg_sched) handle_g = sim.sample((0, 1), reg_sched) handle_apost = sim.sample((0, 2), reg_sched) handle_apre = sim.sample((0, 3), reg_sched) handle_weight_plastic = sim.sample((0, 4), reg_sched) sim.run(tfinal=600) if do_plots: print("Plotting detailed results ...") for (handle, var) in [(handle_mem, 'U'), (handle_g, "g"), (handle_apost, "apost"), (handle_apre, "apre"), (handle_weight_plastic, "weight_plastic")]: data, meta = sim.samples(handle)[0] df = pandas.DataFrame({'t/ms': data[:, 0], var: data[:, 1]}) seaborn.relplot(data=df, kind="line", x="t/ms", y=var, ci=None).savefig( 'single_cell_stdp_result_{}.svg'.format(var)) weight_plastic, meta = sim.samples(handle_weight_plastic)[0] return weight_plastic[:, 1][-1]
def test_set_tstart_dt_tstop_regular_schedule(self): rs = arb.regular_schedule() rs.tstart = 17. rs.dt = 0.5 rs.tstop = 42. self.assertEqual(rs.tstart, 17.) self.assertAlmostEqual(rs.dt, 0.5) self.assertEqual(rs.tstop, 42.)
def test_exceptions_explicit_schedule(self): with self.assertRaisesRegex(RuntimeError, "explicit time schedule cannot contain negative values"): arb.explicit_schedule([-1]) with self.assertRaises(TypeError): arb.explicit_schedule(['times']) with self.assertRaises(TypeError): arb.explicit_schedule([None]) with self.assertRaises(TypeError): arb.explicit_schedule([[1,2,3]]) with self.assertRaisesRegex(RuntimeError, "t0 must be a non-negative number"): rs = arb.regular_schedule() rs.events(-1., 1.) with self.assertRaisesRegex(RuntimeError, "t1 must be a non-negative number"): rs = arb.regular_schedule() rs.events(1., -1.)
def test_spike_clearing(self, art_spiking_sim): sim = art_spiking_sim sim.record(A.spike_recording.all) handle = sim.sample((3, 0), A.regular_schedule(0.1)) # baseline to test against Run in exactly the same stepping to make sure there are no rounding differences sim.run(3, 0.01) sim.run(5, 0.01) spikes = sim.spikes() times = spikes["time"].tolist() gids = spikes["source"]["gid"].tolist() data, meta = sim.samples(handle)[0] # reset the simulator sim.reset() # simulated with clearing the memory inbetween the steppings sim.run(3, 0.01) spikes = sim.spikes() times_t = spikes["time"].tolist() gids_t = spikes["source"]["gid"].tolist() data_t, meta_t = sim.samples(handle)[0] # clear the samplers memory sim.clear_samplers() # Check if the memory is cleared spikes = sim.spikes() self.assertEqual(0, len(spikes["time"].tolist())) self.assertEqual(0, len(spikes["source"]["gid"].tolist())) data_test, meta_test = sim.samples(handle)[0] self.assertEqual(0, data_test.size) # run the next part of the simulation sim.run(5, 0.01) spikes = sim.spikes() times_t.extend(spikes["time"].tolist()) gids_t.extend(spikes["source"]["gid"].tolist()) data_temp, meta_temp = sim.samples(handle)[0] data_t = np.concatenate((data_t, data_temp), 0) # check if results are the same self.assertEqual(gids, gids_t) self.assertEqual(times_t, times) self.assertEqual(list(data[:, 0]), list(data_t[:, 0])) self.assertEqual(list(data[:, 1]), list(data_t[:, 1]))
def test_events_regular_schedule(self): expected = [0, 0.25, 0.5, 0.75, 1.0] rs = arb.regular_schedule(tstart = 0., dt = 0.25, tstop = 1.25) self.assertEqual(expected, rs.events(0., 1.25)) self.assertEqual(expected, rs.events(0., 5.)) self.assertEqual([], rs.events(5., 10.))
return p, cell # get place_pwlin and cable_cell objects p, cell = make_cable_cell(morphology, clamp_location) # instantiate recipe with cell recipe = Recipe(cell) # instantiate simulation context = arbor.context() domains = arbor.partition_load_balance(recipe, context) sim = arbor.simulation(recipe, domains, context) # set up sampling on probes with sampling every 1 ms schedule = arbor.regular_schedule(1.) v_handle = sim.sample(recipe.vprobe_id, schedule, arbor.sampling_policy.exact) i_handle = sim.sample(recipe.iprobe_id, schedule, arbor.sampling_policy.exact) c_handle = sim.sample(recipe.cprobe_id, schedule, arbor.sampling_policy.exact) # run simulation for 500 ms of simulated activity and collect results. sim.run(tfinal=500) # extract time, V_m, I_m and I_c for each CV V_m_samples, V_m_meta = sim.samples(v_handle)[0] I_m_samples, I_m_meta = sim.samples(i_handle)[0] I_c_samples, I_c_meta = sim.samples(c_handle)[0] # drop recorded V_m values and corresponding metadata of # zero-sized CVs (branch-point potentials). # Here this is done as the V_m values are only used for visualization purposes
def test_event_generator_regular_schedule(self): rs = arb.regular_schedule(2.0, 1., 100.) rg = arb.event_generator(3, 3.14, rs) self.assertEqual(rg.target, 3) self.assertAlmostEqual(rg.weight, 3.14)
def test_tstart_dt_tstop_contor_regular_schedule(self): rs = arb.regular_schedule(10., 1., 20.) self.assertEqual(rs.tstart, 10.) self.assertEqual(rs.dt, 1.) self.assertEqual(rs.tstop, 20.)
def test_none_contor_regular_schedule(self): rs = arb.regular_schedule(tstart=None, tstop=None)
# create cell and set properties cell = arbor.cable_cell(morphology, labels, decor) # create single cell model model = arbor.single_cell_model(cell) # instantiate recipe with cell recipe = Recipe(cell) # instantiate simulation context = arbor.context() domains = arbor.partition_load_balance(recipe, context) sim = arbor.simulation(recipe, domains, context) # set up sampling on probes schedule = arbor.regular_schedule(0.1) v_handle = sim.sample(recipe.vprobe_id, schedule, arbor.sampling_policy.exact) i_handle = sim.sample(recipe.iprobe_id, schedule, arbor.sampling_policy.exact) c_handle = sim.sample(recipe.cprobe_id, schedule, arbor.sampling_policy.exact) # run simulation for 500 ms of simulated activity and collect results. sim.run(tfinal=500) # extract time, V_m and I_m for each compartment V_m_samples, V_m_meta = sim.samples(v_handle)[0] I_m_samples, I_m_meta = sim.samples(i_handle)[0] I_c_samples, I_c_meta = sim.samples(c_handle)[0] # drop recorded V_m values and corresponding meta data of # zero-sized CVs (branch-point potentials) inds = np.array([m.dist != m.prox for m in V_m_meta])
# set up membrane voltage probes equidistantly along the dendrites probes = [ arbor.cable_probe_membrane_voltage(f'(location 0 {r})') for r in np.linspace(0, 1, 11) ] recipe = Cable(probes, **vars(args)) # create a default execution context and a default domain decomposition context = arbor.context() domains = arbor.partition_load_balance(recipe, context) # configure the simulation and handles for the probes sim = arbor.simulation(recipe, domains, context) dt = 0.001 handles = [ sim.sample((0, i), arbor.regular_schedule(dt)) for i in range(len(probes)) ] # run the simulation for 30 ms sim.run(tfinal=30, dt=dt) # retrieve the sampled membrane voltages and convert to a pandas DataFrame data = [sim.samples(handle)[0][0] for handle in handles] data_dict = {str(i): d[:, 1] for i, d in enumerate(data)} data_dict["t"] = data[0][:, 0] df = pandas.DataFrame.from_dict(data_dict) # plot all probes and save to file for i in range(len(probes)):
def test_exceptions_regular_schedule(self): with self.assertRaisesRegex(RuntimeError, "tstart must be a non-negative number"): arb.regular_schedule(tstart=-1., dt=0.1) with self.assertRaisesRegex(RuntimeError, "dt must be a positive number"): arb.regular_schedule(dt=-0.1) with self.assertRaisesRegex(RuntimeError, "dt must be a positive number"): arb.regular_schedule(dt=0) with self.assertRaises(TypeError): arb.regular_schedule(dt=None) with self.assertRaises(TypeError): arb.regular_schedule(dt='dt') with self.assertRaisesRegex( RuntimeError, "tstop must be a non-negative number, or None"): arb.regular_schedule(tstart=0, dt=0.1, tstop='tstop') with self.assertRaisesRegex(RuntimeError, "t0 must be a non-negative number"): rs = arb.regular_schedule(0., 1., 10.) rs.events(-1, 0) with self.assertRaisesRegex(RuntimeError, "t1 must be a non-negative number"): rs = arb.regular_schedule(0., 1., 10.) rs.events(0, -10)
hints = dict([(arbor.cell_kind.cable, hint)]) decomp = arbor.partition_load_balance(recipe, context, hints) print(f'{decomp}') meters.checkpoint('load-balance', context) sim = arbor.simulation(recipe, decomp, context) sim.record(arbor.spike_recording.all) meters.checkpoint('simulation-init', context) # Attach a sampler to the voltage probe on cell 0. # Sample rate of 10 sample every ms. handles = [ sim.sample((gid, 0), arbor.regular_schedule(0.1)) for gid in range(ncells) ] tfinal = 100 sim.run(tfinal) print(f'{sim} finished') meters.checkpoint('simulation-run', context) # Print profiling information print(f'{arbor.meter_report(meters, context)}') # Print spike times print('spikes:') for sp in sim.spikes(): print(' ', sp)
context = arbor.context() domains = arbor.partition_load_balance(recipe, context) sim = arbor.simulation(recipe, domains, context) # Instruct the simulation to record the spikes sim.record(arbor.spike_recording.all) # Instruct the simulation to sample the probe (0, 0) # at a regular schedule with period = 0.1 ms (1000 Hz) voltage_probe_id = arbor.cell_member(0,0) ca_conc_probe_id = arbor.cell_member(0,1) volt_handle = sim.sample(voltage_probe_id, arbor.regular_schedule(0.1)) ca_conc_handle = sim.sample(ca_conc_probe_id, arbor.regular_schedule(0.1)) handles = [volt_handle, ca_conc_handle] sim.run(tfinal=500, dt=0.1) spikes = sim.spikes() # Print the number of spikes. print(len(spikes), 'spikes recorded:') # Print the spike times. for s in spikes: print(s)
arbor.mpi_init() comm = arbor.mpi_comm() print(comm) context = arbor.context(mpi=comm) print(context) # (13) Create a default domain decomposition and simulation decomp = arbor.partition_load_balance(recipe, context) sim = arbor.simulation(recipe, decomp, context) # (14) Set spike generators to record sim.record(arbor.spike_recording.all) # (15) Attach a sampler to the voltage probe on cell 0. Sample rate of 1 sample every ms. # Sampling period increased w.r.t network_ring.py to reduce amount of data handles = [sim.sample((gid, 0), arbor.regular_schedule(1)) for gid in range(ncells)] # (16) Run simulation sim.run(ncells*5) print('Simulation finished') # (17) Plot the recorded voltages over time. print('Storing results ...') df_list = [] for gid in range(ncells): if len(sim.samples(handles[gid])): samples, meta = sim.samples(handles[gid])[0] df_list.append(pandas.DataFrame({'t/ms': samples[:, 0], 'U/mV': samples[:, 1], 'Cell': f"cell {gid}"})) if len(df_list): df = pandas.concat(df_list,ignore_index=True)
# (5) Instantiate recipe with a voltage probe located on "midpoint". recipe = single_recipe(cell, [arbor.cable_probe_membrane_voltage('"midpoint"')]) # (6) Create a default execution context and a default domain decomposition. context = arbor.context() domains = arbor.partition_load_balance(recipe, context) # (7) Create and run simulation and set up 10 kHz (every 0.1 ms) sampling on the probe. # The probe is located on cell 0, and is the 0th probe on that cell, thus has probe_id (0, 0). sim = arbor.simulation(recipe, domains, context) sim.record(arbor.spike_recording.all) handle = sim.sample((0, 0), arbor.regular_schedule(0.1)) sim.run(tfinal=30) # (8) Collect results. spikes = sim.spikes() data, meta = sim.samples(handle)[0] if len(spikes) > 0: print('{} spikes:'.format(len(spikes))) for t in spikes['time']: print('{:3.3f}'.format(t)) else: print('no spikes') print("Plotting results ...")
context = arbor.context() # (5) Create a domain decomposition domains = arbor.partition_load_balance(recipe, context) # (6) Create a simulation sim = arbor.simulation(recipe, domains, context) # Instruct the simulation to record the spikes and sample the probe sim.record(arbor.spike_recording.all) probe_id = arbor.cell_member(0, 0) handle = sim.sample(probe_id, arbor.regular_schedule(0.02)) # (7) Run the simulation sim.run(tfinal=100, dt=0.025) # (8) Print or display the results spikes = sim.spikes() print(len(spikes), 'spikes recorded:') for s in spikes: print(s) data = [] meta = [] for d, m in sim.samples(handle):
def test_none_ctor_regular_schedule(self): rs = arb.regular_schedule(tstart=0, dt=0.1, tstop=None) self.assertEqual(rs.dt, 0.1)