Fix audited correctness, API-drift & edge-case issues; add regression+coverage suite#830
Merged
Merged
Conversation
A senior architecture / JAX / BrainX-ecosystem audit of the brainpy package surfaced 131 distinct issues (26 Critical, 53 High, 36 Medium, 16 Low), documented in docs/issues-found-20260618.md. The dominant theme is ecosystem-migration drift: BrainPy 2.7.x was rebased onto brainstate 0.5, brainevent 0.1, braintools, and JAX >=0.10, and many code paths were not updated in lockstep, producing silent numerical errors and crash-on-first-use bugs. Notable fixes: - math: correct Array pytree unflatten under abstract eval (object.__new__ bypass), restoring eval_shape / for_loop / scan over Array. - dyn/channels: remove removable exp/(exp-1) gating singularities via an _exprel helper so HH/TM/Ba sodium & potassium rates stay finite at the singular membrane voltages. - optim: fix SM3 hyperparameter init order (base __init__ reads momentum) and torch-style keepdim -> keepdims. - connect: fix FixedProb zero-density truncation (int(round(.)) ) and the contradictory include_self guard for rectangular populations. - integrators: remove dead srk_strong module (generated-code syntax error, unregistered, unused) per L-12. - delay/pre_syn_post: correct ring-buffer modulo indexing. Adds a comprehensive regression + coverage test suite under tests/audit/ (1022 tests, 93% aggregate line coverage over the 74 changed files) that locks in every fix and pins remaining deep latent bugs with explicit pytest.raises regression tests. Adds a coverage badge to README.
There was a problem hiding this comment.
Sorry @chaoming0625, your pull request is larger than the review limit of 150000 diff characters
chaoming0625
added a commit
that referenced
this pull request
Jun 18, 2026
- tests/audit/test_object_transform_fixes.py: #830 added M-06 asserting a None-returning while_loop body raises, but that broke the canonical brainpy idiom (body mutates Variable state, returns None) used by real models like SpikeTimeGroup. Now that the wrapper threads operands through unchanged, rewrite the test to assert that idiom works (state-driven termination) and update the module docstring. - conftest.py (new, repo root): force matplotlib onto the non-interactive Agg backend for both test roots (tests/ and brainpy/) so analysis tests that call pyplot.show() never open GUI windows, locally or in CI. - CI-models.yml: set MPLBACKEND=Agg on the pytest steps to match CI.yml.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
A senior architecture / JAX / BrainX-ecosystem audit of the
brainpypackage surfaced 131 distinct issues (26 Critical, 53 High, 36 Medium, 16 Low), documented indocs/issues-found-20260618.md. The dominant theme is ecosystem-migration drift: BrainPy 2.7.x was rebased ontobrainstate0.5,brainevent0.1,braintools, and JAX ≥0.10, and many code paths were not updated in lockstep — producing silent numerical errors and crash-on-first-use bugs concentrated in the optimizer/loss/scheduler stack, surrogate-gradient & synapse/plasticity code, sparse/event operators, FDE/adaptive integrators, and normalization layers.This PR fixes those issues and adds a comprehensive regression + coverage test suite that locks in every fix.
Notable fixes
Arraypytree unflatten under abstract eval (object.__new__bypass), restoringjax.eval_shape/for_loop/scanoverArray.exp/(exp-1)gating singularities via an_exprelhelper so HH/TM/Ba sodium & potassium rates stay finite (and differentiable) at the singular membrane voltages.__init__readsself.momentumwhile registering train vars) and a torch-stylekeepdim→keepdims.FixedProbzero-density truncation (int(round(.))) and a contradictoryinclude_selfguard for rectangular populations.srk_strongmodule (generated-code syntax error, unregistered, unused) per finding L-12.math,dyn,dynold,dnn,integrators,analysis,losses,runners, andconnect.Testing
tests/audit/, all passing.coverage7.14.1).pytest.raisesregression tests rather than silently worked around.README.md.Full per-issue detail and severities are in
docs/issues-found-20260618.md.