Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian-B committed Jul 12, 2024
2 parents 2f608dd + 14076df commit ba8433f
Show file tree
Hide file tree
Showing 65 changed files with 574 additions and 285 deletions.
78 changes: 18 additions & 60 deletions .github/workflows/python_actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,66 +17,24 @@

name: Python Actions
on: [push]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.8, 3.9, "3.10", "3.11", "3.12"]

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

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install pip, etc
uses: ./support/actions/python-tools
- name: Install Spinnaker Dependencies
uses: ./support/actions/install-spinn-deps
with:
repositories: >
jobs:
call:
uses: SpiNNakerManchester/SupportScripts/.github/workflows/python_checks.yml@main
with:
dependencies: >
SpiNNUtils SpiNNMachine SpiNNMan PACMAN spalloc
SpiNNFrontEndCommon sPyNNaker
install: true

- name: Setup PyNN
uses: ./support/actions/pynn-setup
- name: Install matplotlib
uses: ./support/actions/install-matplotlib

- name: Lint with flake8
run: flake8 examples

- name: Lint with pylint
uses: ./support/actions/pylint
with:
package: examples
exitcheck: 39

validate:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Checkout SupportScripts
uses: actions/checkout@v4
with:
repository: SpiNNakerManchester/SupportScripts
path: support
- name: Run rat copyright enforcement
if: matrix.python-version == 3.12
uses: ./support/actions/check-copyrights
with:
config_file: rat_asl20.xml

- name: Validate CITATION.cff
if: matrix.python-version == 3.12
uses: dieghernan/cff-validator@main
install_module: false
pip_installs: pytest
ubuntu_packages: graphviz
test_directories: unittests
coverage-package:
flake8-packages: examples balanced_random learning sudoku synfire
pylint-packages: examples balanced_random learning sudoku synfire
# invalid-name because scripts have values pylint considers constants
# wrong-spelling-in-docstring due to param names ect
pylint-disable: R, wrong-spelling-in-docstring, invalid-name
# Examples are not typed to keep them easier to read
mypy-packages:
run_sphinx: false
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[![Build Status](https://travis-ci.org/SpiNNakerManchester/PyNNExamples.svg?branch=master)](https://travis-ci.org/SpiNNakerManchester/PyNNExamples)

Examples for PyNN
=====================
=================

This repository holds miscellaneous examples of using sPyNNaker for PyNN

Expand Down
2 changes: 1 addition & 1 deletion examples/balanced_random/balanced_random.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,6 @@
Panel(data.segments[0].spiketrains,
yticks=True, markersize=2.0, xlim=(0, end_time)),
title="Balanced Random Network",
annotations="Simulated with {}".format(p.name())
annotations=f"Simulated with {p.name()}"
)
pylab.show()
16 changes: 15 additions & 1 deletion examples/balanced_random/split/balanced_random_split.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# Copyright (c) 2021 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.

import pylab
import numpy
from pyNN.random import RandomDistribution
Expand Down Expand Up @@ -113,6 +127,6 @@
Panel(data.segments[0].spiketrains,
yticks=True, markersize=2.0, xlim=(0, end_time)),
title="Balanced Random Network",
annotations="Simulated with {}".format(p.name())
annotations=f"Simulated with {p.name()}"
)
pylab.show()
2 changes: 1 addition & 1 deletion examples/current_injection_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
xlabel="Time (ms)", ylabel="Membrane potential (mV)",
ylim=(-96, -59)),
title="Current injection example",
annotations="Simulated with {}".format(sim.name())
annotations=f"Simulated with {sim.name()}"
)

plt.show()
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import time
import numpy
import pylab
import pyNN.spiNNaker as p
from pyNN.random import RandomDistribution
import pylab
import numpy
from pyNN.utility.plotting import Figure, Panel
import time

p.setup(timestep=0.1)
p.set_number_of_neurons_per_core(p.SpikeSourcePoisson, 50)
Expand Down Expand Up @@ -92,6 +92,12 @@


def start_callback(label, connection):
"""
Changes the connection rate very 10 seconds
:param str label:
:param SpynnakerPoissonControlConnection connection:
"""
for rate in [50, 10, 20]:
time.sleep(10.0)
connection.set_rates(label, [(i, rate) for i in range(100)])
Expand All @@ -112,6 +118,6 @@ def start_callback(label, connection):
Panel(data.segments[0].spiketrains,
yticks=True, markersize=2.0, xlim=(0, end_time)),
title="Balanced Random Network",
annotations="Simulated with {}".format(p.name())
annotations=f"Simulated with {p.name()}"
)
pylab.show()
49 changes: 38 additions & 11 deletions examples/external_devices_examples/live_examples/spike_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
# limitations under the License.

import random
import pyNN.spiNNaker as Frontend
import time
from threading import Condition
import pyNN.spiNNaker as Frontend
from pyNN.utility.plotting import Figure, Panel
import matplotlib.pyplot as plt

Expand All @@ -29,38 +29,65 @@

# Create an initialisation method
def init_pop(_label, _n_neurons, _run_time_ms, _machine_timestep_ms):
print("{} has {} neurons".format(_label, _n_neurons))
print("Simulation will run for {}ms at {}ms timesteps".format(
_run_time_ms, _machine_timestep_ms))
"""
Print method to show callback has been called
:param str _label:
:param int _n_neurons:
:param float _run_time_ms:
:param float _machine_timestep_ms:
"""
print(f"{_label} has {_n_neurons} neurons")
print(f"Simulation will run for {_run_time_ms}ms "
f"at {_machine_timestep_ms}ms timesteps")


