From 33b6584cd34ec79345cafeaad24831b17692b061 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5kon=20M=C3=B8rk?= Date: Mon, 26 Sep 2022 14:07:03 +0200 Subject: [PATCH] Updated example notebook --- ...nection_semantics_prototype_examples.ipynb | 164 ++++-------------- 1 file changed, 29 insertions(+), 135 deletions(-) diff --git a/pynest/examples/Connection_semantics_prototype_examples.ipynb b/pynest/examples/Connection_semantics_prototype_examples.ipynb index 7d08baded0..deb3f0db69 100644 --- a/pynest/examples/Connection_semantics_prototype_examples.ipynb +++ b/pynest/examples/Connection_semantics_prototype_examples.ipynb @@ -16,11 +16,17 @@ "\n", "## What is currently implemented\n", "\n", - "- A PyNEST interface with several projection classes, implemented in a submodule `nest.projections`.\n", + "- A PyNEST interface with several projection classes, implemented in the top level of `nest`.\n", + "- `nest.Connect()` now only works with projection objects.\n", "- Projections work with both normal connections, and spatially structured connections involving for example distance based probabilities or masks.\n", - "- Classes for some of the synapse models, in the submodule `nest.synapsemodels`. The synapse object created can be used as the synapse specification when creating projections.\n", + "- Classes for all synapse models, in the submodule `nest.synapsemodels`. The synapse object created can be used as the synapse specification when creating projections.\n", "- Synapse objects can be combined with `CollocatedSynapses`, and used instead of a single synapse model object when creating a projection.\n", - "- Basic C++ implementation for connection, without any processing of the projections before connecting." + "- Basic C++ implementation for connection, without any processing of the projections before connecting.\n", + "\n", + "## Remaining work and next steps\n", + "\n", + "- Documentation\n", + "- Smarter C++ implementation" ] }, { @@ -38,7 +44,7 @@ "source": [ "## Projection object\n", "\n", - "Introducing the Projection object, representing projection between two populations with a certain rule. The projection object is added to a buffer with `projections.Connect()`, and held until calling `projections.BuildNetwork()`.\n", + "Introducing the Projection object, representing projection between two populations with a certain rule. The projection object is added to a buffer with `Connect()`, and held until calling `BuildNetwork()`.\n", "\n", "### `OneToOne`" ] @@ -145,9 +151,7 @@ { "cell_type": "code", "execution_count": 4, - "metadata": { - "scrolled": false - }, + "metadata": {}, "outputs": [ { "name": "stdout", @@ -200,16 +204,13 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "### `PairwiseBernoulli`\n", - "Projections can store synapse specifications." + "### `PairwiseBernoulli`" ] }, { "cell_type": "code", "execution_count": 5, - "metadata": { - "scrolled": false - }, + "metadata": {}, "outputs": [ { "name": "stdout", @@ -302,12 +303,12 @@ "metadata": {}, "source": [ "## Multiple projections\n", - "Multiple Projections can be added to the buffer before connecting by calling `projections.Connect()` multiple times." + "Multiple Projections can be added to the buffer before connecting, by calling `Connect()` multiple times." ] }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 7, "metadata": {}, "outputs": [ { @@ -375,7 +376,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 8, "metadata": {}, "outputs": [ { @@ -435,121 +436,19 @@ "print(conns)" ] }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Using `ConnectImmediately()`\n", - "Using `projections.ConnectImmediately()` will immediately construct the connections of a Projection." - ] - }, - { - "cell_type": "code", - "execution_count": 10, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - " source target synapse model weight delay \n", - "-------- -------- --------------- -------- -------\n", - " 1 1 static_synapse 1.000 1.000\n", - " 2 2 static_synapse 1.000 1.000\n", - " 3 3 static_synapse 1.000 1.000\n", - " 4 4 static_synapse 1.000 1.000\n", - " 5 5 static_synapse 1.000 1.000\n" - ] - } - ], - "source": [ - "nest.ResetKernel()\n", - "\n", - "n = nest.Create('iaf_psc_alpha', 5)\n", - "nest.ConnectImmediately(nest.OneToOne(source=n, target=n))\n", - "\n", - "conns = nest.GetConnections()\n", - "print(conns)\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Or for all Projections in a list." - ] - }, - { - "cell_type": "code", - "execution_count": 11, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - " source target synapse model weight delay \n", - "-------- -------- --------------- -------- -------\n", - " 1 4 static_synapse 1.000 1.000\n", - " 1 4 static_synapse 1.000 1.000\n", - " 1 5 static_synapse 1.000 1.000\n", - " 1 3 static_synapse 1.000 1.000\n", - " 1 2 static_synapse 1.000 1.000\n", - " 1 5 static_synapse 1.000 1.000\n", - " 2 3 static_synapse 1.000 1.000\n", - " 2 5 static_synapse 1.000 1.000\n", - " 2 4 static_synapse 1.000 1.000\n", - " 3 5 static_synapse 1.000 1.000\n", - " 3 2 static_synapse 1.000 1.000\n", - " 3 3 static_synapse 1.000 1.000\n", - " 3 5 static_synapse 1.000 1.000\n", - " 3 5 static_synapse 1.000 1.000\n", - " 3 1 static_synapse 1.000 1.000\n", - " 3 1 static_synapse 1.000 1.000\n", - " 3 3 static_synapse 1.000 1.000\n", - " 4 2 static_synapse 1.000 1.000\n", - " 4 2 static_synapse 1.000 1.000\n", - " 4 3 static_synapse 1.000 1.000\n", - " 4 4 static_synapse 1.000 1.000\n", - " 4 4 static_synapse 1.000 1.000\n", - " 4 4 static_synapse 1.000 1.000\n", - " 4 3 static_synapse 1.000 1.000\n", - " 4 2 static_synapse 1.000 1.000\n", - " 5 2 static_synapse 1.000 1.000\n", - " 5 1 static_synapse 1.000 1.000\n", - " 5 1 static_synapse 1.000 1.000\n", - " 5 1 static_synapse 1.000 1.000\n", - " 5 1 static_synapse 1.000 1.000\n" - ] - } - ], - "source": [ - "nest.ResetKernel()\n", - "\n", - "N = 5\n", - "IN_A = 2\n", - "IN_B = 4\n", - "n = nest.Create('iaf_psc_alpha', N)\n", - "\n", - "projections = [nest.FixedIndegree(source=n, target=n, indegree=IN_A),\n", - " nest.FixedIndegree(source=n, target=n, indegree=IN_B)]\n", - "nest.ConnectImmediately(projections)\n", - "\n", - "conns = nest.GetConnections()\n", - "print(conns)" - ] - }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Synapse model object\n", + "We introduce synapse model objects, which hold information previously passed as a `dict` to `syn_spec`.\n", + "\n", "### `static_synapse`" ] }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 9, "metadata": {}, "outputs": [ { @@ -590,7 +489,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 10, "metadata": {}, "outputs": [ { @@ -641,7 +540,7 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 11, "metadata": {}, "outputs": [ { @@ -700,12 +599,13 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "### Using `CollocatedSynapses` in projections" + "### Using `CollocatedSynapses` in projections\n", + "Projections support passing a `CollocatedSynapses` object as `syn_spec`. With `CollocatedSynapses`, connections with different synapse parameters can be created between the same nodes." ] }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 12, "metadata": {}, "outputs": [ { @@ -749,12 +649,13 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "### Spatial connections" + "### Spatial connections\n", + "Projections for spatial connections are created the same way as regular connections." ] }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 13, "metadata": {}, "outputs": [ { @@ -815,7 +716,7 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 14, "metadata": {}, "outputs": [ { @@ -866,13 +767,6 @@ "conns = nest.GetConnections()\n", "print(conns)" ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] } ], "metadata": { @@ -891,7 +785,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.2" + "version": "3.9.12" } }, "nbformat": 4,