AllenInstitute / bmtk

Brain Modeling Toolkit
https://alleninstitute.github.io/bmtk/
BSD 3-Clause "New" or "Revised" License
272 stars 88 forks source link

Tutorial 4: raster plot error #273

Closed mitometa closed 1 year ago

mitometa commented 1 year ago

Running the simulation is ok, but failed when analyzing results. Here is the error massage:

---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
Cell In [1], line 3
      1 from bmtk.analyzer.spike_trains import plot_raster, plot_rates_boxplot
----> 3 plot_raster(config_file='sim_ch04/config.json', group_by='pop_name')

File /usr/local/miniconda3/envs/brain/lib/python3.9/site-packages/bmtk/analyzer/spike_trains.py:189, in plot_raster(config_file, population, with_histogram, times, title, show, save_as, group_by, group_excludes, spikes_file, nodes_file, node_types_file, plt_style)
    148 """Create a raster plot (plus optional histogram) from the results of the simulation.
    149 
    150 Will using the SONATA simulation configs "output" section to locate where the spike-trains file was created and
   (...)
    186 :return: matplotlib figure.Figure object
    187 """
    188 plot_fnc = partial(plotting.plot_raster, with_histogram=with_histogram, plt_style=plt_style)
--> 189 return _plot_helper(
    190     plot_fnc,
    191     config_file=config_file, population=population, times=times, title=title, show=show, save_as=save_as,
    192     group_by=group_by, group_excludes=group_excludes,
    193     spikes_file=spikes_file, nodes_file=nodes_file, node_types_file=node_types_file
    194 )

File /usr/local/miniconda3/envs/brain/lib/python3.9/site-packages/bmtk/analyzer/spike_trains.py:101, in _plot_helper(plot_fnc, config_file, population, times, title, show, save_as, group_by, group_excludes, spikes_file, nodes_file, node_types_file)
     97 def _plot_helper(plot_fnc, config_file=None, population=None, times=None, title=None, show=True, save_as=None,
     98                  group_by=None, group_excludes=None,
     99                  spikes_file=None, nodes_file=None, node_types_file=None):
    100     sonata_config = SonataConfig.from_json(config_file) if config_file else None
--> 101     pop, spike_trains = _find_spikes(config_file=config_file, spikes_file=spikes_file, population=population)
    103     # Create the title
    104     title = title if title is not None else "Nodes in network '{}'".format(pop)

File /usr/local/miniconda3/envs/brain/lib/python3.9/site-packages/bmtk/analyzer/spike_trains.py:78, in _find_spikes(spikes_file, config_file, population)
     76     raise ValueError('Spikes file {} contains more than one node population.'.format(spikes_f))
     77 else:
---> 78     return spikes_obj.populations[0], spikes_obj

IndexError: list index out of range
xpliu16 commented 1 year ago

Hi, can you verify that the simulation produced spike outputs - e.g., the size of the spikes.h5 file is not really small, or open it with HDFView or similar tool, or crank up any of the inputs in the network to try to drive spiking?

If that's the issue, I will try to create a more informative error for this situation.

mitometa commented 1 year ago

Thanks for the point. The spikes.h5 file is small with <HDF5 group "/spikes" (0 members)>, while the V_report.h5 is about 25M. Therefore, the simulation failed in the ubuntu system with

nest-simulator            2.20.0 
python                    3.9.13
neuron                    8.0.2
bmtk.__version__         '1.0.7'
mitometa commented 1 year ago

log.txt is not informative for the failure:

2022-11-25 21:54:48,844 [INFO] Created log file
2022-11-25 21:54:48,919 [INFO] Building cells.
2022-11-25 21:54:54,834 [INFO] Building recurrent connections
2022-11-25 21:55:10,172 [INFO] Running simulation for 3000.000 ms with the time step 0.100 ms
2022-11-25 21:55:10,175 [INFO] Starting timestep: 0 at t_sim: 0.000 ms
2022-11-25 21:55:10,176 [INFO] Block save every 5000 steps
2022-11-25 21:55:36,787 [INFO]     step:5000 t_sim:500.00 ms
2022-11-25 21:56:02,980 [INFO]     step:10000 t_sim:1000.00 ms
2022-11-25 21:56:29,684 [INFO]     step:15000 t_sim:1500.00 ms
2022-11-25 21:56:55,913 [INFO]     step:20000 t_sim:2000.00 ms
2022-11-25 21:57:22,105 [INFO]     step:25000 t_sim:2500.00 ms
2022-11-25 21:57:48,258 [INFO]     step:30000 t_sim:3000.00 ms
2022-11-25 21:57:48,276 [INFO] Simulation completed in 2.0 minutes, 38.1 seconds
xpliu16 commented 1 year ago

The fact that you have a membrane report and a log that shows completion suggests the simulation did complete, but that there were simply no triggered spikes. What are you using as inputs? Have you tried increasing the excitatory synaptic weight? You can increase the feedforward weights if you have a spike file or filternet driving the responses. Or you can very gently increase the recurrent excitatory weights (it can easily get very excitable this way). If you have inhibition, try notching down the inhibition. Lastly, you can check that the spike threshold in the simulation configs are reasonable. We would need to know more about the simulation and inputs to be able to help in any more detail.

mitometa commented 1 year ago

Thanks, I will double check those parameters since I only tried the simulation so far by simply following the tutortial 4.

xpliu16 commented 1 year ago

I assume you're running it from the .ipynb notebook? First off, just to doublecheck, did you do the part of the tutorial excerpted below? This tutorial requires you to download some files and edit the configuration file in a text editor. Unfortunately, you can't just execute the blocks all the way through the first time around.

lgn input
We need to provide our LGN external network cells with spike-trains so they can activate our recurrent network. Previously we showed how to do this by generating csv files. We can also use NWB files, which are a common format for saving electrophysiological data in neuroscience.

We can use any NWB file generated experimentally or computationally, but for this example we will use a preexsting one. First download the file:

$ wget https://github.com/AllenInstitute/bmtk/blob/develop/examples/spikes_inputs/lgn_spikes.h5?raw=true -O lgn_spikes.h5
or copy from [here](https://github.com/AllenInstitute/bmtk/tree/develop/examples/spikes_inputs/lgn_spikes.nwb).

Then we must edit the simulation_config.json file to tell the simulator to find the nwb file and which network to associate it with.

{
  "inputs": {
    "LGN_spikes": {
      "input_type": "spikes",
      "module": "sonata",
      "input_file": "$BASE_DIR/lgn_spikes.h5",
      "node_set": "LGN"
    }
  }
}
mitometa commented 1 year ago

Yes, that is my fault. The tutorial 4 runs well. Thanks a lot!

xpliu16 commented 1 year ago

Great. I will try editing the tutorial to make this more clear rather than buried in the text.