def main_example(tvb_sim_model, connectivity_zip=CONFIGURED.DEFAULT_CONNECTIVITY_ZIP, dt=0.1, noise_strength=0.001, simulation_length=100.0, config=CONFIGURED): plotter = Plotter(config) # --------------------------------------1. Load TVB connectivity---------------------------------------------------- connectivity = Connectivity.from_file(connectivity_zip) connectivity.configure() plotter.plot_tvb_connectivity(connectivity) # ----------------------2. Define a TVB simulator (model, integrator, monitors...)---------------------------------- # Create a TVB simulator and set all desired inputs # (connectivity, model, surface, stimuli etc) # We choose all defaults in this example simulator = Simulator() simulator.integrator = HeunStochastic(dt=dt) simulator.integrator.noise.nsig = np.array(ensure_list(noise_strength)) simulator.model = tvb_sim_model simulator.connectivity = connectivity mon_raw = Raw(period=simulator.integrator.dt) simulator.monitors = (mon_raw, ) # -----------------------------------3. Simulate and gather results------------------------------------------------- # Configure the simulator with the TVB-NEST interface... # simulator.configure(tvb_nest_interface=tvb_nest_model) simulator.configure() # ...and simulate! t_start = time.time() results = simulator.run(simulation_length=simulation_length) print("\nSimulated in %f secs!" % (time.time() - t_start)) # -------------------------------------------6. Plot results-------------------------------------------------------- plot_results(results, simulator, None, "State Variables", simulator.model.variables_of_interest, plotter) return connectivity, results
from tvb_nest.interfaces.builders.red_ww_exc_io_inh_i import RedWWexcIOinhIBuilder from tvb_nest.simulator_nest.models_builders.red_ww_exc_io_inh_i import RedWWExcIOInhIBuilder from tvb_nest.simulator_tvb.model_reduced_wong_wang_exc_io_inh_i import ReducedWongWangExcIOInhI from tvb_nest.plot.plotter import Plotter from tvb_scripts.time_series.model import TimeSeriesRegion from tvb.datatypes.connectivity import Connectivity from tvb.simulator.monitors import Raw # , Bold # , EEG if __name__ == "__main__": config = CONFIGURED plotter = Plotter(config) connectivity = Connectivity.from_file(config.DEFAULT_CONNECTIVITY_ZIP) connectivity.configure() plotter.plot_tvb_connectivity(connectivity) # ----------------------2. Define a TVB simulator (model, integrator, monitors...)----------------------------------- # Create a TVB simulator and set all desired inputs # (connectivity, model, surface, stimuli etc) # We choose all defaults in this example simulator = Simulator() simulator.model = ReducedWongWangExcIOInhI() def boundary_fun(state): state[state < 0] = 0.0 state[state > 1] = 1.0 return state # Synaptic gating state variables S_e, S_i need to be in the interval [0, 1]
def main_example(tvb_sim_model, nest_model_builder, tvb_nest_builder, nest_nodes_ids, nest_populations_order=100, connectivity=None, connectivity_zip=CONFIGURED.DEFAULT_CONNECTIVITY_ZIP, simulation_length=100.0, tvb_state_variable_type_label="Synaptic Gating Variable", delays=True, dt=0.1, noise_strength=0.001, exclusive_nodes=False, config=CONFIGURED): plotter = Plotter(config) # --------------------------------------1. Load TVB connectivity---------------------------------------------------- if connectivity is None: connectivity = Connectivity.from_file(connectivity_zip) connectivity.configure() plotter.plot_tvb_connectivity(connectivity) if not delays: connectivity.tract_lengths /= 100000.0 connectivity.configure() plotter.base.plot_regions2regions(connectivity.delays, connectivity.region_labels, 111, "Delays") plotter.base._save_figure(figure_name="Delays") # ----------------------2. Define a TVB simulator (model, integrator, monitors...)---------------------------------- # Create a TVB simulator and set all desired inputs # (connectivity, model, surface, stimuli etc) # We choose all defaults in this example simulator = Simulator() simulator.integrator.dt = dt simulator.integrator.noise.nsig = np.array([noise_strength]) simulator.model = tvb_sim_model simulator.connectivity = connectivity mon_raw = Raw(period=simulator.integrator.dt) simulator.monitors = (mon_raw, ) # ------3. Build the NEST network model (fine-scale regions' nodes, stimulation devices, spike_detectors etc)------- print("Building NEST network...") tic = time.time() # Build a NEST network model with the corresponding builder # Using all default parameters for this example nest_model_builder = nest_model_builder(simulator, nest_nodes_ids, config=config) # Common order of neurons' number per population: nest_model_builder.populations_order = nest_populations_order nest_network = nest_model_builder.build_nest_network() print("Done! in %f min" % ((time.time() - tic) / 60)) # -----------------------------------4. Build the TVB-NEST interface model ----------------------------------------- print("Building TVB-NEST interface...") tic = time.time() # Build a TVB-NEST interface with all the appropriate connections between the # TVB and NEST modelled regions # Using all default parameters for this example tvb_nest_builder = tvb_nest_builder(simulator, nest_network, nest_nodes_ids, exclusive_nodes) tvb_nest_model = tvb_nest_builder.build_interface() print("Done! in %f min" % ((time.time() - tic) / 60)) # -----------------------------------5. Simulate and gather results------------------------------------------------- # Configure the simulator with the TVB-NEST interface... simulator.configure(tvb_nest_interface=tvb_nest_model) # ...and simulate! t_start = time.time() results = simulator.run(simulation_length=simulation_length) # Integrate NEST one more NEST time step so that multimeters get the last time point # unless you plan to continue simulation later simulator.run_spiking_simulator( simulator.tvb_nest_interface.nest_instance.GetKernelStatus( "resolution")) # Clean-up NEST simulation if simulator.run_spiking_simulator == simulator.tvb_nest_interface.nest_instance.Run: simulator.tvb_nest_interface.nest_instance.Cleanup() print("\nSimulated in %f secs!" % (time.time() - t_start)) # -------------------------------------------6. Plot results-------------------------------------------------------- plot_results(results, simulator, tvb_nest_model, tvb_state_variable_type_label, simulator.model.variables_of_interest, plotter) return connectivity, results