Skip to content

Commit

Permalink
Merge pull request #91 from SpiNNakerManchester/use_build
Browse files Browse the repository at this point in the history
github action fixes
  • Loading branch information
Christian-B authored Jul 12, 2024
2 parents 30c7e8a + 0880149 commit 62081be
Show file tree
Hide file tree
Showing 17 changed files with 89 additions and 147 deletions.
93 changes: 15 additions & 78 deletions .github/workflows/python_actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,83 +17,20 @@ 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: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
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 mypy
run: pip install mypy

- name: Install Spinnaker Dependencies
uses: ./support/actions/install-spinn-deps
with:
repositories: >
call:
uses: SpiNNakerManchester/SupportScripts/.github/workflows/python_checks.yml@main
with:
dependencies: >
SpiNNUtils SpiNNMachine SpiNNMan PACMAN spalloc
SpiNNFrontEndCommon sPyNNaker TestBase
install: true

- name: Install matplotlib
uses: ./support/actions/install-matplotlib

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

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

# Add this when tests are built
- name: Create a spynnaker.cfg
uses: ./support/actions/configure-spynnaker
with:
board-address: spinn-4.cs.man.ac.uk

- name: Test with pytest
uses: ./support/actions/pytest
with:
tests: unittests
coverage: ${{ matrix.python-version == 3.12 }}
cover-packages: ${{ env.CODE_PATHS }}
coveralls-token: ${{ secrets.COVERALLS_REPO_TOKEN }}

- name: Lint with flake8
run: flake8 examples spinn_gym

# Instance of 'Block' has no 'segments' member (no-member)
- name: Lint with pylint
uses: ./support/actions/pylint
with:
disable: no-member
package: examples spinn_gym
exitcheck: 39

#- name: Validate XML
# if: matrix.python-version == 3.8
# uses: ./support/actions/validate-xml
# with:
# base-path: examples spinn_gym

- name: Run rat copyright enforcement
if: matrix.python-version == 3.12
uses: ./support/actions/check-copyrights

- name: Validate CITATION.cff
if: matrix.python-version == 3.12
uses: dieghernan/cff-validator@main

- name: Lint with mypy
run: mypy spinn_gym
install_module: true
pip_installs: pytest
test_directories: unittests
coverage-package: spinn_gym
flake8-packages: examples spinn_gym integration_tests
pylint-packages: examples spinn_gym integration_tests
pylint-disable: R, invalid-name, missing-class-docstring, missing-function-docstring, wrong-spelling-in-comment, wrong-spelling-in-docstring
mypy-packages: examples spinn_gym integration_tests
run_sphinx: false
cfg_file: spynnaker
rat_config_file: rat_gpl3.xml
1 change: 1 addition & 0 deletions .ratexcludes
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
**/SpiNNFrontEndCommon/**
**/sPyNNaker/**
**/sPyNNaker8/**
**/TestBase/**
**/.pylintrc
22 changes: 12 additions & 10 deletions examples/breakout/automated.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
# Copyright (c) 2023 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
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# https://www.apache.org/licenses/LICENSE-2.0
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# 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.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

from threading import Thread
import pyNN.spiNNaker as p

from spinn_gym.games.breakout.visualise_host import (
host_visualiser, start_visualiser)
from spinn_gym.games.breakout.automated_breakout import (
AutomatedBreakout, X_RES, X_SCALE, Y_RES, Y_SCALE)
from threading import Thread

# ---------------------------------------------------------------------
# Initialise Simulation and Parameters
Expand Down
6 changes: 3 additions & 3 deletions examples/breakout/breakout_simple_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@

# non-SpiNNaker imports
import matplotlib.pyplot as plt
import pyNN.spiNNaker as p
from pyNN.utility.plotting import Figure, Panel

# SpiNNaker imports
from spinn_gym.games.breakout.breakout_sim import get_scores
from spinn_gym.games.breakout.random_breakout import RandomBreakout
import pyNN.spiNNaker as p

breakout = RandomBreakout()

