Skip to content

Use explicit ADC conversion in physical writes - #892

Merged
tompollard merged 1 commit into
mainfrom
refactor/explicit-write-adc
Dec 3, 2026
Merged

tompollard merged 1 commit into
mainfrom
refactor/explicit-write-adc

Conversation

@tompollard

Copy link
Copy Markdown
Member

Summary

Extract the ADC conversion from SignalMixin.adc into an array-based helper. Physical writes through _WriteModel now pass their values, formats, gains, and baselines directly to that helper instead of calling the inherited Record.adc method. Record.adc remains a wrapper with the same public behavior.

This is another step toward #866. It does not change the public API or intended file output.

Checks

  • 2,288 offline tests passed; 48 skipped and 23 network tests deselected.
  • The documentation build passed with warnings treated as errors.
  • Ruff check and format check passed.
  • A differential run of 400 generated Record.adc cases matched pre-change main byte for byte as JSON results. It covered uniform and expanded signals, in-place and returned conversions, float32 and float64 inputs, missing samples, and eight storage formats.
  • The existing writer byte fixtures passed. A new test makes SignalMixin.adc fail if a modern physical write calls it.

No changelog entry: this only moves internal conversion logic.

@tompollard tompollard left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is correct, and it can merge. The ADC tests, fixtures and parity tests pass (414 passed, 44 expected skips), as do the offline suite (2,288 passed, 48 skipped), Ruff and all 19 CI checks.

What I checked

  • _adc_values keeps the old in-place behaviour. That's the subtle part of Record.adc. With inplace=True, a float64 uniform array is converted in its own buffer, an expanded list is updated element by element and becomes e_d_signal, and the physical attribute is cleared. Without it, everything is converted on a float64 copy. Both are unchanged.

  • Record.adc compared with main (8a88d1c), including memory sharing. The description's JSON comparison covers values. Since sharing is the part a refactor most easily breaks, I added checks for it. Across 3,000 random calls, uniform and expanded, in-place and returned, I compared:

    • the result's values and dtype;
    • whether the result shares memory with the input, and for expanded data whether it's the same list;
    • whether the input array was modified;
    • which signal attributes are left set, and what's returned.

    The inputs were float16, float32 and float64, with NaNs, values landing exactly half-way between integers, gains from 1e-3 to 12345.678, and every writable format. Every outcome matched main.

  • Performance is unchanged. Alternating runs of 8a88d1c and this branch (100skew, physical, write only) agree within noise: write_record 19.00/20.28 → 18.57/18.71 ms, SignalRead.write 15.59/16.36 → 15.37/15.14 ms and write_signals 31.08/32.42 → 31.20/30.99 ms. Peak memory is identical.

Non-blocking: _adc_values keeps the inplace branches only because Record.adc needs them, since the model always converts on a copy. When the legacy method is eventually the only caller of the in-place mode, that part could move back into Record.adc, leaving the shared function copy-only. No need to do it now.

@tompollard
tompollard merged commit b6ed4d1 into main Dec 3, 2026
19 checks passed
@tompollard
tompollard deleted the refactor/explicit-write-adc branch December 3, 2026 17:37
tompollard added a commit that referenced this pull request Dec 3, 2026
## Summary

Move the field validation rules out of `Record.check_field` into one
private function that takes an explicit field value and a lookup for
related fields. `Record.check_field` remains the public wrapper and
validates its current attributes. `_WriteModel` validates its own field
values without borrowing the `Record` method.

This is the next small step toward #866. It does not intentionally
change validation, the public API, or written files. The in-place ADC
branch noted in the #892 review is independent of this change.

## Checks

- 2,290 offline tests passed; 48 skipped and 23 network tests
deselected.
- Writer byte fixtures and header parity tests passed, including
invalid-header error comparisons (412 passed, 44 expected skips in the
focused run).
- A new test asserts that `_WriteModel` owns a distinct validator; it
fails on pre-change main and passes here. Another checks the public
method still validates current `Record` attributes.
- The docs build passed with warnings treated as errors. Ruff check and
format check passed.

No changelog entry because this only extracts internal validation logic.
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