Fix/correctness - #5
Merged
Merged
Conversation
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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.