.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/csa_example.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_csa_example.py: Using CSA for connection setup ------------------------------ .. 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%2Fcsa_example.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 example sets up a simple network in NEST using the Connection Set Algebra (CSA) instead of using the built-in connection routines. Using the CSA requires NEST to be compiled with support for libneurosim. For details, see [1]_. See Also ~~~~~~~~ :doc:`csa_spatial_example` References ~~~~~~~~~~ .. [1] Djurfeldt M, Davison AP and Eppler JM (2014). Efficient generation of connectivity in neuronal networks from simulator-independent descriptions, Front. Neuroinform. http://dx.doi.org/10.3389/fninf.2014.00043 .. GENERATED FROM PYTHON SOURCE LINES 48-49 First, we import all necessary modules for simulation and plotting. .. GENERATED FROM PYTHON SOURCE LINES 49-54 .. code-block:: Python import matplotlib.pyplot as plt import nest from nest import visualization, voltage_trace .. GENERATED FROM PYTHON SOURCE LINES 55-57 Next, we check for the availability of the CSA Python module. If it does not import, we exit with an error message. .. GENERATED FROM PYTHON SOURCE LINES 57-73 .. code-block:: Python try: import csa haveCSA = True except ImportError: print( "This example requires CSA to be installed in order to run.\n" + "Please make sure you compiled NEST using\n" + " -Dwith-libneurosim=[OFF|ON|]\n" + "and CSA and libneurosim are available." ) import sys sys.exit(1) .. GENERATED FROM PYTHON SOURCE LINES 74-77 To set up the connectivity, we create a ``random`` connection set with a probability of 0.1 and two associated values (10000.0 and 1.0) used as weight and delay, respectively. .. GENERATED FROM PYTHON SOURCE LINES 77-80 .. code-block:: Python cg = csa.cset(csa.random(0.1), 10000.0, 1.0) .. GENERATED FROM PYTHON SOURCE LINES 81-83 Using the ``Create`` command from PyNEST, we create the neurons of the pre- and postsynaptic populations, each of which containing 16 neurons. .. GENERATED FROM PYTHON SOURCE LINES 83-87 .. code-block:: Python pre = nest.Create("iaf_psc_alpha", 16) post = nest.Create("iaf_psc_alpha", 16) .. GENERATED FROM PYTHON SOURCE LINES 88-93 We can now connect the populations using the ``Connect`` function with the ``conngen`` rule. It takes the IDs of pre- and postsynaptic neurons (``pre`` and ``post``), the connection set (``cg``) and a dictionary that maps the parameters weight and delay to positions in the value set associated with the connection set (``params_map``). .. GENERATED FROM PYTHON SOURCE LINES 93-98 .. code-block:: Python params_map = {"weight": 0, "delay": 1} connspec = {"rule": "conngen", "cg": cg, "params_map": params_map} nest.Connect(pre, post, connspec) .. GENERATED FROM PYTHON SOURCE LINES 99-102 To stimulate the network, we create a ``poisson_generator`` and set it up to fire with a rate of 100000 spikes per second. It is connected to the neurons of the pre-synaptic population. .. GENERATED FROM PYTHON SOURCE LINES 102-106 .. code-block:: Python pg = nest.Create("poisson_generator", params={"rate": 100000.0}) nest.Connect(pg, pre, "all_to_all") .. GENERATED FROM PYTHON SOURCE LINES 107-109 To measure and record the membrane potentials of the neurons, we create a ``voltmeter`` and connect it to all postsynaptic nodes. .. GENERATED FROM PYTHON SOURCE LINES 109-113 .. code-block:: Python vm = nest.Create("voltmeter") nest.Connect(vm, post, "all_to_all") .. GENERATED FROM PYTHON SOURCE LINES 114-116 We save the whole connection graph of the network as a PNG image using the ``plot_network`` function of the ``visualization`` submodule of PyNEST. .. GENERATED FROM PYTHON SOURCE LINES 116-120 .. code-block:: Python allnodes = pg + pre + post + vm visualization.plot_network(allnodes, "csa_example_graph.png") .. GENERATED FROM PYTHON SOURCE LINES 121-123 Finally, we simulate the network for 50 ms. The voltage traces of the postsynaptic nodes are plotted. .. GENERATED FROM PYTHON SOURCE LINES 123-127 .. code-block:: Python nest.Simulate(50.0) voltage_trace.from_device(vm) plt.show() .. _sphx_glr_download_auto_examples_csa_example.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: csa_example.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: csa_example.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_