Skip to content

Speed up Parameters copy/set_transmits and fix compute_time_to_peak - #656

Merged
wesselvannierop merged 11 commits into
mainfrom
feature/parameters-speedup
Oct 21, 2026
Merged

wesselvannierop merged 11 commits into
mainfrom
feature/parameters-speedup

Conversation

@wesselvannierop

@wesselvannierop wesselvannierop commented Oct 16, 2026 •

Copy link
Copy Markdown
Collaborator

Changes

  • Faster Parameters.copy() / set_transmits: the dependents search is now cached per class, since the dependency graph doesn't change. Without the cache, copy() of a full Parameters took about a second.
  • Fixed compute_time_to_peak: demodulate ran the Hilbert transform over the size-1 channel axis instead of the time axis, so t_peak came from argmax(|waveform|) rather than the envelope peak. Added a sine-carrier test case that catches this.
  • Batched and simplified compute_time_to_peak: it now handles a stack of waveforms in a single call, with either one center frequency or one per waveform.

Breaking

  • Removed compute_time_to_peak_stack. Use compute_time_to_peak instead.
  • Parameters.t_peak values estimated from waveforms_two_way change wherever the carrier peak doesn't coincide with the envelope peak.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Enhancements

    • Improved ultrasound peak-time calculations for individual waveforms and waveform stacks.
    • Supports both shared and per-waveform center frequencies, with validation for incompatible frequency inputs.
    • Parameter-derived values now update more reliably when related inherited parameters change.
    • Improved efficiency by caching parameter dependencies independently for each parameter type.
  • Bug Fixes

    • Corrected peak-time calculation behavior for two-way waveforms.

wesselvannierop and others added 3 commits October 16, 2026 15:14
Memoise the dependents search per class, since the dependency graph is
fixed; the uncached recursive rescan made copy() of a full Parameters
cost about a second. Batch compute_time_to_peak_stack into one call
instead of looping per waveform.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
compute_time_to_peak now takes a scalar or per-waveform center frequency
for a stack of waveforms, so the stack variant is removed from the API.

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

coderabbitai Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 369d1ead-40cd-4eae-b573-57dd522fc8f9
📥 Commits

Reviewing files that changed from the base of the PR and between 884d7c7 and 7dee98d.

📒 Files selected for processing: 5
  • tests/test_operations.py
  • tests/test_parameters.py
  • zea/func/ultrasound.py
  • zea/internal/parameters.py
  • zea/parameters.py

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review.

Walkthrough

The peak-time utility now handles waveform stacks and per-waveform center frequencies. Parameters.t_peak and tests use the updated utility. Parameter dependency traversal now caches class-level results.

Changes

Peak-Time Calculation

Layer / File(s) Summary
Batched peak-time calculation
zea/func/ultrasound.py, zea/func/__init__.py, zea/parameters.py, tests/test_operations.py
compute_time_to_peak processes waveforms along the sample axis and returns peak-envelope times. The separate stack helper is removed. Parameters.t_peak and tests use the updated function. The existing fallback remains unchanged.

Parameter Dependency Traversal

Layer / File(s) Summary
Cached class dependents
zea/internal/parameters.py
_find_all_dependents delegates traversal to class-level methods. The traversal caches each target’s transitive dependents and uses a shared seen set.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Suggested reviewers: tristan-deep

Merge Risk: ⚪ Minimal · up to 7dee9

The change caches parameter dependency lookups and makes peak-time calculation use the envelope, including for waveform stacks. No concrete merge-blocking risk was found.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 20 functions across 5 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title accurately identifies both main changes: caching dependency discovery to speed up Parameters operations and fixing compute_time_to_peak behavior.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Oct 16, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

@wesselvannierop
wesselvannierop marked this pull request as ready for review October 19, 2026 06:56
@wesselvannierop
wesselvannierop requested review from a team and benluijten and removed request for a team October 19, 2026 08:56
@wesselvannierop wesselvannierop added bug Something isn't working efficiency Improvements made regarding code or tests efficiency labels Oct 19, 2026
@wesselvannierop wesselvannierop added the status: review needed Ready for maintainer or peer review/merge label Oct 20, 2026
_collect_dependents only scanned cls.__dict__, so subclasses of a parameters
class (such as the deprecated Scan) found no dependents and never invalidated
their cached properties. The memoised lookup made that permanent per class.
It is part of the public zea.func API, so removing it outright breaks
existing imports. Forward it to compute_time_to_peak, which now handles
stacks itself.
_find_all_dependents already returns every direct and indirect dependent,
but _invalidate recursed into each of them again, re-walking the subtree
for every node on each __setattr__.
A size-1 frequency is treated as a scalar, so a single waveform keeps
returning a scalar. A per-waveform frequency must match the waveforms'
leading shape; mismatches now raise a clear ValueError instead of
silently broadcasting or failing deep inside the backend.
functools.cache on the classmethod kept every parameters class it had seen
alive for the lifetime of the process. Store the memo in a per-class dict,
created in __init_subclass__, so it is freed together with the class.
The instance method had become a one-line wrapper around the memoised
classmethod; make _find_all_dependents itself the cached classmethod.
@tristan-deep
tristan-deep self-requested a review October 20, 2026 20:53

@tristan-deep tristan-deep left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nice, is giving me about a 100x speedup for a common Parameters.copy(). Pushed some minor clean-up commits too.

@wesselvannierop
wesselvannierop merged commit d9e1620 into main Oct 21, 2026
15 checks passed
@wesselvannierop
wesselvannierop deleted the feature/parameters-speedup branch October 21, 2026 08:14
@tristan-deep tristan-deep mentioned this pull request Nov 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working efficiency Improvements made regarding code or tests efficiency status: review needed Ready for maintainer or peer review/merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants