Skip to content

Fix how the dataset reader uses its device module - #26

Merged
glopesdev merged 5 commits into
mainfrom
fix-dataset-reader
Aug 16, 2026
Merged

Fix how the dataset reader uses its device module#26
glopesdev merged 5 commits into
mainfrom
fix-dataset-reader

Conversation

@glopesdev

Copy link
Copy Markdown
Contributor

Three defects in DatasetReader surfaced while reviewing documentation ahead of the release, two of which made the reader silently wrong. A fourth change renames strict to require_converters, to make its meaning explicit and avoid clashing with the new validate flag.

Preserve the device module type

DatasetReader is now generic over its device module, mirroring Device. device_module returns the module type passed to the constructor, so registers reached through the reader resolve exactly as they do on the module itself.

Match files by the declared device name

A device module now declares the name used to prefix its recordings under DEVICE_NAME, and DeviceModuleLike requires it in place of __name__. The reader takes the file prefix from name when given, then from DEVICE_NAME, then from the folder itself when it holds a single device, which covers a schema that declares no name at all.

The prefix previously came from the module __name__, which is the dotted import path for a pre-generated package, so DatasetReader(behavior, folder) matched no files and a whole session read as empty with no error.

Validate device identity

The reader now compares the module WHO_AM_I against the whoAmI in the folder device.yml, and refuses to construct when they disagree. A module reused across sessions and reaching the wrong folder therefore fails on construction rather than decoding the files against the wrong register map. validate=False turns off every check the reader performs, so a folder whose device.yml is damaged can be read with a module obtained elsewhere.

Rename strict to require_converters

strict is now require_converters on create_registers, create_device_module and create_dataset_reader. Behavior is unchanged. An unresolved custom interfaceType still raises UnknownConverterError, and passing False still decodes it as the native element type.

The old name said nothing about converters, and read as the same kind of switch as the new validate while sitting on the opposite side of the data boundary. validate=False changes whether a check runs, whereas require_converters=False changes the decoded values.

DatasetReader is now generic over its device module, so device_module
returns the module passed to the constructor rather than the
DeviceModuleLike contract, and create_dataset_reader declares
DatasetReader[DeviceModule]. Reaching a register through the device
module in the reader now resolves to the register class itself for a
pre-generated package, and collectively for a module built by
create_device_module.
A device module now declares DEVICE_NAME, the device name from the
schema, matching what the generator emits for a static package, and
DeviceModuleLike requires it in place of __name__. DatasetReader takes
the file prefix from name when given, then from DEVICE_NAME, then from
the folder when it holds a single device. A pre-generated package
therefore reads correctly, where the module name used before is its
dotted import path and matches no file.
The keyword controlling converter resolution is now require_converters
on create_registers, create_device_module and create_dataset_reader.
Behavior is unchanged. A custom interfaceType with no matching entry in
converters still raises UnknownConverterError, and passing False still
decodes it as its native element type. The error message now names the
flag rather than explaining what strict meant.
DatasetReader compares the WHO_AM_I of its device module with the
whoAmI declared by the device.yml in the folder, and raises when they
disagree, so a module reused across sessions and reaching the wrong
folder fails on construction rather than decoding the files against
the wrong register map. The check is skipped when either side declares
no identity, and when the schema does not describe a device pyharp can
model. A schema that is not well-formed raises instead. validate=False
turns off every check the reader performs.
@glopesdev
glopesdev requested a review from bruno-f-cruz August 16, 2026 10:02
DatasetReader no longer infers a device name from the file names in a
folder. The prefix comes from name when given and otherwise from the
DEVICE_NAME declared by the module, and construction fails when that is
empty, as it is for a module built from a schema with no device header.
DEVICE_NAME and WHO_AM_I are now read directly rather than through
getattr, so a module that does not satisfy DeviceModuleLike raises
AttributeError.

The dataset fixtures take their prefix from DEVICE_NAME rather than from
the module __name__, which were equal only by coincidence, and the chunk
test now uses ISO 8601 UTC timestamps in basic format to illustrate
lexicographic sorting.

@bruno-f-cruz bruno-f-cruz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Lgtm!

@glopesdev
glopesdev merged commit 31aec99 into main Aug 16, 2026
13 checks passed
@glopesdev
glopesdev deleted the fix-dataset-reader branch August 16, 2026 22:49
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.

2 participants