Skip to content

fix(dyn/neurons): CondNeuGroup synaptic-current scaling (1000x attenuation)#842

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

fix(dyn/neurons): CondNeuGroup synaptic-current scaling (1000x attenuation)#842
chaoming0625 merged 1 commit into
masterfrom
fix/audit-20260619-dyn-neurons

Conversation

@chaoming0625

@chaoming0625 chaoming0625 commented Jun 18, 2026

Copy link
Copy Markdown
Member

Fresh review of brainpy/dyn/{neurons,channels,ions}.

HighCondNeuGroup scaled incoming synaptic current by the membrane-area factor 1e-3/A, a silent 1000x attenuation of synaptic drive whenever A != 1e-3. Synaptic input is already a current density and is now injected unscaled via the derivative (matching CondNeuGroupLTC); external injected current stays correctly density-converted.

Prior-audit channel/neuron findings (HH/Markov NaN at voltage singularity, etc.) were verified already-fixed. Regression tests added (263 passed in-scope). Findings: docs/issues-found-20260619-dyn-neurons.md.

Summary by Sourcery

Fix synaptic current density scaling in CondNeuGroup and document neuron/channel audit findings.

Bug Fixes:

  • Correct CondNeuGroup synaptic-current handling so synaptic inputs are treated as current densities and no longer attenuated by the membrane-area scaling factor.
  • Ensure external injected currents in CondNeuGroup continue to be correctly converted from absolute current to current density.

Enhancements:

  • Align CondNeuGroup synaptic handling semantics with CondNeuGroupLTC by injecting precomputed synaptic current density directly into the membrane potential derivative.

Documentation:

  • Add an audit report documenting prior neuron/channel issues, their fix status, and remaining low-priority findings in the dyn neurons/channels/ions modules.

Tests:

  • Add regression tests verifying CondNeuGroup synaptic current scaling matches CondNeuGroupLTC and that external input scaling remains correct.

… by 1e-3/A

CondNeuGroup scaled incoming synaptic current by the membrane-area factor
1e-3/A (a 1000x attenuation whenever A != 1e-3); synaptic input is already a
current density and must be injected unscaled via the derivative, matching
CondNeuGroupLTC. (High)

Findings recorded in docs/issues-found-20260619-dyn-neurons.md
@chaoming0625 chaoming0625 merged commit ee61019 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 a 1000x attenuation bug in CondNeuGroup synaptic current handling by treating synaptic inputs as current densities in the derivative (consistent with CondNeuGroupLTC), adds regression tests to lock in the behavior and ensure external injected currents remain correctly scaled, and documents audit findings for neuron/channel/ion modules, including one high-priority bug fix and several low-priority style/documentation issues.

Sequence diagram for CondNeuGroup synaptic-current scaling fix

sequenceDiagram
  actor Sim
  participant CondNeuGroup
  participant CondNeuGroupLTC
  participant SynInputs
  participant Channels

  Sim->>CondNeuGroup: update(x_external)
  CondNeuGroup->>SynInputs: sum_current_inputs(V, init=0.)
  SynInputs-->>CondNeuGroup: syn_density
  CondNeuGroup->>CondNeuGroup: _syn_current = syn_density
  CondNeuGroup->>CondNeuGroupLTC: update(x_external)
  CondNeuGroupLTC->>CondNeuGroupLTC: x = x * (1e-3 / A)
  CondNeuGroupLTC->>CondNeuGroup: derivative(V, t, x)
  CondNeuGroup->>CondNeuGroup: I = x + _syn_current
  CondNeuGroup->>Channels: current(V)
  Channels-->>CondNeuGroup: channel_density
  CondNeuGroup->>CondNeuGroup: I = I + channel_density
  CondNeuGroup-->>CondNeuGroupLTC: I / C
  CondNeuGroupLTC-->>Sim: updated state
Loading

File-Level Changes

Change Details Files
Corrected CondNeuGroup synaptic current handling to treat synaptic inputs as unscaled current densities while preserving external current density conversion semantics.
  • Introduced an instance attribute to cache synaptic current density evaluated at the pre-update membrane potential so it can be injected directly in the derivative.
  • Updated the derivative to sum the cached synaptic density with external injected current (already converted to density) and channel currents before dividing by capacitance.
  • Changed update to compute synaptic current density with zero initial external input and pass only the external current to the parent update, avoiding double- or mis-scaling of synaptic inputs.
brainpy/dyn/neurons/hh.py
Added regression tests ensuring CondNeuGroup and CondNeuGroupLTC apply synaptic and external currents with consistent density scaling.
  • Added a helper to step neurons one timestep under a constant synaptic current density for both CondNeuGroup and CondNeuGroupLTC.
  • Added a test that compares one-step voltage changes under synaptic drive for CondNeuGroup and CondNeuGroupLTC at non-default membrane area values and checks they match the expected dt * I / C relation.
  • Added a test that confirms external injected currents to CondNeuGroup remain scaled by the 1e-3/A factor when converted from absolute current to density.
brainpy/dyn/neurons/hh_test.py
Documented neuron/channel/ion audit findings, including the CondNeuGroup bug and several recorded-only low-priority issues, in a new markdown report.
  • Created a detailed audit report summarizing cross-check status against previous findings and confirming several earlier bugs are already fixed.
  • Described the CondNeuGroup synaptic scaling issue, its impact, reproduction steps, implemented fix, and associated tests.
  • Recorded multiple low-priority style and documentation issues in channels and ions modules without changing code.
docs/issues-found-20260619-dyn-neurons.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:

  • In CondNeuGroup, _syn_current is defined as a class-level attribute and then mutated per instance; consider initializing it in __init__ (or another instance-level setup) to avoid accidental cross-instance sharing or confusion for static analyzers.
  • The new CondNeuGroup.update/derivative coupling relies on update being called before derivative so _syn_current is set; if derivative can be used independently (e.g., by analysis tools), consider guarding against stale _syn_current or computing synaptic density lazily inside derivative when needed.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `CondNeuGroup`, `_syn_current` is defined as a class-level attribute and then mutated per instance; consider initializing it in `__init__` (or another instance-level setup) to avoid accidental cross-instance sharing or confusion for static analyzers.
- The new `CondNeuGroup.update`/`derivative` coupling relies on `update` being called before `derivative` so `_syn_current` is set; if `derivative` can be used independently (e.g., by analysis tools), consider guarding against stale `_syn_current` or computing synaptic density lazily inside `derivative` when needed.

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