Skip to content

fix(dyn/synapses): DualExp equal-tau + STP per-neuron reset#847

Merged
chaoming0625 merged 1 commit into
masterfrom
fix/audit-20260619-dyn-synapses
Jun 18, 2026
Merged

fix(dyn/synapses): DualExp equal-tau + STP per-neuron reset#847
chaoming0625 merged 1 commit into
masterfrom
fix/audit-20260619-dyn-synapses

Conversation

@chaoming0625

@chaoming0625 chaoming0625 commented Jun 18, 2026

Copy link
Copy Markdown
Member

Fresh review of brainpy/dyn/{synapses,projections}. Three High fixes:

  • DualExpon raised ZeroDivisionError/NaN when tau_rise == tau_decay; now uses the e/tau limit element-wise (matches Alpha).
  • DualExponV2 silently produced zeros/NaN for equal taus; now raises a clear ValueError pointing to bp.dyn.Alpha.
  • STP.reset_state crashed for a per-neuron array U (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:

  • Handle DualExpon synapses with equal rise and decay time constants without crashes or NaNs by using a well-defined alpha-function limit.
  • Make DualExponV2 explicitly reject equal-tau configurations with a clear error message instead of producing invalid or silent-zero outputs.
  • Allow STP synapses to reset correctly when the release probability U is provided as a per-neuron array, including in batched modes.

Documentation:

  • Add an audit report documenting identified and previously fixed issues in dyn/synapses and dyn/projections, including rationale for recorded-but-unfixed items.

Tests:

  • Add regression tests covering DualExpon equal-tau behaviour, DualExponV2 equal-tau error handling, and STP reset and dynamics with scalar and per-neuron U configurations.

- 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
@chaoming0625 chaoming0625 merged commit b78d61b into master Jun 18, 2026
1 of 4 checks passed
@sourcery-ai

sourcery-ai Bot commented Jun 18, 2026

Copy link
Copy Markdown

Reviewer's Guide

Fixes 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

Change Details Files
Handle DualExpon equal tau_rise == tau_decay robustly and clarify DualExponV2 behaviour.
  • Refactored computation of the DualExpon input-scaling coefficient a into a dedicated helper that uses an algebraically stable closed form and an e/tau L’Hôpital limit for equal taus.
  • Updated DualExpon.init to use the new helper instead of the previous A-based expression that suffered from division-by-zero and NaN when tau_rise == tau_decay.
  • Extended the dual-exponential peak-normalizer helper to detect tau_rise == tau_decay when A is auto-computed and raise a clear ValueError explaining that DualExponV2 is singular in that regime and pointing users to Alpha or explicit A.
brainpy/dyn/synapses/abstract_models.py
Fix STP.reset_state to support per-neuron array U while preserving batched behaviour.
  • Changed STP.reset_state to initialise u and then broadcast-multiply by U instead of using Variable.fill_, which only accepts scalar fills.
  • Ensured the new initialisation works both for scalar U and heterogeneous per-neuron U in batched and non-batched modes.
brainpy/dyn/synapses/abstract_models.py
Add regression tests for DualExpon equal-tau behaviour and STP per-neuron U, and document the broader synapse/projection audit.
  • Added unit tests that cover DualExpon equal-tau construction, numerical behaviour matching a normalized alpha function, and DualExponV2 raising a clear ValueError for equal taus.
  • Added unit tests verifying that STP supports array-valued U at reset, integrates without NaNs for heterogeneous U, and preserves existing scalar-U batched behaviour.
  • Added a markdown document capturing the 2026-06-19 dyn/synapses and dyn/projections audit results, including both fixed and recorded-only issues.
brainpy/dyn/synapses/abstract_models_test.py
docs/issues-found-20260619-dyn-synapses.md

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've left some high level feedback:

  • 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.
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`.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@github-actions github-actions Bot added documentation Improvements or additions to documentation tests labels Jun 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant