Skip to content

fix: raise the waveform-shape ValueError on the native ensemble gradient path - #23

Merged
deepnmr merged 1 commit into
masterfrom
fix/native-waveform-ndim
Oct 22, 2026
Merged

deepnmr merged 1 commit into
masterfrom
fix/native-waveform-ndim

Conversation

@deepnmr

@deepnmr deepnmr commented Oct 22, 2026

Copy link
Copy Markdown
Owner

Summary

Follow-up from #22. On the native (Rust) path, grape_xy_and_gradient on an ensemble problem raised the wrong error for a waveform that is not two-dimensional:

waveform before (native ensemble gradient) after
scalar TypeError: 'numpy.float64' object is not iterable ValueError: waveform must be two-dimensional, got shape ()
1-D same TypeError ValueError: ... got shape (3,)
3-D ValueError: zip() argument 2 is longer than argument 1 ValueError: ... got shape (2, 3, 1)

Every other path (fallback, grape_xy, single problems) already raised the validation ValueError.

Cause: _accelerator._generators_coherent, the cheap coherence pre-gate of the gradient rungs, computed per-channel waveform amplitudes before any shape check. It now declines a non-2-D waveform, so the NumPy path raises its validation error, consistent with _problem_inputs, which already declines waveform.ndim != 2.

Tests

  • test_validation_messages_identical_on_both_paths no longer skips the native comparison for the scalar and 3-D cases. Without the guard both cases fail; with it they pass.
  • Native suite 454 passed; fallback suite (--deselect tests/test_rust_accelerator.py) 438 passed in 58 s; mypy, ruff and ruff format are clean.

…ce pre-gate

The native ensemble gradient path computed per-channel waveform amplitudes in _generators_coherent before any shape check, so a scalar or 1-D waveform raised TypeError ('numpy.float64' object is not iterable) and a 3-D waveform raised an unrelated zip() ValueError, while every other path raised 'waveform must be two-dimensional'. The pre-gate now declines a non-2-D waveform, so the NumPy path raises its validation error on both backends. test_validation_messages_identical_on_both_paths now compares native and fallback messages for the scalar and 3-D cases too (both fail without the guard).
@deepnmr
deepnmr merged commit ddaef96 into master Oct 22, 2026
4 checks passed
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.

1 participant