Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix/correctness - #5

Merged
remislp merged 2 commits into
DCPROGS:masterfrom
remislp:fix/correctness
Aug 3, 2026
Merged

Fix/correctness#5
remislp merged 2 commits into
DCPROGS:masterfrom
remislp:fix/correctness

Conversation

@remislp

@remislp remislp commented Aug 3, 2026

Copy link
Copy Markdown
Member

No description provided.

remislp and others added 2 commits August 2, 2026 21:47
1. popen.maxPopen - five errors in the non-monotonic bisection loop

   A plain agonist-gated mechanism gives a monotonically rising Popen curve,
   so this branch is never entered and the bugs stayed hidden. Adding a fast
   pore blocker makes the curve rise and then fall, which exposes them:

     a. P1 was evaluated at conc instead of conc/fac
     b. conc1 was overwritten by conc*fac, destroying the lower probe point
     c. P2 was evaluated at conc instead of conc*fac
     d. the bracket updates were backwards and used conc1, not the midpoint
     e. nstep was never incremented

   Net effect: P1 == P2 always, so perr == 0 and the loop exited after one
   iteration with no real bisection. Measured on CH82 with a 1 mM fast
   blocker, maxPopen returned 0.90337 where a dense scan finds 0.92695 - a
   2.6 % error in the reported maximum, at the wrong concentration.

   The loop now probes either side of the midpoint, moves the correct bracket
   end, terminates on the concentration tolerance, and returns the midpoint of
   the final bracket.

2. AsymptoticPDFCalculator._calculate_roots - overflow at large tres

   The lower search bound was fixed at -1e6, so |s| * tres exceeded
   ln(float64 max) ~ 709 once tres was above about 0.7 ms.
   exp((QFF - s*I)*tres) then overflowed and inf/nan reached W(s):

     numpy.linalg.LinAlgError: Array must not contain infs or NaNs

   Reproduced with CH82: fine at tres = 700 us (|s|*tres = 700), raises at
   1 ms (1000). The bound is now clamped to -700/tres, and only when the
   default would overflow, so ordinary resolutions keep the full search range.

3. AsymptoticPDFCalculator._bisect_intervals - infinite loop

   Subintervals containing no roots were pushed back onto the work list, so
   they split into two more empty halves for ever. Mechanisms with a single
   open state never returned: CO and CCO both hang, at tres = 0 and at
   tres = 100 us. Zero-root subintervals are now discarded.

Tests
-----
tests/test_popen_maxpopen.py (8 tests) and tests/test_hjc_roots.py (14 tests).
Against the unfixed code 2/8 and 9/14 fail respectively; all pass after the
fix. The five hjclib tests that pass either way are the CH82 multi-open-state
cases, which neither bug affects.

The root-finding tests run each call in a subprocess with a timeout, so a
regression of bug 3 reports a test failure instead of hanging the run.

Co-Authored-By: Claude Opus 5 <[email protected]>
Both are test-only; no library code is touched. Kept separate from the
correctness fixes so it can be dropped independently.

1. test_HJC.py compared a zero eigenvalue with a relative tolerance

   One Q-matrix eigenvalue is mathematically zero and comes out as about
   +-1e-14, its sign depending on the BLAS build. assert_allclose with
   rtol=1e-6 and no atol therefore failed on this machine:

     Mismatch at index [0]: -4.158903441056854e-14 (ACTUAL)
                             6.067797900000000e-14 (DESIRED)

   Both tests in TestExactPDFCalculator failed for this reason alone. The
   comparisons now go through a small helper that adds a tolerance floor of
   1e-9 times the largest element. The smallest genuine eigenvalue in these
   arrays is about 1e2, so the floor cannot mask a real difference.

2. test_popen.py defined test_ideal_curve twice

   The second definition shadowed the first, so the ideal-curve assertions
   never ran at all. The second is the missed-events case, so it is renamed
   to test_HJC_curve. Both now run, and both pass.

Suite goes from 49 passed / 2 failed to 74 passed / 0 failed (the extra
tests are the 22 added with the correctness fixes, plus the one that was
previously shadowed).

Co-Authored-By: Claude Opus 5 <[email protected]>
@remislp
remislp merged commit cf0df11 into DCPROGS:master Aug 3, 2026
@remislp
remislp deleted the fix/correctness branch August 6, 2026 11:05
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