← Back to Pull requests

Prefix local variables in the Cython `synapses.pyx` template with underscores (fixes #1906) #1908

Closed
unknown closed this pull request without merging on Oct 28, 2026 15:53 UTC
View on GitHub
unknown unknown commented on Oct 28, 2026 11:57 UTC
Author

Fixes #1906.

The Cython template for synaptic propagation used i as its loop counter, which clashed with the presynaptic index i in on_pre/on_post code. As discussed in the issue, this renames all local variables of synapses.pyx with a leading underscore, so they can't clash with user-defined names:

| Before | After |
|---|---|
| i | _spike_idx |
| num_spikes | _num_spikes |
| synapse_id | _synapse_id |
| spike_data | _spike_data |
| spike_vector | _spike_vector |
| cpp_queue | _cpp_queue |
| capsule | _capsule |

The new names don't appear anywhere else in the Cython runtime or templates, apart from _num_spikes in ratemonitor.pyx, which is compiled as a separate module.

Test

New test_transmission_names_of_template_variables in test_synapses.py (standalone compatible):

  • on_pre="v_post += i"

  • on_post="u_pre += i", with presynaptic indices 5 to 9 only. A clash with the loop counter then makes the loop stop early, so a regression shows up as a test failure instead of a hang. The hang can't be interrupted by pytest-timeout, because the loop is compiled code.

  • synaptic variables called num_spikes, synapse_id, spike_data, spike_vector, cpp_queue and capsule, used in on_pre
  • On macOS (arm64, Apple clang 21.0.0, Python 3.13.15, Cython 3.3.0, numpy 2.5.4):

  • Without the template change, the test fails on cython (v is [0, 0, 0] instead of [0, 1, 2]; u is [0, 0, 0, 0, 0, 5, 0, 0, 0, 0] instead of [0, 0, 0, 0, 0, 5, 6, 7, 8, 9]; Cython reports 'num_spikes' redeclared etc.).

  • With the change, the test passes on numpy, cython and cpp_standalone.

  • Full cython test suite, including long and codegen-independent tests: 56 doctests and 455 codegen-independent tests passed; 316 Cython tests passed, 10 skipped. The only failure was test_spikegenerator_rounding_long hitting the 1 h pytest timeout while running in parallel with the other workers. Run on its own, it passes and takes the same time with and without this change (37:27 vs. 37:20 on master).

  • ruff format --check (v0.14.2) reports no changes.
  • The examples from the issue now give the same results as numpy with cython ([0. 1. 2.] and [2. 4. 6.], the latter finishing in a few seconds).

    Diff: 284 lines (+213 / -71) across 3 files Reviewer: mstimberg Review duration: 235m
    All Vouch review confidence checks passed
    Residual risk 0.16 = Change Risk (0.40) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.40 · 284 lines diff across 3 files
    0.40
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.338
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #1908"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 39.7% (MEDIUM) · Higher = larger blast radius
    39.7%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 15.7% · Safe to merge
    15.7%