Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test notebooks using nbmake #2

Merged
merged 43 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
15192a6
use nbmake
Christian-B Jan 9, 2024
866fceb
simple install
Christian-B Jan 9, 2024
4e658fb
virtual simple
Christian-B Jan 9, 2024
a6076c2
Merge remote-tracking branch 'origin/main' into play
Christian-B Jan 9, 2024
084fe9b
without setup PyNN
Christian-B Jan 9, 2024
5d6de66
Remove metadata
rowleya Jan 9, 2024
6578430
test specific
Christian-B Jan 9, 2024
43dc0c4
fix what is tested
Christian-B Jan 9, 2024
3696c9d
Some fixes
rowleya Jan 12, 2024
28b4022
Try this
rowleya Jan 12, 2024
0f5a572
Attempt another fix
rowleya Jan 12, 2024
0d706a2
merged in main
Christian-B Jan 15, 2024
44f85af
detect files for pytest
Christian-B Jan 16, 2024
ac277a4
notebooks that do not work virtually
Christian-B Jan 16, 2024
5ee7291
Dont raise SkipTest
Christian-B Jan 16, 2024
3d0c9cd
test setup by itself
Christian-B Jan 16, 2024
40f3645
fix workflow
Christian-B Jan 16, 2024
333d3fb
more workflow fixes
Christian-B Jan 16, 2024
65ad613
fix try 3
Christian-B Jan 16, 2024
c231210
fix workflow
Christian-B Jan 16, 2024
38d6689
test each by itself
Christian-B Jan 16, 2024
50b65ca
dont test two scipt not able to run virtual
Christian-B Jan 17, 2024
dbacc5b
fix exception handling
Christian-B Jan 17, 2024
b936918
skip 02.LiveInputAndOutput/solutions/task4-solutions.ipynb
Christian-B Jan 17, 2024
3b81b21
multiple pythons
Christian-B Jan 18, 2024
058f99f
test less versions
Christian-B Jan 18, 2024
8586a00
add 3.9
Christian-B Jan 18, 2024
9a0ee60
Fix data spec import
Jan 18, 2024
6de6a50
Merge branch 'fix_live' into play
Jan 18, 2024
694a787
Remove kernel again!
Jan 18, 2024
f61b8b9
add 3.8
Christian-B Jan 18, 2024
419ada9
Remove outputs here too
Jan 18, 2024
bfbb15f
weirdness for python 3.8
Christian-B Jan 18, 2024
2162bd6
debug print
Christian-B Jan 18, 2024
a8e430b
Merge branch 'play' of https://github.com/SpiNNakerManchester/SpiNNak…
Jan 18, 2024
f14f4dc
debug
Christian-B Jan 18, 2024
05585aa
Merge remote-tracking branch 'origin/play' into play
Christian-B Jan 18, 2024
3132d8a
type to adapt to 3.8
Christian-B Jan 18, 2024
e504049
add 3.9
Christian-B Jan 18, 2024
9edd043
remove the play notebooks
Christian-B Jan 18, 2024
64bc7b3
minor fixes and style checks
Christian-B Jan 18, 2024
60a2826
pylint correct directories
Christian-B Jan 18, 2024
2cb2edc
pylint correct directories 2nd attempt
Christian-B Jan 18, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 86 additions & 0 deletions .github/workflows/python_actions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# Copyright (c) 2020 The University of Manchester
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# This workflow will install Python dependencies, run tests, lint and rat with a variety of Python versions
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: Python Actions

on: [push]

jobs:
test:
runs-on: ubuntu-latest
timeout-minutes: 10
strategy:
matrix:
python-version: [3.8, 3.9, "3.10", "3.11", "3.12"]

steps:
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Checkout
uses: actions/checkout@v4

- name: Checkout SupportScripts
uses: actions/checkout@v4
with:
repository: SpiNNakerManchester/SupportScripts
path: support

- name: Install pip, etc
uses: ./support/actions/python-tools

- name: Install nbmake
run: pip install pytest nbmake

- name: Install Spinnaker Dependencies
uses: ./support/actions/install-spinn-deps
with:
repositories: >
SpiNNUtils SpiNNMachine SpiNNMan PACMAN spalloc
SpiNNFrontEndCommon sPyNNaker TestBase
install: true

- name: Setup
uses: ./support/actions/run-install

#- name: Setup PyNN
# uses: ./support/actions/pynn-setup

- name: Create a spynnaker.cfg
uses: ./support/actions/configure-spynnaker
with:
virtual: true

- name: Build test bash
run: python integration_tests/bash_builder.py

- name: Test with nbmake
run: bash integration_tests/pytest.bash

- name: Lint with flake8
run: flake8 integration_tests spinnaker_jupyter_examples

- name: Lint with pylint
uses: ./support/actions/pylint
with:
package: integration_tests spinnaker_jupyter_examples
exitcheck: 31 # Action fails on any message
language: en_GB