# Create a sender of packets for the forward population
def send_input_forward(label, sender):
"""
Sends 5 spikes at 20 millisecond intervals
:param str label:
:param SpynnakerLiveSpikesConnection sender:
"""
for neuron_id in range(0, 100, 20):
time.sleep(random.random() + 0.5)
print_condition.acquire()
print("Sending forward spike {}".format(neuron_id))
print(f"Sending forward spike {neuron_id}")
print_condition.release()
sender.send_spike(label, neuron_id, send_full_keys=True)


# Create a sender of packets for the backward population
def send_input_backward(label, sender):
"""
Sends 5 spikes at 20 millisecond intervals
:param str label:
:param SpynnakerLiveSpikesConnection sender:
"""
for neuron_id in range(0, 100, 20):
real_id = 100 - neuron_id - 1
time.sleep(random.random() + 0.5)
print_condition.acquire()
print("Sending backward spike {}".format(real_id))
print(f"Sending backward spike {real_id}")
print_condition.release()
sender.send_spike(label, real_id)


# Create a receiver of live spikes
def receive_spikes(label, _time, neuron_ids):
"""
Prints that spikes have been received
:param int label:
:param str _time:
:param list(int) neuron_ids:
:return:
"""
for neuron_id in neuron_ids:
print_condition.acquire()
print("Received spike at time {} from {} - {}".format(
_time, label, neuron_id))
print(f"Received spike at time {_time} from {label} - {neuron_id}")
print_condition.release()


Expand Down Expand Up @@ -110,7 +137,7 @@ def receive_spikes(label, _time, neuron_ids):
run_time = 8000
weight_to_spike = 2.0

# neural parameters of the ifcur model used to respond to injected spikes.
# neural parameters of the model used to respond to injected spikes.
# (cell params for a synfire chain)
cell_params_lif = {'cm': 0.25,
'i_offset': 0.0,
Expand Down Expand Up @@ -177,7 +204,7 @@ def receive_spikes(label, _time, neuron_ids):
Frontend.FromListConnector(loop_backward))

# record spikes from the synfire chains so that we can read off valid results
# in a safe way afterwards, and verify the behavior
# in a safe way afterwards, and verify the behaviour
pop_forward.record('spikes')
pop_backward.record('spikes')

Expand All @@ -203,7 +230,7 @@ def receive_spikes(label, _time, neuron_ids):
Panel(spikes_backward.segments[0].spiketrains,
yticks=True, markersize=0.2, xlim=(0, run_time)),
title="Simple synfire chain example with injected spikes",
annotations="Simulated with {}".format(Frontend.name())
annotations=f"Simulated with {Frontend.name}"
)
plt.show()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import multiprocessing
import tkinter as tk
import pyNN.spiNNaker as Frontend
from pyNN.utility.plotting import Figure, Panel
import matplotlib.pyplot as plt
import multiprocessing


class PyNNScript(object):
Expand All @@ -37,7 +37,7 @@ def __init__(self):
# simulation, as well as the expected weight each spike will contain
self.n_neurons = 100

# set up gui
# set up GUI
p = None
sender_port = None
if use_spike_injector:
Expand Down Expand Up @@ -65,7 +65,7 @@ def __init__(self):
live_spikes_connection_receive.add_receive_callback(
"pop_backward", receive_spikes)

# different runtimes for demostration purposes
# different run times for demonstration purposes
run_time = None
if not use_c_visualiser and not use_spike_injector:
run_time = 1000
Expand Down Expand Up @@ -185,7 +185,7 @@ def __init__(self):
Frontend.FromListConnector(loop_backward))

# record spikes from the synfire chains so that we can read off valid
# results in a safe way afterwards, and verify the behavior
# results in a safe way afterwards, and verify the behaviour
pop_forward.record('spikes')
pop_backward.record('spikes')

Expand Down Expand Up @@ -218,16 +218,23 @@ def __init__(self):
Panel(spikes_backward.segments[0].spiketrains,
yticks=True, markersize=0.2, xlim=(0, run_time)),
title="Simple synfire chain example with injected spikes",
annotations="Simulated with {}".format(Frontend.name())
annotations=f"Simulated with {Frontend.name()}"
)
plt.show()


# Create a receiver of live spikes
def receive_spikes(label, time, neuron_ids):
"""
Print that spikes have been received
:param str label:
:param int time:
:param list(int) neuron_ids:
:return:
"""
for neuron_id in neuron_ids:
print("Received spike at time {} from {} - {}".format(
time, label, neuron_id))
print(f"Received spike at time {time} from {label} - {neuron_id}")


class GUI(object):
Expand Down Expand Up @@ -274,13 +281,22 @@ def __init__(self, n_neurons, ready, port):
self._root.mainloop()

def start(self, pop_label, connection):
"""
Set the start button to state to normal
:param pop_label: IGNORED
:param connection: IGNORED
"""
# pylint: disable=unused-argument
self._button["state"] = "normal"

def inject_spike(self):
"""
Inject a spike into system
"""
neuron_id = self._neuron_id.get()
label = self._pop_label.get()
print("injecting with neuron_id {} to pop {}".format(neuron_id, label))
print(f"injecting with neuron_id {neuron_id} to pop {label}")
self._live_spikes_connection.send_spike(label, neuron_id)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
Panel(spikes.segments[0].spiketrains,
yticks=True, markersize=0.2, xlim=(0, 5000)),
title="Simple synfire chain example with injected spikes",
annotations="Simulated with {}".format(p.name())
annotations=f"Simulated with {p.name()}"
)
plt.show()

Expand Down
Loading

0 comments on commit ba8433f

Please sign in to comment.