Skip to content

Enforce matching types in layout deserialization - #1115

Merged
a-corni merged 2 commits into
pasqal-io:developfrom
danielgaskins:fix/matching-layout-deserialization
Sep 14, 2026
Merged

a-corni merged 2 commits into
pasqal-io:developfrom
danielgaskins:fix/matching-layout-deserialization

Conversation

@danielgaskins

Copy link
Copy Markdown
Contributor

RegisterLayout.from_abstract_repr() currently ignores the class it is called on, which allows a specialized layout class to return an incompatible layout type.

This change makes it a classmethod and passes the requested class to the standalone layout deserializer. Specialized classes now reject incompatible serialized layouts with a clear error. Calling the base class or standalone deserializer without a requested type keeps the existing automatic subtype detection.

Tests cover matching special layouts, generic layouts, base-class compatibility, explicit None, and mismatches through both public APIs.

Closes #1099

Tests:

  • 321 abstract representation, register layout, register, and JSON tests passed
  • Mypy passed for the changed source files
  • Black, isort, flake8, and diff checks passed

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

Hey @danielgaskins!
Thanks for tackling this issue! It's looking good, I have only few nits before approving :)

Comment thread pulser-core/pulser/json/abstract_repr/deserializer.py Outdated
Comment thread pulser-core/pulser/json/abstract_repr/deserializer.py Outdated
Comment thread pulser-core/pulser/json/abstract_repr/deserializer.py
Comment thread tests/test_abstract_repr.py Outdated

@a-corni a-corni 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! Thanks for your contribution @danielgaskins !

@a-corni
a-corni merged commit 98bc039 into pasqal-io:develop Sep 14, 2026
14 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.

Make sure RegisterLayout.from_abstract_repr() only returns an instance of a matching type

2 participants