Skip to content

Commit

Permalink
premerge to main
Browse files Browse the repository at this point in the history
  • Loading branch information
LukeHollingsworth committed Nov 22, 2024
2 parents d423f89 + f830c6a commit 3351dd8
Show file tree
Hide file tree
Showing 50 changed files with 1,527 additions and 636 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/docs_build_and_deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Build Sphinx docs and deploy to GitHub Pages

# Generate the documentation on all merges to main, all pull requests, or by
# manual workflow dispatch. The build job can be used as a CI check that the
# docs still build successfully. The deploy job only runs when a tag is
# pushed and actually moves the generated html to the gh-pages branch
# (which triggers a GitHub pages deployment).
on:
push:
branches:
- main
tags:
- '*'
pull_request:
workflow_dispatch:


jobs:
linting:
# scheduled workflows should not run on forks
if: (${{ github.event_name == 'schedule' }} && ${{ github.repository_owner == 'SainsburyWellcomeCentre' }} && ${{ github.ref == 'refs/heads/main' }}) || (${{ github.event_name != 'schedule' }})
runs-on: ubuntu-latest
steps:
- uses: neuroinformatics-unit/actions/lint@v2

build_sphinx_docs:
name: Build Sphinx Docs
runs-on: ubuntu-latest
steps:
- uses: neuroinformatics-unit/actions/build_sphinx_docs@v2

deploy_sphinx_docs:
name: Deploy Sphinx Docs
needs: build_sphinx_docs
permissions:
contents: write
if: github.event_name == 'push' && github.ref_type == 'tag'
runs-on: ubuntu-latest
steps:
- uses: neuroinformatics-unit/actions/deploy_sphinx_docs@v2
with:
secret_input: ${{ secrets.GITHUB_TOKEN }}
19 changes: 7 additions & 12 deletions .github/workflows/test_and_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ jobs:
linting:
runs-on: ubuntu-latest
steps:
- uses: neuroinformatics-unit/actions/lint@v2.0.0
- uses: neuroinformatics-unit/actions/lint@v2

manifest:
name: Check Manifest
runs-on: ubuntu-latest
steps:
- uses: neuroinformatics-unit/actions/check_manifest@v2.0.0
- uses: neuroinformatics-unit/actions/check_manifest@v2

test:
needs: [linting, manifest]
Expand All @@ -38,29 +38,24 @@ jobs:
~/.NeuralPlayground/*
key: cached-test-data
enableCrossOsArchive: true
- uses: neuroinformatics-unit/actions/test@v2.0.0
- uses: neuroinformatics-unit/actions/test@v2
with:
python-version: ${{ matrix.python-version }}
use-xvfb: true
secret-codecov-token: ${{ secrets.CODECOV_TOKEN }}

build_sdist_wheels:
name: Build source distribution
needs: [test]
if: github.event_name == 'push' && github.ref_type == 'tag'
runs-on: ubuntu-latest
steps:
- uses: neuroinformatics-unit/actions/build_sdist_wheels@v2.0.0
- uses: neuroinformatics-unit/actions/build_sdist_wheels@v2

upload_all:
name: Publish build distributions
needs: [build_sdist_wheels]
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v3
- uses: neuroinformatics-unit/actions/upload_pypi@v2
with:
name: artifact
path: dist
- uses: pypa/[email protected]
with:
user: __token__
password: ${{ secrets.TWINE_API_KEY }}
secret-pypi-key: ${{ secrets.TWINE_API_KEY }}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,6 @@ coverage.xml

# PyPI distribution / packages
dist/

# Sphinx documentation
docs/build/
9 changes: 6 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
exclude: '^neuralplayground/experiments/.*_20.*|^documents/'
# Configuring https://pre-commit.ci/ bot
ci:
autoupdate_schedule: monthly
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v5.0.0
hooks:
- id: check-docstring-first
- id: check-executables-have-shebangs
Expand All @@ -14,10 +17,10 @@ repos:
- id: trailing-whitespace
exclude: 'README.md'
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.284
rev: v0.6.9
hooks:
- id: ruff
- repo: https://github.com/psf/black
rev: 23.7.0
rev: 24.8.0
hooks:
- id: black
2 changes: 2 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ recursive-include images *
recursive-include documents *.cff
recursive-include documents *.md
recursive-include neuralplayground *.md

recursive-exclude docs *
78 changes: 60 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@
<!-- ALL-CONTRIBUTORS-BADGE:END -->

# NeuralPlayground


## *A standardised environment for the hippocampus and entorhinal cortex models.* <a href="https://githubtocolab.com/SainsburyWellcomeCentre/NeuralPlayground/blob/main/examples/colab_example.ipynb" target="_parent"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/></a>

<div align="center">
<img src="images/NPG_GH-social-preview_white-bg.jpg" alt="NeuralPlayground Logo" width="500"/>
</div>


<img src="../../images/NPG_GH-social-preview_white-bg.jpg" alt="NeuralPlayground Logo" width="500"/>


<!-- TOC -->
- [Introduction](#introduction)
Expand Down Expand Up @@ -95,7 +98,7 @@ pip install NeuralPlayground==0.0.5
```
> **Note**
>
> If you wish to run our implementation of the Tolman-Eichenbaum machine, there are additional dependencies to install. These can be found in the [TEM_README.md](examples/agent_examples/TEM_README.md) file.
> If you wish to run our implementation of the Tolman-Eichenbaum machine, there are additional dependencies to install. These can be found in the [TEM_README.md](https://github.com/ClementineDomine/NeuralPlayground/tree/main/examples/agent_examples/TEM_README.md) file.
### Install for development

Expand Down Expand Up @@ -123,20 +126,15 @@ understanding of the HEC mechanisms. We follow reproducible, inclusive, and coll
All relevant documents can be found in [Documents](https://github.com/ClementineDomine/NeuralPlayground/blob/main/documents/).
### Agent Arena interaction
You can pick an Agent, an Arena of your choice to run a simulation.
arenas and simulations have a simple interface to interact with each other as in [OpenAI gymnasium](https://gymnasium.farama.org/).
You can pick an Agent and an Arena of your choice to run a simulation. Arenas and simulations have a simple interface to interact with each other as in [OpenAI gymnasium](https://gymnasium.farama.org/).
```python
# import an agent based on a plasticity model of grid cells
from neuralplayground.agents import Weber2018
# import a square 2D arena
from neuralplayground.arenas import Simple2D
# Initialise the agent
from neuralplayground.arenas import Simple2D
# Initialize the agent
agent = Weber2018()
# Initialise the arena
# Initialize the arena
arena = Simple2D()
```
To make the agent interact with the arena, a very simple loop can be the following:
Expand All @@ -158,7 +156,7 @@ and [experiment](https://github.com/SainsburyWellcomeCentre/NeuralPlayground/blo
> **Note**
>
> Check our Tolman-Eichenbaum Machine Implementation in
[this branch](https://github.com/ClementineDomine/NeuralPlayground/tree/whittington_2020) (work in progress), you will also need to install [pytorch](https://pytorch.org/) ro run it.</strong>
[this branch](https://github.com/SainsburyWellcomeCentre/NeuralPlayground/blob/main/neuralplayground/agents/whittington_2020.py) (work in progress), you will also need to install [pytorch](https://pytorch.org/) ro run it.</strong>
### Simulation Manager
Expand All @@ -168,7 +166,7 @@ the details in [Simulation Manager](https://github.com/SainsburyWellcomeCentre/N
and [Comparison Board](https://github.com/SainsburyWellcomeCentre/NeuralPlayground/blob/main/examples/comparisons_examples/comparison_from_manager.ipynb) jupyters. In addition,
we have some [default simulations](https://github.com/SainsburyWellcomeCentre/NeuralPlayground/blob/main/neuralplayground/backend/default_simulation.py)
you can try out, for which you don't need to write much code, since they are
implemented using a [SingleSim](https://github.com/SainsburyWellcomeCentre/NeuralPlayground/blob/55085e792f5dc446e0c3a808cd0d9901a37484a8/neuralplayground/backend/simulation_manager.py#L211)
implemented using a SingleSim
class. For example
```python
Expand All @@ -182,7 +180,51 @@ folder with the name you provide, keeping track of any errors and logs. You can
[Simulation Manager](https://github.com/SainsburyWellcomeCentre/NeuralPlayground/blob/main/examples/comparisons_examples/simulation_manager.ipynb)
to run multiple simulations at once, save the results, keep run of each run and possible errors for easy debugging, and other functions.
To make the agent interact with the arena, a very simple loop can be the following:
```python
iterations = 1000
obs, state = arena.reset()
for j in range(iterations):
# Observe to choose an action
action = agent.act(obs)
# Run environment for given action
obs, state, reward = arena.step(action)
# Update agent parameters
update_output = agent.update()
```
This process is the base of our package. We provide a more detailed example in <a href="https://githubtocolab.com/SainsburyWellcomeCentre/NeuralPlayground/blob/main/examples/colab_example.ipynb" target="_parent"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/></a>.
Also, specific examples of how to use each module can be found in [agent](https://github.com/ClementineDomine/NeuralPlayground/tree/main/examples/agent_examples),
[arena](https://github.com/SainsburyWellcomeCentre/NeuralPlayground/blob/main/examples/arena_examples/arena_examples.ipynb)
and [experiment](https://github.com/SainsburyWellcomeCentre/NeuralPlayground/blob/main/examples/experimental_examples/experimental_data_examples.ipynb) jupyter notebooks.
> **Note**
>
> Check our Tolman-Eichenbaum Machine Implementation in
[this branch](https://github.com/SainsburyWellcomeCentre/NeuralPlayground/blob/main/neuralplayground/agents/whittington_2020.py) (work in progress), you will also need to install [pytorch](https://pytorch.org/) ro run it.</strong>
### Simulation Manager
We provide some backend tools to run simulations and compare the results with experimental data in the background,
including some methods to keep track of your runs, and a comparison board to visualise the results. You can check
the details in [Simulation Manager](https://github.com/SainsburyWellcomeCentre/NeuralPlayground/blob/main/examples/comparisons_examples/simulation_manager.ipynb)
and [Comparison Board](https://github.com/SainsburyWellcomeCentre/NeuralPlayground/blob/main/examples/comparisons_examples/comparison_from_manager.ipynb) jupyters. In addition,
we have some [default simulations](https://github.com/SainsburyWellcomeCentre/NeuralPlayground/blob/main/neuralplayground/backend/default_simulation.py)
you can try out, for which you don't need to write much code, since they are
implemented using a SingleSim class. For example
```python
# Import default simulation, which is a SingleSim
from neuralplayground.backend.default_simulation import stachenfeld_in_2d
from neuralplayground.backend.default_simulation import weber_in_2d
stachenfeld_in_2d.run_sim(save_path="my_results")
```
This class allows you to run a simulation with a single line of code, and it will automatically save the results in a
folder with the name you provide, keeping track of any errors and logs. You can also use our
[Simulation Manager](https://github.com/SainsburyWellcomeCentre/NeuralPlayground/blob/main/examples/comparisons_examples/simulation_manager.ipynb)
to run multiple simulations at once, save the results, keep run of each run and possible errors for easy debugging, and other functions.
```python
# Import Simulation Manager
from neuralplayground.backend import SimulationManager
Expand All @@ -199,7 +241,7 @@ my_manager.check_run_status()
To compare the results, use the comparison board described in [Comparison Board](https://github.com/SainsburyWellcomeCentre/NeuralPlayground/blob/main/examples/comparisons_examples/comparison_from_manager.ipynb) jupyter
notebook. With time, we will build an interface for easy model comparison and visualisation of the results!
<img src="images/board_diagram.jpeg" alt="NeuralPlayground Logo" width="500"/>
<img src="../../images/board_diagram.jpeg" alt="NeuralPlayground Logo" width="500"/>
## I want to contribute
Expand All @@ -224,7 +266,7 @@ Before sending a pull request, make sure you have the done following:
3. Followed the [PEP8](https://www.python.org/dev/peps/pep-0008/) and [numpy docstring](https://numpydoc.readthedocs.io/en/latest/format.html) style convention. More details found in [Style Guide](https://github.com/ClementineDomine/NeuralPlayground/tree/main/documents/style_guide.md).
4. Implemented and ran [tests](https://github.com/ClementineDomine/NeuralPlayground/tree/main/neuralplayground/tests).
4. Implemented and ran [tests](https://github.com/SainsburyWellcomeCentre/NeuralPlayground/tree/main/tests).
5. Comment your work.
Expand All @@ -238,7 +280,7 @@ See [Citation](https://github.com/ClementineDomine/NeuralPlayground/blob/main/do
## License
⚖️ [MIT](./LICENSE)
⚖️ [MIT](https://github.com/ClementineDomine/NeuralPlayground/blob/main/LICENSE)
## Contributors
Expand Down
20 changes: 20 additions & 0 deletions docs/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Minimal makefile for Sphinx documentation
#

# You can set these variables from the command line, and also
# from the environment for the first two.
SPHINXOPTS ?=
SPHINXBUILD ?= sphinx-build
SOURCEDIR = source
BUILDDIR = build

# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

.PHONY: help Makefile

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
35 changes: 35 additions & 0 deletions docs/make.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
@ECHO OFF

pushd %~dp0

REM Command file for Sphinx documentation

if "%SPHINXBUILD%" == "" (
set SPHINXBUILD=sphinx-build
)
set SOURCEDIR=source
set BUILDDIR=build

%SPHINXBUILD% >NUL 2>NUL
if errorlevel 9009 (
echo.
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
echo.installed, then set the SPHINXBUILD environment variable to point
echo.to the full path of the 'sphinx-build' executable. Alternatively you
echo.may add the Sphinx directory to PATH.
echo.
echo.If you don't have Sphinx installed, grab it from
echo.https://www.sphinx-doc.org/
exit /b 1
)

if "%1" == "" goto help

%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
goto end

:help
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%

:end
popd
10 changes: 10 additions & 0 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
-e .
linkify-it-py
myst-parser
nbsphinx
pydata-sphinx-theme
setuptools-scm
sphinx
sphinx-autodoc-typehints
sphinx-design
sphinx-sitemap
Loading

0 comments on commit 3351dd8

Please sign in to comment.