You are welcome to use AI tools to find bugs in BindsNET and to improve it. A person must stay responsible for the work:
- You are the author. The person who opens the pull request answers for every line in it, whoever or whatever wrote it.
- Read it and run it yourself. Before you open the pull request, read every changed line, run the tests on your own machine, and make sure you can explain the change in your own words.
- No autonomous agents. An AI agent may not open pull requests, push commits or post comments on its own. A pull request stating that no human has reviewed the code is put on hold until its author has.
- Say what you used. Fill in the "AI assistance" section of the pull request template: which tools, and for which parts. A CI check makes sure the section is filled in.
- Answer review questions yourself. The maintainer may ask you about the design of the change. Please answer in your own words, not with AI-generated text (translation and grammar help are fine).
This follows the policies of NumPy (https://numpy.org/devdocs/dev/ai_policy.html) and LLVM (https://llvm.org/docs/AIToolPolicy.html).
To clone this project locally, issue
git clone https://github.com/BindsNET/bindsnet.git # clones bindsnet repositoryin the directory of your choice. This will place the repository's code in a directory titled bindsnet.
Install the project with Poetry (version 2.4.3 is used in CI)
poetry install
poetry run pre-commit installNow you can activate the project environment with eval $(poetry env activate) or run commands with poetry run <command>. For example, poetry run python examples/mnist/conv_mnist.py.
Please make sure the Poetry environment is activated when you commit your files! The git commit command will invoke pre-commit, which is installed with Poetry too. IDEs like PyCharm have plugins for Poetry and will activate the environment automatically.
Run the tests, they all should pass
poetry run pytestNotable changes are recorded in CHANGELOG.md; please add an entry to the
Unreleased section in your pull request.
If your pull request changes any file under bindsnet/, it must add or change a
test that fails on master and passes with your change. The bug-test check
(.github/scripts/fails_before_fix.py) runs the test files you added or changed
twice, once on master's code and once on yours, and fails if none of them goes
from failing to passing. Only a test that runs on master and fails there counts;
a test that cannot even be imported on master (because it imports something your
change adds) shows no bug. The job summary shows how each counted test failed on
master, and a maintainer checks that it is the bug. You can run the same check
locally:
poetry run python .github/scripts/fails_before_fix.py --base master --head HEADA change that is not a bug fix (a refactor, a speed-up, or a new feature) has no
such test; a maintainer then adds the label no-bug-test, and every existing test
must still pass.
The weakened-tests check (.github/scripts/weakened_tests.py) lists every
place where a pull request may make tests pass by changing the tests: a removed or
no longer collected test, fewer checks or exact comparisons, a check that cannot
fail, a new skip or xfail, a new or wider tolerance, changed recorded results
(golden files, operation counts, API snapshot, coverage floor), or a changed file
that decides which tests run (conftest.py, pyproject.toml, pytest.ini,
setup.cfg, tox.ini, .coveragerc, the torch version in poetry.lock). CI runs
pytest with -c pyproject.toml, so other configuration files are ignored there.
The bench check fails when a workload runs more than twice as slow as on master.
Some of these are right, for example regenerating goldens after a real fix. Explain
each one in the pull request; a maintainer reviews them and adds the label
tests-changed-ok. Files listed in .github/CODEOWNERS also need a maintainer's
approval.
Some tests do not check one behaviour; they check that nothing changed. They fail when a change alters simulated results or the public API, even if the change looks harmless. Please do not edit them by hand to make them pass.
-
Golden-output tests (
test/regression/). Small seeded networks are run and their spikes, voltages, traces and weights are compared with stored reference files undertest/regression/. Spikes must match exactly; other values must match to within 1e-6. If your change alters these on purpose (for example, you fixed a formula), the reference files must be regenerated with the script intest/regression/, which refuses to run without--reason "<why the results changed>"and writes that reason into the files. Say in the pull request which files changed and why. -
Public API snapshot (
test/api_surface.json).test/test_api_surface.pyrecords the parameters and defaults of every public class, method and function inbindsnet. If you add, remove, rename or reorder a parameter, or change a default, regenerate it in the same pull request:poetry run python test/regen_api_surface.py --reason "<why the API changed>"The reason is required and is stored in the file. Removing or renaming a parameter can break other people's code, so expect to be asked why.
-
Every-class smoke tests (
test/network/test_all_classes.py). Every node, connection, learning rule, feature, monitor and model class is found automatically and run for a few steps. A new connection class needs an entry inCONNECTION_SPECS(its source and target shapes), a new model needs one inMODEL_SPECS, and a new learning rule needs one inSUPPORTED.FIXED_BUGSholds the reproducers of crashes fixed in 0.3.5; each must keep running without error. -
Operation counts (
test/regression/op_counts.json).test/regression/test_op_counts.pycounts the tensor operations of one learning-rule update, one simulation step and one neuron update on small fixed networks. It fails when a count grows, because more operations per time step usually means slower code. If the extra work is needed, regenerate in the same pull request:poetry run python test/regression/regen_op_counts.py --reason "<why the hot path does more work>" -
Speed comparison (informational). The workflow
Speed comparison (informational)(.github/workflows/bench.yml) times the benchmark workloads on the base and the head of your pull request, alternating ten rounds, and writes a table to the job summary (also downloadable as thebench-abartifact). A workload is flagged SLOWER when the head takes more than 1.25 times as long (median over the rounds) and the lower end of the 95% bootstrap interval of that ratio is above 1. It is not a required check; shared CI machines are noisy, and a maintainer decides.
Fixes that change results can ship in any release, and are always announced. A
correct fix that changes what a simulation produces still changes numbers people have
published, so CHANGELOG.md lists it first, under "Results changes", naming the affected
classes or models. State in the pull request whether your change alters results, and add
that entry. Changes that break user code (a removed or renamed argument, a different
return type) wait for the next minor release (0.4.0).
- Set
versioninpyproject.tomlandCITATION.cff, and move theUnreleasedentries inCHANGELOG.mdunder the new version. - Merge to
master, then publish a GitHub Release whose tag equals that version. .github/workflows/publish.ymlbuilds the package, checks that the tag matches thepyproject.tomlversion, and uploads to PyPI through trusted publishing (no token). It can also be started by hand from the Actions tab.
A version number can be uploaded to PyPI only once, even after deletion.
All development should take place on a branch separate from master. To create a branch, issue
git branch [branch-name] # create new branchreplacing [branch-name] with a simple and memorable name of choice; e.g., git branch dan. Switch to the newly created branch using
git checkout [branch-name] # switch to a different branch of the repositoryNote: Issue git branch with no arguments to list all branches currently being tracked, with an asterisk next to the currently used branch; e.g.,
$ git branch # list all branches and indicate current branch
* dan
devel
hananel
masterIf new branches have been created on the remote repository, you may start tracking them with git pull --all, and check them out using git checkout [branch-name], as before. git branch -a will list all locally tracked branches, and well as list all remote branches (which can be checked out!).
After making changes to the repository, issue a git status command to see which files have been modified. Then, use
git add [file-name(s) | -A] # add modified or newly created filesto add one or more modified files (file-name(s)), or all modified files (-A or --all). These include newly created files. Issue
pre-commit run -ato run the pre-commit tool that will automatically format your code with black. Issue
git commit -m "[commit-message]" # Useful messages help when reverting / searching through history to "commit" your changes to your local repository, where [commit-message] is a short yet descriptive note about what changes have been made.
Before pushing your changes to the remote repository, you must make sure that you have an up-to-date version of the master code. That is, if master has been updated while you have been making your changes, your code will be out of date with respect to the master branch. Issue
git pull # gets all changes from remote repository
git merge master # merges changes made in master branch with those made in your branchand fix any merge conflicts that may have resulted, and re-commit after the fix with
git commit # no -m message needed; merge messages are auto-generatedPush your changes back to the repository onto the same branch you are developing on. Issue
git push [origin] [branch-name] # verbose; depends on push.default behavior settingsor,
git push # concise; again, depends on push.default behaviorwhere [origin] is the name of the remote repository, and [branch-name] is the name of the branch you have developed on.
Note: See push.default for more information.
To merge your changes into the master branch (the definitive version of the project's code), open a pull request on the webpage of the project. You can select the base branch (typically master, to merge changes into the definitive version of the code) and the compare branch (say, dan, if I added a new feature locally and want to add it to the project code). You may add an optional extended description of your pull request changes. If there are merge conflicts at this stage, you may fix these using GitHub's pull request review interface.
Assign reviewer(s) from the group of project contributors to perform a code review of your pull request. If the reviewer(s) are happy with your changes, you may then merge it in to the master branch. Code review is crucial for the development of this project, as the whole team should be held accountable for all changes.