.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/sonata_example/sonata_network.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_sonata_example_sonata_network.py: NEST SONATA network ------------------- .. only:: html ---- Run this example as a Jupyter notebook: .. card:: :width: 25% :margin: 2 :text-align: center :link: https://lab.ebrains.eu/hub/user-redirect/git-pull?repo=https%3A%2F%2Fgithub.com%2Fnest%2Fnest-simulator-examples&urlpath=lab%2Ftree%2Fnest-simulator-examples%2Fnotebooks%2Fnotebooks%2Fsonata_example%2Fsonata_network.ipynb&branch=main :link-alt: JupyterHub service .. image:: https://nest-simulator.org/TryItOnEBRAINS.png .. grid:: 1 1 1 1 :padding: 0 0 2 0 .. grid-item:: :class: sd-text-muted :margin: 0 0 3 0 :padding: 0 0 3 0 :columns: 4 See :ref:`our guide ` for more information and troubleshooting. ---- This script builds and simulates a network of point neurons represented by the SONATA format [1]_. The network model consists of 300 internal nodes (explicitly simulated) and 100 external nodes (only provide inputs to the simulated system). The SONATA files can be found in the `pynest/examples/sonata_example/300_pointneurons `_ directory. See the :ref:`nest_sonata` for details on the NEST support of the SONATA format. References ~~~~~~~~~~ .. [1] Dai K, Hernando J, Billeh YN, Gratiy SL, Planas J, et al. (2020). The SONATA data format for efficient description of large-scale network models. PLOS Computational Biology 16(2): e1007696. https://doi.org/10.1371/journal.pcbi.1007696 .. GENERATED FROM PYTHON SOURCE LINES 46-47 Import all necessary packages for simulation, analysis and plotting. .. GENERATED FROM PYTHON SOURCE LINES 47-56 .. code-block:: Python from pathlib import Path import matplotlib.pyplot as plt import nest nest.set_verbosity("M_ERROR") nest.ResetKernel() .. GENERATED FROM PYTHON SOURCE LINES 57-61 Specify the path to the SONATA .json configuration file(s). The `300_pointneurons` model has two configuration files: One circuit and one simulation configuration file. We locate the configuration files relative to this example script. .. GENERATED FROM PYTHON SOURCE LINES 61-67 .. code-block:: Python base_path = Path(__file__).resolve().parent sonata_path = base_path / "300_pointneurons" net_config = sonata_path / "circuit_config.json" sim_config = sonata_path / "simulation_config.json" .. GENERATED FROM PYTHON SOURCE LINES 68-74 SONATA networks are built and simulated through the :py:class:`.SonataNetwork` class. SONATA config files are passed to the class constructor. Passing a second config is optional and only relevant if the network and simulation configurations are specified separately. First, we instantiate the class. .. GENERATED FROM PYTHON SOURCE LINES 74-77 .. code-block:: Python sonata_net = nest.SonataNetwork(net_config, sim_config=sim_config) .. GENERATED FROM PYTHON SOURCE LINES 78-95 Next, we build the network. The network nodes are created by the membership function :py:meth:`~.SonataNetwork.Create` and their connections by the membership function :py:meth:`~.SonataNetwork.Connect`. For convenience, we only need to call the membership function :py:meth:`~.SonataNetwork.BuildNetwork` which internally calls :py:meth:`~.SonataNetwork.Create` and :py:meth:`~.SonataNetwork.Connect` For large networks, the edges HDF5 files might not fit into memory in their entirety. In the NEST kernel, the edges HDF5 datasets are therefore read sequentially in blocks of contiguous hyperslabs. The hyperslab size is modifiable through the keyword argument ``hdf5_hyperslab_size``. This allows the user to control the balance between the number of read operations and memory overhead. :py:meth:`~.SonataNetwork.BuildNetwork()` returns a dictionary containing the created :py:class:`.NodeCollection`\s. The population names are the dictionary keys. .. GENERATED FROM PYTHON SOURCE LINES 95-98 .. code-block:: Python node_collections = sonata_net.BuildNetwork(hdf5_hyperslab_size=2**20) .. GENERATED FROM PYTHON SOURCE LINES 99-101 We can now verify whether the built network has the expected number of nodes and connections. .. GENERATED FROM PYTHON SOURCE LINES 101-106 .. code-block:: Python print(f'Network built from SONATA specifications in directory "{sonata_path.name}"') print(f" Number of nodes : {nest.network_size}") print(f" Number of connections: {nest.num_connections}") .. GENERATED FROM PYTHON SOURCE LINES 107-117 NEST does not currently support SONATA Spike Train Reports or utilize other ``output`` components in the SONATA config. This means that recording devices must be created and connected manually. Here, we create a ``spike_recorder`` to record the spiking events of neurons. We wish to connect the spike recorder to the internal population and only record from a subset of the neurons in the population. We extract the internal population's :py:class:`.NodeCollection` from the ``node_collections`` dictionary by using the internal population's name. Then we slice the :py:class:`.NodeCollection` with a list specifying the node ids of the neurons we wish to record from. .. GENERATED FROM PYTHON SOURCE LINES 117-123 .. code-block:: Python s_rec = nest.Create("spike_recorder") pop_name = "internal" record_node_ids = [1, 80, 160, 240, 270] nest.Connect(node_collections[pop_name][record_node_ids], s_rec) .. GENERATED FROM PYTHON SOURCE LINES 124-127 Finally, we call the membership function :py:meth:`~.SonataNetwork.Simulate` to simulate the network. Note that the simulation time and resolution are expected to be provided in the SONATA config. .. GENERATED FROM PYTHON SOURCE LINES 127-130 .. code-block:: Python sonata_net.Simulate() .. GENERATED FROM PYTHON SOURCE LINES 131-133 After the simulation has finished, we can obtain the data recorded by the spike recorder for further analysis. .. GENERATED FROM PYTHON SOURCE LINES 133-136 .. code-block:: Python nest.raster_plot.from_device(s_rec) plt.show() .. _sphx_glr_download_auto_examples_sonata_example_sonata_network.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: sonata_network.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: sonata_network.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_