Skip to content

fix: superposition converges instead of hanging when tlast < tau with auc.type "AUClast" - #588

Open
billdenney wants to merge 1 commit into
mainfrom
580-superposition-infinite-loop
Open

fix: superposition converges instead of hanging when tlast < tau with auc.type "AUClast"#588
billdenney wants to merge 1 commit into
mainfrom
580-superposition-infinite-loop

Conversation

@billdenney

Copy link
Copy Markdown
Member

Fixes #580.

The steady-state loop's zeros guard reset the convergence tolerance every iteration, so structural zeros from auc.type = "AUClast"/"AUCall" tail handling (when a subject's tlast < tau) made n.tau = Inf loop forever. The tolerance logic now distinguishes zeros that can still accumulate (previous behavior kept) from zeros originating after tlast, which can never become nonzero — those converge on the nonzero concentrations with a warning naming the persisting zeros, tlast, and auc.type. A generous 10,000-interval cap errors informatively as a backstop.

Verification: nine reference results (AUCinf steady state, finite n.tau, dose-scaled, multi-subject) are byte-identical before/after, verified by stash-toggling the source; the formerly-hanging Theoph case now returns in ~0.05 s with the expected warning; the cap error path is exercised in tests. Full superposition + TSS test files pass.

🤖 Generated with Claude Code

… auc.type AUClast

With auc.type="AUClast" (or "AUCall"), concentrations after tlast
extrapolate as exactly zero, so when tlast < tau the superposed profile
keeps structural zeros (for example at time 0 and tau) at steady-state.
The zero-concentration guard in the steady-state loop reset the
convergence tolerance whenever any concentration was zero, on the
assumption that all values eventually become nonzero, so
superposition() with the default n.tau=Inf looped forever (issue 580).
Two of the twelve Theoph subjects have tlast < 24, so a
superposition(conc_obj, tau=24, auc.type="AUClast") call on that
dataset hung.

Now, once a completed dosing interval draws all of its concentrations
from times after tlast, any remaining zero concentration can never
become nonzero, so steady-state is assessed on the nonzero
concentrations only, and a warning explains that zero concentrations
remain in the steady-state profile.  Zeros that can still accumulate
from later dosing intervals keep the previous guard behavior, so all
previously-converging cases are unchanged (verified byte-identical
before and after the fix for AUCinf steady-state on all Theoph
subjects, finite-n.tau AUClast, and the documented multi-dose cases).
A generous 10000-interval backstop now raises an informative error
instead of looping forever if steady-state cannot be reached.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.

superposition() never returns with auc.type = "AUClast" when a subject's tlast < tau (infinite loop at default n.tau = Inf)

1 participant