fix(dyn/synapses): DualExp equal-tau + STP per-neuron reset#847
Merged
Conversation
- DualExpon raised ZeroDivisionError / produced NaN when tau_rise == tau_decay; compute the normalization with the e/tau limit element-wise (High) - DualExponV2 silently output zeros/NaN for equal taus; raise a clear ValueError in the auto-normalizer pointing to bp.dyn.Alpha (High) - STP.reset_state crashed for a per-neuron array U (Variable.fill_ needs a scalar); broadcast U instead (High) Findings recorded in docs/issues-found-20260619-dyn-synapses.md
Reviewer's GuideFixes equal time-constant handling for dual-exponential synapses and makes STP reset support per-neuron U, plus adds regression tests and an audit findings doc for dyn/synapses and projections. File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- The exact equality check
self.tau_rise == self.tau_decayin_dual_exp_a(and_format_dual_exp_A) may behave unintuitively for non-integer or JIT-transformed parameters; consider using a small tolerance (or documenting that only exactly equal taus trigger the alpha-limit behavior/error) to make the edge case more predictable. - In
STP.reset_state, the broadcasting viaself.u.value = self.u.value * self.Uworks but is a bit opaque; using an explicit broadcast (e.g.,bm.broadcast_towith the target shape or a helper that mirrorsinit_variable) would make the intended semantics with batched modes and heterogeneousUclearer and less error-prone if shapes change later. - The new
_dual_exp_ahelper partially duplicates the logic in_format_dual_exp_Aand relies on the caller to know when each path is valid; consider centralizing the dual-exp normalization (including the equal-tau handling and L’Hôpital limit) into a single, well-documented function to avoid future divergence betweenDualExponandDualExponV2.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The exact equality check `self.tau_rise == self.tau_decay` in `_dual_exp_a` (and `_format_dual_exp_A`) may behave unintuitively for non-integer or JIT-transformed parameters; consider using a small tolerance (or documenting that only *exactly* equal taus trigger the alpha-limit behavior/error) to make the edge case more predictable.
- In `STP.reset_state`, the broadcasting via `self.u.value = self.u.value * self.U` works but is a bit opaque; using an explicit broadcast (e.g., `bm.broadcast_to` with the target shape or a helper that mirrors `init_variable`) would make the intended semantics with batched modes and heterogeneous `U` clearer and less error-prone if shapes change later.
- The new `_dual_exp_a` helper partially duplicates the logic in `_format_dual_exp_A` and relies on the caller to know when each path is valid; consider centralizing the dual-exp normalization (including the equal-tau handling and L’Hôpital limit) into a single, well-documented function to avoid future divergence between `DualExpon` and `DualExponV2`.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
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.
Fresh review of
brainpy/dyn/{synapses,projections}. Three High fixes:DualExponraisedZeroDivisionError/NaNwhentau_rise == tau_decay; now uses thee/taulimit element-wise (matchesAlpha).DualExponV2silently produced zeros/NaN for equal taus; now raises a clearValueErrorpointing tobp.dyn.Alpha.STP.reset_statecrashed for a per-neuron arrayU(Variable.fill_needs a scalar); now broadcasts.Prior-audit synapse/projection bugs (STP u growth, double-comm, STDP, PoissonInput std) verified already-fixed. In-scope: 181 passed. Findings:
docs/issues-found-20260619-dyn-synapses.md.Summary by Sourcery
Fix edge-case behaviour of dual-exponential synapses and STP reset, and record audit findings for dyn/synapses and projections.
Bug Fixes:
Documentation:
Tests: