Skip to content

Document and test what the XQRS backsearch skip relies on - #598

Merged
tompollard merged 2 commits into
MIT-LCP:mainfrom
TheNetherWatcher:docs/backsearch-skip-comment
Oct 31, 2026
Merged

tompollard merged 2 commits into
MIT-LCP:mainfrom
TheNetherWatcher:docs/backsearch-skip-comment

Conversation

@TheNetherWatcher

Copy link
Copy Markdown
Contributor

Closes #597.

The skip added in #596 is only correct while two things stay true:

  • _update_noise doesn't change qrs_thr.
  • _update_qrs sets last_qrs_peak_num to the current peak.

This PR:

  • Uses the comment suggested in Document what the XQRS backsearch skip depends on #597 above the skip in _backsearch.
  • Adds test_xqrs_backsearch_skip_assumptions, which runs XQRS on record 100 with a 2-minute low-amplitude gap followed by scaled-down beats (so backsearch actually finds QRS complexes) and checks both properties after every update.

I first tried a test comparing the skip against a full rescan, but it still passed when I broke either property, because the data never hit the case where they matter. The direct check fails for both changes:

  • _update_noise also recalculating qrs_thr → fails
  • _update_qrs setting last_qrs_peak_num = peak_num → fails

No change in behaviour, so no changelog entry. ruff check is clean and pytest -m "not network" passes (83 tests).

The skip added in #596 is only correct while _update_noise leaves qrs_thr
alone and _update_qrs moves last_qrs_peak_num to the current peak. Name
both in the comment and add a test that fails if either changes.

@tompollard tompollard left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks @TheNetherWatcher, this looks good! Checking the two assumptions directly makes sense.

One small optional addition: the comment says the result depends on qrs_thr and last_qrs_ind, but noise_spy only checks qrs_thr.
Checking both would cover the comment fully:

def noise_spy(peak_num):
    qrs_thr, last_qrs_ind = xqrs.qrs_thr, xqrs.last_qrs_ind
    update_noise(peak_num)
    assert (xqrs.qrs_thr, xqrs.last_qrs_ind) == (qrs_thr, last_qrs_ind)

Happy to merge as it is, or with that change.

@TheNetherWatcher

Copy link
Copy Markdown
Contributor Author

Thanks! Good point, I've added it. The noise check now compares (qrs_thr, last_qrs_ind), and it fails if _update_noise changes last_qrs_ind.

@tompollard

Copy link
Copy Markdown
Member

Looks good to me, thanks @TheNetherWatcher!

@tompollard
tompollard merged commit 4bee652 into MIT-LCP:main Oct 31, 2026
18 checks passed
@TheNetherWatcher
TheNetherWatcher deleted the docs/backsearch-skip-comment branch November 1, 2026 06:13
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.

Document what the XQRS backsearch skip depends on

2 participants