Skip to content

Write model signal files from explicit arrays - #896

Merged
tompollard merged 1 commit into
mainfrom
refactor/explicit-dat-writing
Dec 3, 2026
Merged

tompollard merged 1 commit into
mainfrom
refactor/explicit-dat-writing

Conversation

@tompollard

Copy link
Copy Markdown
Member

Summary

Write _WriteModel signal files from the header's channel snapshot and explicit digital arrays. The model path now validates the digital field, shape, and per-channel format bounds, then calls the existing _write_dat_files encoder directly. It no longer calls inherited SignalMixin.wr_dats, check_sig_cohesion, or wr_dat_files.

This is the .dat step of #866. The public Record methods and the old comparison path remain in place. No public behavior or file output change is intended.

The old wr_dats call passes an empty write_fields list to check_sig_cohesion, so its checksum and initial-value branches do not run on this path. Those branches remain in the legacy method; this PR extracts the checks that the model actually uses.

Checks

  • 2,294 offline tests passed; 48 skipped and 23 network tests deselected.
  • Writer byte fixtures, header parity, and warning caller tests passed (415 passed, 44 expected skips in the focused run).
  • A new test makes inherited signal writer methods fail if the modern path calls them. It fails on pre-change main and passes here.
  • Shape and range checks matched the old SignalMixin.check_sig_cohesion method in 1,000 generated valid and invalid cases.
  • Docs built with warnings treated as errors; Ruff and git diff --check passed.

No changelog entry because this changes only the internal writer path.

@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.

The .dat step is correct, and it can merge. It has the same follow-up as #895. The focused .dat, fixture, parity and warning tests pass (416 passed, 44 expected skips), as do the offline suite (2,294 passed, 48 skipped) and Ruff.

What I checked

  • _check_dat_values matches the checks the model path actually ran. You're right that wr_dats passes an empty write_fields list, so only the shape and range branches of check_sig_cohesion ran. The new function repeats those branches exactly: the same expanded length check with samps_per_frame or 1, the same uniform shape check with its prints and message, and the same per-channel _digi_bounds check raising IndexError with the same text. The only change is that the channel count comes from the header snapshot instead of self.n_sig, and the header step has already validated that they agree.

  • Output compared directly with main (fa5f324). As for #895, every modern write now goes through new code:

    • every readable sample header, both kinds and layouts, through write_record and SignalRead.write;
    • 3,000 random sparse records through write_record;
    • the 15 invalid header-field cases;
    • the 480 flattened multi-segment writes across all four writers.

    Every outcome matches main, file names, bytes and errors included.

  • Inputs are unchanged. My 1,464-write SignalRead.write check still shows no changed arrays, masks or retained fields, with the same 232 expected errors as main.

  • The new test fails on main, which I checked by copying it into a main checkout.

  • Performance is unchanged. On 100skew (write only), all five writer and kind combinations are within noise of main, with identical peak memory.

Follow-up for the cleanup PR, as on #895

_check_dat_values now repeats the shape and range branches of SignalMixin.check_sig_cohesion, which Record.wrsamp still uses through wr_dats. With this and #895, the model no longer calls the inherited header or .dat writers. So the cleanup PR can:

  1. make Record._write_checked_header, check_field_cohesion's snapshot branch and check_sig_cohesion's shape and range branches call the new module functions, while the parity test can still confirm the Record side;
  2. drop the mixin inheritance from _WriteModel;
  3. remove the _legacy_* paths, with the checklist mapping each parity test to its replacement.

@tompollard
tompollard merged commit 69fbc95 into main Dec 3, 2026
19 checks passed
@tompollard
tompollard deleted the refactor/explicit-dat-writing branch December 3, 2026 18:25
tompollard added a commit that referenced this pull request Dec 3, 2026
## Summary

Consolidate the duplicate header and signal validation left by #895 and
#896. `Record._write_checked_header` now calls the explicit header
function, its snapshot cohesion check calls the shared helper, and
`SignalMixin.check_sig_cohesion` uses the explicit shape and range
checker while keeping its direct-call checksum and initial-value checks.
`_WriteModel` no longer inherits `BaseRecord`, `HeaderMixin`, or
`SignalMixin`.

This is the first #866 cleanup step. The `_legacy_*` paths and parity
test remain independent for this review. Removing them needs a separate
checklist that maps each parity case to a fixed byte fixture or test.
The model still projects channel fields to lists while preparing a
write; that remaining metadata representation work is separate from
inheritance removal.

## Checks

- 2,294 offline tests passed; 48 skipped and 23 network tests
deselected.
- Writer byte fixtures, old-versus-new parity, explicit header and
`.dat` tests, and warning caller tests passed (417 passed, 44 expected
skips in the focused run).
- Direct `Record.check_sig_cohesion` calls matched pre-change main in
2,000 generated cases, including errors, printed diagnostics, and
in-place samples-per-frame defaults.
- Docs built with warnings treated as errors; Ruff and `git diff
--check` passed.

No changelog entry because this changes only internal writer structure.
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