Skip to content

IDA consistent IC: dae_init_mode, battery hold, forcing t+, source currents - #3845

Open
nrnhines wants to merge 24 commits into
masterfrom
hines-grok/ida-init
Open

IDA consistent IC: dae_init_mode, battery hold, forcing t+, source currents#3845
nrnhines wants to merge 24 commits into
masterfrom
hines-grok/ida-init

Conversation

@nrnhines

Copy link
Copy Markdown
Member

Summary

Adds optional consistent initialization for the IDA (DASPK) path when models have algebraic constraints, LinearMechanism networks, extracellular capacitance, and discontinuous source currents (steps / PWL / Vector.play).

  • CVode.dae_init_mode (0–3) — default remains 0 (nano-step heuristic). Mode 1/2 use IDACalcIC; mode 3 holds continuous content (LM battery + extracellular / cable) then sets (y') from (C y' = f(y)). Residual failure falls back to the heuristic (unless the three-panel audit is armed).
  • Battery-style content hold — floating LM capacitors, inductor/op-amp lag holds; extracellular (V_m)/layer holds; free algebraic cable ends (CAP list) so electrode current at 0/1 can set absolute levels without fighting continuous content.
  • Forcing (t^+) — classical right-limit value and derivative for continuous Vector.play at reinit; free LM (y') completed from play, LinearMechanism.dforce, or FD of f_callable.
  • Electrode / extracellular seed — mode-3 (y') seed for coupled (c_m+x_c) and multi-layer (x_c) so electrode residual is not left on outer layers; zero-area / end-ri notes and tests.
  • Diagnosticsdae_init_audit three-panel dump, IC path stats, residual classification on mode-3 failure.
  • DocsCVode.dae_init_mode / electrode notes in cvode.rst; LM dforce in linmod.rst.
  • Teststest_ida_init_mode.py, test_ida_source_current.py (E0–E4, ends, Z*, A3/A4 forcing), unit vecplay_tplus, PWLClamp MOD, ctest -R hoctests::test_ida_(init_mode|source_current).

Also includes working handoff GROK-IDA-INIT.md (session notes; density MOD dforce remains parked on a separate branch).

Test plan

  • Local: ctest -R 'hoctests::test_ida_(init_mode|source_current)' (and related IDA suites as available)
  • Local cover-diff on changed IC sources (ninja cover-diff with NRN_ENABLE_COVERAGE + listed files)
  • CI green on this PR
  • Reviewer: confirm default mode 0 behavior unchanged for existing models
  • Optional smoke: mode-3 on a multi-electrode / extracellular model; residual fail → heuristic fallback messaging

nrnhines added 23 commits July 15, 2026 20:10
Add dae_init_mode(0|1|2) to select legacy nano-step heuristic (default),
IDACalcIC(IDA_Y_INIT) with heuristic fallback, or pure IDA_Y_INIT. Soft-fail
sparse factor errors during CalcIC so mode 1 can fall back cleanly. Document
and test pure algebraic LinearMechanism success and series C-R fallback.
…acitors

Replace capacitive couplings with voltage-source constraints that hold
branch Δv and solve the augmented G/B algebraic system. Falls back to the
nano-step heuristic only on failure. Includes unit test for series C–R
current step and docs for mode 3.
Classify C structure: floating caps keep Δv battery stamps; diagonal mass
holds inductor current; one-sided C (OpAmp tau*vk') holds output voltage
and drops the dynamic equation. Add unit tests for op-amp continuous hold
and inductor current hold under dae_init_mode(3).
Hold continuous Vm and xc layer content via stiff springs on the resistive
(cj=0) matrix, then restore holds exactly (allowing algebraic common-mode
when outer xc is zero). Wire into Daspk battery init after LinearMechanism
projection and add a cable+extracellular smoke test.
Diagnostic dump of residual/state before discontinuity, after event,
and after re-init. Arm with dae_init_audit(level, t) for first reinit
at or after t; write to stdout or a file via dae_init_audit_file.

Panel A uses the continuous residual captured at integrator retreat
(interpolate after a step that may overshoot), with continuous play
synchronized to the event time—shared by Vector.play, NetCon, and
at_time—not a re-evaluation after the jump or the raw step endpoint.
Status, architecture, build/test notes, and a starting prompt for new
Grok sessions on hines-grok/ida-init in ~/neuron/nrnida.
Recover continuous y' from the mass equation at fixed projected y instead
of the dteps nano-step companion, so residual WRMS can reach zero on
stiff cases (e.g. SEClamp + tiny cm). Keep nano-step only as residual
fallback; classify algebraic vs near-singular residual eqs on failure;
suppress fallback when an IC audit is armed. Document and test.
Add nrn_vecplay_continuous_tplus matching VecPlayContinuous interpolate
geometry (outgoing slope at knots; linear extrapolation of the last two
points past the end). Expose VecPlayContinuous::forcing_tplus for later IC
use. Document forcing t+ info (1-jet) in cvode.rst and GROK-IDA-INIT;
unit tests for slope extraction oracles.
At each Daspk::init, sample all VecPlayContinuous instances for right-limit
u and classical u' (forcing t+ info / 1-jet), store on Daspk for A2, and
list them in the three-panel IC audit. Add ramp-play hoctest checking
u≈0.5 and u'≈0.5 after the t=1 jump onto the ramp segment.
After C*y'=b-Gy particular seed, adjust y' in null(C) so left-null
constraints Z'G y' = Z'b' hold, with b' from Vector.play slopes mapped
into LinearMechanism b. Fixes series C–R ramp IC (V1'=1, V2'=0.5 when
I=0.5, I'=0.5, R=C=1) without a nano-step.
Add series C–R integration tests for step, slope kink, post-end
extrapolation, flat hold, finitialize first-segment slope, and two-event
iramp-like sequence. Treat t=t0 as outgoing slope for forcing t+ (strict
hold only for t<t0) so finitialize ramps get the correct I'.
Add lm.dforce(callable, bdot) so non-play forcing can supply db/dt for
mode-3 free y' completion. Callable runs at IC time; optional FD of the
force callable when dforce is unset. Audit lists LM dforce/bdot/fd
entries. Tests: sinusoid analytic and FD fallback on series C–R.
Track mode-3 success/fallback and free-y' sources (play, dforce, FD).
Expose CVode.dae_init_stats() for print/reset/Vector fill; include in
statistics(). Audit notes list free-y' sources; fallback messages name
mode 3 vs nano-step explicitly.
Add piecewise-linear electrode stimulus (test-only) and mode-3 coverage for
IClamp/PWL istep, kink, jump-ramp, and E0 Section vs LM play parity. Update
GROK-IDA-INIT for (b) in progress and parked density dforce.
Re-ran test_ida_init_mode.py and isolated A1 ramp + A3 istep/kink suite
under mode 3; no code changes. Handoff notes WP2 done; next is WP3.
…i tests.

Coupled C y'=f seeding now puts electrode current into extracellular mass
(1-layer and multi-layer cumulative F), so mode 3 clears residual for
IClamp/PWL steps with extracellular. Add E1 Section/LM parity and Z0/Z1
LM end-ri() twins; cable zero-area end inject still may nano-step fallback.
Note hoctests::test_ida_source_current (PWLClamp via nrnivmodl hash) and
standalone run instructions; handoff points at C→A→B stack.
Add nrn_cable_battery_ic: hold CAP-list node voltages, free section-end
nodes so electrode at loc 0/1 can set absolute levels; soft-fail if the
cj=0 factor is singular. Pre-evaluate residual so BREAKPOINT/at_time sees
t+ before project. Extracellular Vm holds skip zero-area nodes. Tests
require path_mode=3 for end IClamp/PWL and Z0/Z1 Section+LM.
E2 xc=0 resistive xtral istep (path_mode 3); E3 multi-layer xc>0 istep;
E4 weak/strong xg istep with Vm hold. Completes WP3 topology matrix for
mid-compartment electrode sources.
Expand CVode.dae_init_mode documentation for electrode sources, at_time,
extracellular Vm vs vext, and play/dforce 1-jet use. Fix E2/E* tests to
treat seg.v as transmembrane Vm (vext may jump when xc=0). Handoff notes
nrndc1sim smoke: mode 3 at finitialize; transfer re_init often falls back.
@azure-pipelines

Copy link
Copy Markdown

✔️ a15e968 -> Azure artifacts URL

@codecov

codecov Bot commented Aug 13, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 85.98726% with 176 lines in your changes missing coverage. Please review.
✅ Project coverage is 68.72%. Comparing base (d71477f) to head (a108b2a).

Files with missing lines Patch % Lines
src/nrncvode/nrndaspk.cpp 79.76% 105 Missing ⚠️
src/nrniv/linmod.cpp 89.35% 23 Missing ⚠️
src/nrniv/nrndae.cpp 87.50% 15 Missing ⚠️
src/nrniv/vrecord.cpp 85.00% 9 Missing ⚠️
src/nrniv/linmod1.cpp 63.63% 8 Missing ⚠️
src/nrniv/vecplay_tplus.h 85.71% 7 Missing ⚠️
src/nrnoc/treeset.cpp 89.28% 6 Missing ⚠️
src/nrncvode/cvodeobj.cpp 95.45% 2 Missing ⚠️
src/nrnoc/extcelln.cpp 98.57% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3845      +/-   ##
==========================================
+ Coverage   68.34%   68.72%   +0.37%     
==========================================
  Files         701      704       +3     
  Lines      112265   113470    +1205     
==========================================
+ Hits        76731    77978    +1247     
+ Misses      35534    35492      -42     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions

Copy link
Copy Markdown
Contributor

✔️ a15e968 -> artifacts URL

UBSan aborted LinearMechanism construction: NrnDAE bound references to
optional-null elayer and y0 Vectors. Defer those dereferences until the
pointers are known non-null.

macOS ASan/TSan aborted isolated python -c children because SIP drops
DYLD_INSERT_LIBRARIES. Re-apply NRN_SANITIZER_PRELOAD_* (same pattern as
test_basic.py) so interceptors load before dlopen of libnrniv.
@sonarqubecloud

Copy link
Copy Markdown

@azure-pipelines

Copy link
Copy Markdown

✔️ a108b2a -> Azure artifacts URL

@github-actions

Copy link
Copy Markdown
Contributor

✔️ a108b2a -> artifacts URL

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant