Skip to content

Fix significant-duration benchmark to feed cumulative Arias intensity - #247

Merged
lispandfound merged 2 commits into
masterfrom
ai/issue-237
Oct 2, 2026
Merged

lispandfound merged 2 commits into
masterfrom
ai/issue-237

Conversation

@ucgmsim

@ucgmsim ucgmsim Bot commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

Closes #237

What was wrong

significant_duration::significant_duration expects a cumulative Arias
intensity
array (non-decreasing along each row, total in the last
element) — threshold_search binary-searches it. The Python binding
(_significant_duration in src-rust/lib.rs) always computes
cumulative_arias_intensity first.

bench_significant_duration in benches/intensity_benchmarks.rs instead
passed the raw sinusoidal output of generate_waveforms straight into
significant_duration. Those rows go negative and are not monotonic, so:

  • for stations whose last sample is negative or below 1e-10,
    threshold_search took its early 0.0 return and did no work;
  • for the rest, the binary search ran over unsorted data.

The benchmark therefore measured neither the real workload nor a
meaningful path, and left out the cumulative-integration cost that
dominates _significant_duration in practice.

The fix

Extracted the waveform generator and a new
significant_duration_from_waveforms helper (integrate, then search — the
same two steps the Python binding runs) into benches/common.rs, shared
between the benchmark and a new test. bench_significant_duration now
calls the helper inside b.iter, so it measures the full Ds pipeline as
Python uses it, and the benchmark group is renamed to
Significant_Duration_Full_Pipeline to say so.

How the new test shows it

tests/significant_duration_benchmark.rs calls the shared helper on
synthetic waveforms (same generator as the benchmark) and asserts every
station's Ds duration is in (0, total_duration]. Before the fix (i.e.
with the helper calling significant_duration directly on raw waveforms,
as the benchmark used to), this test fails — reproducing exactly the
0.0-duration degeneracy the issue describes:

station 3: expected a Ds duration in (0, 9.995...], got 0; feeding raw
waveforms directly into significant_duration (instead of their cumulative
Arias intensity) collapses this to 0.0 for most stations

After computing cumulative_arias_intensity first, it passes.

What to check

  • benches/common.rs is a new file included into both the bench binary
    (#[path = "common.rs"] mod common;) and the test
    (#[path = "../benches/common.rs"] mod common;) — this is the only way
    to get a real (non-smoke) pass/fail check on benchmark-only code, since
    cargo test --benches just runs criterion's panic-only smoke pass and
    doesn't check output values.
  • No production (src-rust) code changed; this is benchmark/test-only.

Cost $1.59, 15 turns.

🤖 Generated with Claude Code

Closes #237

## What was wrong

`significant_duration::significant_duration` expects a **cumulative Arias
intensity** array (non-decreasing along each row, total in the last
element) — `threshold_search` binary-searches it. The Python binding
(`_significant_duration` in `src-rust/lib.rs`) always computes
`cumulative_arias_intensity` first.

`bench_significant_duration` in `benches/intensity_benchmarks.rs` instead
passed the raw sinusoidal output of `generate_waveforms` straight into
`significant_duration`. Those rows go negative and are not monotonic, so:

- for stations whose last sample is negative or below `1e-10`,
  `threshold_search` took its early `0.0` return and did no work;
- for the rest, the binary search ran over unsorted data.

The benchmark therefore measured neither the real workload nor a
meaningful path, and left out the cumulative-integration cost that
dominates `_significant_duration` in practice.

## The fix

Extracted the waveform generator and a new
`significant_duration_from_waveforms` helper (integrate, then search — the
same two steps the Python binding runs) into `benches/common.rs`, shared
between the benchmark and a new test. `bench_significant_duration` now
calls the helper inside `b.iter`, so it measures the full Ds pipeline as
Python uses it, and the benchmark group is renamed to
`Significant_Duration_Full_Pipeline` to say so.

## How the new test shows it

`tests/significant_duration_benchmark.rs` calls the shared helper on
synthetic waveforms (same generator as the benchmark) and asserts every
station's Ds duration is in `(0, total_duration]`. Before the fix (i.e.
with the helper calling `significant_duration` directly on raw waveforms,
as the benchmark used to), this test fails — reproducing exactly the
`0.0`-duration degeneracy the issue describes:

```
station 3: expected a Ds duration in (0, 9.995...], got 0; feeding raw
waveforms directly into significant_duration (instead of their cumulative
Arias intensity) collapses this to 0.0 for most stations
```

After computing `cumulative_arias_intensity` first, it passes.

## What to check

- `benches/common.rs` is a new file included into both the bench binary
  (`#[path = "common.rs"] mod common;`) and the test
  (`#[path = "../benches/common.rs"] mod common;`) — this is the only way
  to get a real (non-smoke) pass/fail check on benchmark-only code, since
  `cargo test --benches` just runs criterion's panic-only smoke pass and
  doesn't check output values.
- No production (`src-rust`) code changed; this is benchmark/test-only.

_Cost $1.59, 15 turns._

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@ucgmsim ucgmsim Bot added ai-generated Opened by the scheduled Claude jobs ai-fix Bot-written fix that needs review labels Oct 2, 2026
@ucgmsim
ucgmsim Bot requested a review from lispandfound October 2, 2026 14:10
@lispandfound
lispandfound merged commit 2482788 into master Oct 2, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai-fix Bot-written fix that needs review ai-generated Opened by the scheduled Claude jobs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Significant-duration benchmark feeds raw waveforms instead of cumulative Arias intensity

1 participant