3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
/.project
/.pydevproject
.ipynb_checkpoints
.pytest_cache
.pytest.bash
38 changes: 15 additions & 23 deletions 00.Setup/Setup.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
"source": [
"import configparser\n",
"import os\n",
"from unittest import SkipTest\n",
"\n",
"OVERRIDE_EXISTING = False\n",
"FULL_PATH = os.path.expanduser('~/.spynnaker.cfg')\n",
Expand Down Expand Up @@ -50,23 +49,23 @@
" return True\n",
"\n",
" # SkipTest as unittest considers this neither a failure nor a success\n",
" raise SkipTest(f\"{FULL_PATH} already exists. \"\n",
" \"To replace it change OVERRIDE_EXISTING to True\")\n",
" print(f\"{FULL_PATH} already exists.\")\n",
" print(\"To replace it change OVERRIDE_EXISTING to True\")\n",
" return False\n",
"\n",
"\n",
"check_should_create()\n",
"\n",
"# Make sure there is a spynnaker.cfg file\n",
"with open(FULL_PATH, 'w') as cfg:\n",
" cfg.write(\"[Machine]\\n\")\n",
" cfg.write(\"spalloc_server = https://spinnaker.cs.man.ac.uk/spalloc/\\n\")\n",
" cfg.write(\"\\n\")\n",
" cfg.write(\"[Java]\\n\")\n",
" cfg.write(\"use_java=True\\n\")\n",
" cfg.write(\"\\n\")\n",
" cfg.write(\"[Reports]\\n\")\n",
" cfg.write(\"read_provenance_data = False\\n\")\n",
" print(f\"New {FULL_PATH} created\")\n"
"if check_should_create():\n",
" with open(FULL_PATH, 'w') as cfg:\n",
" cfg.write(\"[Machine]\\n\")\n",
" cfg.write(\"spalloc_server = https://spinnaker.cs.man.ac.uk/spalloc/\\n\")\n",
" cfg.write(\"\\n\")\n",
" cfg.write(\"[Java]\\n\")\n",
" cfg.write(\"use_java=True\\n\")\n",
" cfg.write(\"\\n\")\n",
" cfg.write(\"[Reports]\\n\")\n",
" cfg.write(\"read_provenance_data = False\\n\")\n",
" print(f\"New {FULL_PATH} created\")\n"
]
},
{
Expand All @@ -82,14 +81,7 @@
]
}
],
"metadata": {
"kernelspec": {
"display_name": "EBRAINS-experimental",
"language": "python",
"name": "ebrains-experimental"
},
"title": "SpiNNaker Setup"
},
"metadata": {},
"nbformat": 4,
"nbformat_minor": 2
}
82 changes: 20 additions & 62 deletions 01.RunningPyNNSimulations/RunningPyNNSimulationsOnSpiNNaker.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,9 @@
"of the current is added over a number of timesteps, with the current decaying exponentially between each.\n",
"A longer decay rate will result in more charge being added overall per spike that crosses the synapse.\n",
"\n",
"In the above example, the default parameters of the IF_curr_exp are used. These are shown below."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"In the above example, the default parameters of the IF_curr_exp are used. These are shown below.\n",
"\n",
"```\n",
"lif_curr_exp_params = {\n",
" 'cm': 1.0, # The capacitance of the LIF neuron in nano-Farads\n",
" 'tau_m': 20.0, # The time-constant of the RC circuit, in milliseconds\n",
Expand All @@ -135,7 +129,8 @@
" 'tau_syn_E': 5.0, # The excitatory input current decay time-constant\n",
" 'tau_syn_I': 5.0, # The inhibitory input current decay time-constant\n",
" 'i_offset': 0.0, # A base input current to add each timestep\n",
"}"
"}\n",
"```"
]
},
{
Expand All @@ -147,19 +142,14 @@
"value of the membrane voltage; the higher the membrane voltage, the more input is required to cause a\n",
"spike. This is modelled as the reversal potential of the synapse; when the membrane potential equals the\n",
"reversal potential, no current will flow across the synapse. A conductance-based version of the LIF model\n",
"is provided, which, in addition to the above parameters, also supports the following."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"is provided, which, in addition to the above parameters, also supports the following.",
"\n",
"```\n",
"lif_cond_exp_extra_params = {\n",
" 'e_rev_E': 0., # The reversal potential of the excitatory synapse\n",
" 'e_rev_I': -80.0 # The reversal potential of the inhibitory synapse\n",
"}"
"}\n",
"```"
]
},
{
Expand All @@ -168,16 +158,10 @@
"source": [
"The initial value of the state variables of the neural model can also be set (such as the membrane voltage).\n",
"This is done via the initialize function of the population, which takes the name of the state variable (e.g. v\n",
"for the membrane voltage), and the value to be assigned e.g. the initial voltage can be set to -65.0mV as follows."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"pop_1.initialize(v=-65.0)"
"for the membrane voltage), and the value to be assigned e.g. the initial voltage can be set to -65.0mV as follows.\n",
"```\n",
"pop_1.initialize(v=-65.0)\n",
"```"
]
},
{
Expand Down Expand Up @@ -208,15 +192,7 @@
"\n",
"As well as a connector the Projection must also have a synapse_type which determines how the synapse\n",
"behaves when spikes are received. For example a StaticSynapse which has fixed weights and delays is\n",
"specified as shown below."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"specified as shown below.\n",
"synapse_type=sim.StaticSynapse(weight=0.75, delay=1.0)"
]
},
Expand Down Expand Up @@ -326,19 +302,14 @@
"### STDP in PyNN\n",
"The steps for creating a network using STDP are much the same as previously described, with the main\n",
"difference being that some of the projections use a STDPMechanism to describe the plasticity. Below is an\n",
"example of the creation of a projection with STDP."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"example of the creation of a projection with STDP.\n",
"\n",
"```\n",
"timing_rule = sim.SpikePairRule(tau_plus=20.0, tau_minus=20.0, A_plus=0.5, A_minus=0.5)\n",
"weight_rule = sim.AdditiveWeightDependence(w_max=5.0, w_min=0.0)\n",
"stdp_model = sim.STDPMechanism(timing_dependence=timing_rule, weight_dependence=weight_rule, weight=0.0, delay=5.0)\n",
"stdp_projection = sim.Projection(input, pop_1, sim.OneToOneConnector(), synapse_type=stdp_model)"
"stdp_projection = sim.Projection(input, pop_1, sim.OneToOneConnector(), synapse_type=stdp_model)\n",
"```"
]
},
{
Expand Down Expand Up @@ -423,22 +394,9 @@
" - Create an STDP curve graph using a SpikeSourceArray stimulating a LIF population, with varying spike times for the SpikeSourceArray.\n",
" - See the notebook for further extensions.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "EBRAINS-experimental",
"language": "python",
"name": "ebrains-experimental"
},
"title": "Running PyNN Simulations on SpiNNaker"
},
"nbformat": 4,
"nbformat_minor": 2
Expand Down
6 changes: 0 additions & 6 deletions 01.RunningPyNNSimulations/solutions/task1-solutions.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -178,12 +178,6 @@
}
],
"metadata": {
"kernelspec": {
"display_name": "EBRAINS-experimental",
"language": "python",
"name": "ebrains-experimental"
},
"title": "Task 1.1 Solutions"
},
"nbformat": 4,
"nbformat_minor": 2
Expand Down
6 changes: 0 additions & 6 deletions 01.RunningPyNNSimulations/solutions/task2-solutions.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -199,12 +199,6 @@
}
],
"metadata": {
"kernelspec": {
"display_name": "EBRAINS-experimental",
"language": "python",
"name": "ebrains-experimental"
},
"title": "Task 1.2 Solutions"
},
"nbformat": 4,
"nbformat_minor": 2
Expand Down
6 changes: 0 additions & 6 deletions 01.RunningPyNNSimulations/solutions/task3-solutions.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -250,12 +250,6 @@
}
],
"metadata": {
"kernelspec": {
"display_name": "EBRAINS-experimental",
"language": "python",
"name": "ebrains-experimental"
},
"title": "Task 1.3 Solutions"
},
"nbformat": 4,
"nbformat_minor": 2
Expand Down
8 changes: 1 addition & 7 deletions 01.RunningPyNNSimulations/solutions/task4-solutions.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@
"source": [
"weights = proj.get([\"weight\"], \"list\")\n",
"p.end()\n",
"print weights"
"print(weights)"
]
},
{
Expand All @@ -221,12 +221,6 @@
}
],
"metadata": {
"kernelspec": {
"display_name": "EBRAINS-experimental",
"language": "python",
"name": "ebrains-experimental"
},
"title": "Task 1.4 Solutions"
},
"nbformat": 4,
"nbformat_minor": 2
Expand Down
11 changes: 3 additions & 8 deletions 01.RunningPyNNSimulations/solutions/task5-solutions.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@
"metadata": {},
"outputs": [],
"source": [
"weights = proj.get([\"weight\"], \"list\", with_address=False)\n",
"import numpy\n",
"weights = numpy.array(proj.get(\"weight\", \"list\", with_address=False))\n",
"pre_spikes = pre.get_data(\"spikes\").segments[0].spiketrains\n",
"post_spikes = post.get_data(\"spikes\").segments[0].spiketrains\n",
"p.end()"
Expand All @@ -177,7 +178,7 @@
"metadata": {},
"outputs": [],
"source": [
"weight_diff = weights[:] - 0.5\n",
"weight_diff = weights - 0.5\n",
"time_diff = [pre_neuron_spikes[0] - post_neuron_spikes[0] for pre_neuron_spikes, post_neuron_spikes in zip(pre_spikes, post_spikes)]"
]
},
Expand All @@ -203,12 +204,6 @@
}
],
"metadata": {
"kernelspec": {
"display_name": "EBRAINS-experimental",
"language": "python",
"name": "ebrains-experimental"
},
"title": "Task 1.5 Solutions"
},
"nbformat": 4,
"nbformat_minor": 2
Expand Down
Loading