Skip to content

Macros to determine the last record for an individual or a simulation#1327

Merged
kylebaron merged 9 commits intomainfrom
last-record
Feb 25, 2026
Merged

Macros to determine the last record for an individual or a simulation#1327
kylebaron merged 9 commits intomainfrom
last-record

Conversation

@kylebaron
Copy link
Collaborator

@kylebaron kylebaron commented Feb 13, 2026

  • FINAL_ROW signals we just advanced to the final row of the output data
  • FINAL_IROW signals we just advanced to the final row of the current individual

Both have been added to the RESERVED word list.

See #1328

prob.rown(crow);
}

this_rec->id(id);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Moved this up for clarity.

double maxtime = a[i].back()->time();

const double maxtime = a[i].back()->time();
const int NNI = dat.inrow(i);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The total row count for "this" individual.

ans(crow,1) = this_rec->time();
ans(crow,0) = id;
ans(crow,1) = tto;
for(unsigned int k=0; k < n_capture; ++k) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Make consistent with main output writing code.

@kylebaron kylebaron requested a review from kyleam February 17, 2026 19:06
Copy link
Contributor

@kyleam kyleam left a comment

Choose a reason for hiding this comment

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

Two non-blocking comments, but looks good to me.

this_rec->id(id);
tto = this_rec->time();

if(icrow==NNI || crow==NN || tto > maxtime) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it correct that this new tto > maxtime condition isn't an essential change, and it just avoids the downstream ->schedule call being a no-op? I removed the condition and the tests still pass.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah; it's probably on the conservative side. I discovered that it was possible for some in consequential events happening after we hit the last official output record for a given individual. For example, we only calculate the end time of an infusion at the time when it starts, not when the dose is scheduled to happen (potentially in the future through addl) and I realized that we are allowing infusions to end after the last output record and the system is advancing to that time. I'm not totally sure what the right thing to do there. I'm guessing we could just decline to schedule the "infusion off" event if it would happen after maxtime. But I didn't want to get into that in this PR.

But you're right ... if maxtime (specific for an individual) is tied to the time when icrow==NNI, then we probably don't event need crow==NN, right? the NN test and the NNI test should both be true on the last record of the data set. I originally had this continue clause in there because crow references a row in the output matrix and you'd get bad behavior in case that count was ever off, so it's sort of fear-based decision :).

Could you test with just icrow==NNI?

      if(icrow==NNI || crow==NN || tto > maxtime) {
        continue;
      }

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Also ... I did open an issue to at least review cases where we can be more careful of turning stuff off.
#1328

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for the details/explanation. Leaning conservative/safe is of course fine by me.

Could you test with just icrow==NNI?

Yes, the tests still all pass on my end with the condition reduced to if(icrow==NNI).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks for checking that. I was almost going to push a commit that removed tto > maxtime, but think I'm going to leave it for now. I still need to fix the issue in #1324 and I think once that is behaving, I can write some check for correctness of the counts. At that point, will go back and see if we can simplify these checks, which I do think we should be able to do.

@kylebaron kylebaron merged commit 93b51e0 into main Feb 25, 2026
7 checks passed
@kylebaron kylebaron deleted the last-record branch February 25, 2026 23:43
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.

2 participants