Skip to content

fix: cover negative times in Data::expand grid - #384

Open
mhovd wants to merge 2 commits into
mainfrom
fix/expand-negative-times
Open

mhovd wants to merge 2 commits into
mainfrom
fix/expand-negative-times

Conversation

@mhovd

@mhovd mhovd commented Oct 16, 2026

Copy link
Copy Markdown
Collaborator

Bug: Data::expand started its grid at t = 0 and keyed times as u64 microseconds. Negative times got no grid points, and they saturated to 0, which also suppressed the grid point at t = 0.

Rationale: Dosing histories before t = 0 are a normal TDM setup. Predictions should start at the first event, so initial conditions are applied there, and stay on a shared grid of multiples of idelta from 0.

Fix: Use signed microseconds. If an occasion's first event is before 0, start the grid there and continue on multiples of idelta from 0. Data with no negative times is unchanged. Also fixes two clippy lints from a newer toolchain.

🤖 Generated with Claude Code

The expand grid started at 0 and keyed times as u64 microseconds, so
negative times produced no grid and collided at 0. Use signed
microseconds and start at the first event when it is before 0, then
continue on multiples of idelta from 0.

Also fix two clippy lints flagged by a newer toolchain.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings October 16, 2026 10:02
@mhovd

mhovd commented Oct 16, 2026

Copy link
Copy Markdown
Collaborator Author

In my usecases, I will often have time = 0 at the current day, so if I had observations in the past then I would not get predictions for it. This fixes that, which should also make BestDose more flexible.

@codecov-commenter

codecov-commenter commented Oct 16, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 99.27536% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 84.80%. Comparing base (a2203f2) to head (d66463a).

Files with missing lines Patch % Lines
src/data/structs.rs 99.27% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #384      +/-   ##
==========================================
+ Coverage   84.75%   84.80%   +0.05%     
==========================================
  Files          78       78              
  Lines       35818    35950     +132     
==========================================
+ Hits        30356    30487     +131     
- Misses       5462     5463       +1     
Files with missing lines Coverage Δ
src/optimize/parameters.rs 0.00% <ø> (ø)
src/data/structs.rs 92.94% <99.27%> (+0.84%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Rounding the initial negative timestamp can move predictions across a dose boundary or change simulation initialization time.

1 open finding
What changed in this PR

Updates Data::expand to cover negative-time dosing histories while keeping later grid points aligned to zero.

Changes:

  • Uses signed microseconds and starts negative-time grids at the earliest event.
  • Adds regression tests for negative-time expansion.
  • Cleans up two lint patterns.
File Description
src/​optimize/​parameters.rs Removes a blank line after documentation.
src/​data/​structs.rs Updates grid generation, documentation, and tests.
src/​data/​parser/​pmetrics/​tests.rs Uses next_back() for final-header checks.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/data/structs.rs Outdated
The seed point at a negative first event used the rounded microsecond
key, which could move it across the first dose or before the
simulation start. Use the exact time and start the aligned grid
strictly after it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

🐰 Bencher Report

Projectpharmsol
Branchfix/expand-negative-times
Testbedmhovd-pgx

⚠️ WARNING: Truncated view!

The full continuous benchmarking report exceeds the maximum length allowed on this platform.

🚨 1 Alert

🐰 View full continuous benchmarking report in Bencher

This branch has not been deployed

No deployments
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.

3 participants