Expand Down Expand Up @@ -58,14 +58,14 @@
xlim=(0, runtime)
),
title="Simple Breakout Example",
annotations="Simulated with {}".format(p.name())
annotations=f"Simulated with {p.name()}"
)

plt.show()

scores = get_scores(breakout_pop=breakout.breakout_pop)

print("Scores: {}".format(scores))
print(f"Scores: {scores}")

# End simulation
p.end()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ def connect_to_arms(pre_pop, from_list, arms, r_type, plastic, stdp_model):
# print "out:", conn[1]
# if conn[1] == 2:
# print '\nit is possible\n'
for j in range(len(arms)):
for j, arm in enumerate(arms):
if len(arm_conn_list[j]) != 0:
if plastic:
p.Projection(pre_pop, arms[j],
p.Projection(pre_pop, arm,
p.FromListConnector(arm_conn_list[j]),
receptor_type=r_type, synapse_type=stdp_model)
else:
p.Projection(pre_pop, arms[j],
p.Projection(pre_pop, arm,
p.FromListConnector(arm_conn_list[j]),
receptor_type=r_type)

Expand Down Expand Up @@ -86,8 +86,8 @@ def connect_to_arms(pre_pop, from_list, arms, r_type, plastic, stdp_model):
# p.Projection(pendulum, null_pops[i],
# p.FromListConnector([[i, 0, weight, 1]]))

arm_collection = []
input_spikes = []
# arm_collection = []
# input_spikes = []
rates = [0, 0]
# rates = [0, 20]
# rates = [0, 10]
Expand Down Expand Up @@ -152,8 +152,7 @@ def connect_to_arms(pre_pop, from_list, arms, r_type, plastic, stdp_model):
i = 0
print("cart | angle")
while i < len(scores[0]):
print("{}\t{}\t{}".format(
scores[0][i], scores[0][i+1], scores[0][i+2]))
print(f"{scores[0][i]}\t{scores[0][i+1]}\t{scores[0][i+2]}")
i += 3

# spikes = []
Expand Down Expand Up @@ -186,7 +185,7 @@ def connect_to_arms(pre_pop, from_list, arms, r_type, plastic, stdp_model):
spikes_o2 = output_pop2.get_data('spikes').segments[0].spiketrains
v_o2 = output_pop2.get_data('v').segments[0].filter(name='v')[0]
g_o2 = output_pop2.get_data('gsyn_exc').segments[0].filter(name='gsyn_exc')[0]
plt.figure("spikes out {}".format(label))
plt.figure(f"spikes out {label}")
Figure(
Panel(spikes_n, xlabel="Time (ms)", ylabel="nID", xticks=True),
Panel(v_n, ylabel="Membrane potential (mV)", yticks=True),
Expand Down
6 changes: 3 additions & 3 deletions examples/inverted_pendulum/inverted_pendulum_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
# p.Projection(pendulum, null_pops[i],
# p.FromListConnector([[i, 0, weight, 1]]))

arm_collection = []
# arm_collection = []
# input_spikes = []
rate = 5
print('rate = ', rate)
Expand Down Expand Up @@ -129,7 +129,7 @@
i = 0
print("cart \t\t|\t\t angle")
while i < len(scores[0]):
print("{:8}\t{:8}".format(scores[0][i], scores[0][i+1]))
print(f"{scores[0][i]:8}\t{scores[0][i+1]:8}")
i += 2

spikes_n = null_pop.get_data('spikes').segments[0].spiketrains
Expand All @@ -140,7 +140,7 @@
spikes_o2 = output_pop2.get_data('spikes').segments[0].spiketrains
v_o2 = output_pop2.get_data('v').segments[0].filter(name='v')[0]
g_o2 = output_pop2.get_data('gsyn_exc').segments[0].filter(name='gsyn_exc')[0]
plt.figure("spikes out {}".format(label))
plt.figure(f"spikes out {label}")
Figure(
Panel(spikes_n, xlabel="Time (ms)", ylabel="nID", xticks=True),
Panel(v_n, ylabel="Membrane potential (mV)", yticks=True),
Expand Down
8 changes: 4 additions & 4 deletions examples/logic/logic_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

import pyNN.spiNNaker as p
import spinn_gym as gym

from pyNN.utility.plotting import Figure, Panel
import matplotlib.pyplot as plt
import numpy as np
import pyNN.spiNNaker as p
from pyNN.utility.plotting import Figure, Panel

import spinn_gym as gym


p.setup(timestep=1.0)
Expand Down
5 changes: 3 additions & 2 deletions examples/multi_arm_bandit/bandit_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

import pyNN.spiNNaker as p
import spinn_gym as gym

from pyNN.utility.plotting import Figure, Panel
import matplotlib.pyplot as plt
import numpy as np
import pyNN.spiNNaker as p

import spinn_gym as gym


p.setup(timestep=1.0)
Expand Down
11 changes: 5 additions & 6 deletions examples/store_recall/store_recall_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

import pyNN.spiNNaker as p
import spinn_gym as gym

from pyNN.utility.plotting import Figure, Panel
import matplotlib.pyplot as plt
import numpy as np
import pyNN.spiNNaker as p
from pyNN.utility.plotting import Figure, Panel

import spinn_gym as gym


rate_on = 10
Expand Down Expand Up @@ -72,8 +72,7 @@
i = 0
print("score 0 \t\t|\t score 1 \t|\t\t trials")
while i < len(scores):
print("{:8}\t\t{:8}\t\t{:8}".format(
scores[i][0], scores[i+1][0], scores[i+2][0]))
print(f"{scores[i][0]:8}\t\t{scores[i + 1][0]:8}\t\t{scores[i + 2][0]:8}")
i += 3

accuracy = float(scores[len(scores)-2][0]+scores[len(scores)-3][0]) / float(
Expand Down
6 changes: 4 additions & 2 deletions spinn_gym/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,19 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

import os
from spynnaker.pyNN.data import SpynnakerDataView

from spinn_gym.games.breakout.breakout import Breakout
from spinn_gym.games.multi_arm_bandit.bandit import Bandit
from spinn_gym.games.inverted_pendulum.inverted_pendulum import Pendulum
from spinn_gym.games.logic.logic import Logic
from spinn_gym.games.store_recall.store_recall import Recall
from spinn_gym.games.double_inverted_pendulum.double_pendulum \
import DoublePendulum
import os


# Put model_binaries directory on path
from spynnaker.pyNN.data import SpynnakerDataView
binary_path = os.path.join(os.path.split(__file__)[0], 'model_binaries')
SpynnakerDataView.register_binary_search_path(binary_path)

Expand Down
2 changes: 1 addition & 1 deletion spinn_gym/games/breakout/breakout.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class Breakout(SpinnGymApplicationVertex):
numpy.random.randint(10000),
numpy.random.randint(10000)]

__slots__ = ("__source_vertex")
__slots__ = ["__source_vertex"]

def __init__(self, x_factor=16, y_factor=16, width=160, height=128,
colour_bits=2, label="Breakout",
Expand Down
4 changes: 2 additions & 2 deletions spinn_gym/games/breakout/breakout_sim.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,8 @@ def get_hidden_to_decision_connections(pop_size, weight):

def clean_connection(data):
clean_conn = []
for i in range(0, len(data.connections)):
for c in data.connections[i]:
for connection in data.connections:
for c in connection:
new_c = (int(c[0]), int(c[1]), float(c[2]), float(c[3]))
clean_conn.append(new_c)

Expand Down
3 changes: 1 addition & 2 deletions spinn_gym/games/breakout/visualise_host.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
import functools
import numpy as np
from time import sleep

import numpy as np
import pyNN.spiNNaker as p
from spinn_gym.games.breakout.visualiser.visualiser import Visualiser

Expand Down
3 changes: 2 additions & 1 deletion spinn_gym/games/breakout/visualise_jupyter.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.
import functools
import threading
from time import sleep

import matplotlib.pyplot as plt
import numpy as np
from time import sleep

import pyNN.spiNNaker as p
from spinn_gym.games.breakout.visualiser.visualiser import Visualiser
Expand Down
Loading

0 comments on commit 62081be

Please sign in to comment.