Repository navigation
Use explicit ADC conversion in physical writes - #892
Conversation
tompollard
left a comment
There was a problem hiding this comment.
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_valueskeeps the old in-place behaviour. That's the subtle part ofRecord.adc. Withinplace=True, afloat64uniform array is converted in its own buffer, an expanded list is updated element by element and becomese_d_signal, and the physical attribute is cleared. Without it, everything is converted on afloat64copy. Both are unchanged. -
Record.adccompared withmain(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,float32andfloat64, withNaNs, values landing exactly half-way between integers, gains from 1e-3 to 12345.678, and every writable format. Every outcome matchedmain. -
Performance is unchanged. Alternating runs of 8a88d1c and this branch (
100skew, physical, write only) agree within noise:write_record19.00/20.28 → 18.57/18.71 ms,SignalRead.write15.59/16.36 → 15.37/15.14 ms andwrite_signals31.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.
## 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.
Summary
Extract the ADC conversion from
SignalMixin.adcinto an array-based helper. Physical writes through_WriteModelnow pass their values, formats, gains, and baselines directly to that helper instead of calling the inheritedRecord.adcmethod.Record.adcremains 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
Record.adccases 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.SignalMixin.adcfail if a modern physical write calls it.No changelog entry: this only moves internal conversion logic.