Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding register_is_from_calibrated_layout and is_calibrated_layout to Device #586

Merged
merged 3 commits into from
Sep 22, 2023

Conversation

a-corni
Copy link
Collaborator

@a-corni a-corni commented Sep 22, 2023

As suggested by @HGSilveri:
Add two new methods to Device:

  • Device.is_calibrated_layout(layout: RegisterLayout): Checks whether a layout is within the calibrated layouts.
  • Device.register_is_from_calibrated_layout(register: BaseRegister|MappableRegister): Checks whether the register was constructed from a pre-calibrated layout (ie checks if it has a layout AND is_calibrated_layout(layout))
    As discussed, returns a boolean and not an error.
    register_is_from_calibrated_layout works with BaseRegister (hence Register and Register3D) and MappableRegister (always has a layout in this case) because the type of the register in a sequence can be of type one of these two types.

Closes #577

pulser-core/pulser/devices/_device_datacls.py Outdated Show resolved Hide resolved
Comment on lines 575 to 581
if (
isinstance(register, BaseRegister)
and register._layout_info is None
):
return False
return self.is_calibrated_layout(cast(RegisterLayout, register.layout))

Copy link
Collaborator

Choose a reason for hiding this comment

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

This will raise an AttributeError when register_layout is not a MappableRegister nor a BaseRegister. I think a TypeError would be more appropriate in that case, so perhaps we can check the type of register_layout first.

pulser-core/pulser/devices/_device_datacls.py Outdated Show resolved Hide resolved
Comment on lines 572 to 573
if not isinstance(register, BaseRegister) or isinstance(
register, MappableRegister
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
if not isinstance(register, BaseRegister) or isinstance(
register, MappableRegister
if not isinstance(register, (BaseRegister, MappableRegister))

Copy link
Collaborator

@HGSilveri HGSilveri left a comment

Choose a reason for hiding this comment

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

LGTM, let's wait for @MatthieuMoreau0

Copy link
Collaborator

@MatthieuMoreau0 MatthieuMoreau0 left a comment

Choose a reason for hiding this comment

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

LGTM! Thank you!

@a-corni a-corni merged commit 9e05982 into develop Sep 22, 2023
6 checks passed
@HGSilveri HGSilveri mentioned this pull request Sep 27, 2023
HGSilveri added a commit that referenced this pull request Sep 27, 2023
Main changes:

e0943d9 Override `optimal_detuning_off` on stored calls (#588)
3e40319 Deprecate legacy serializer + Improve error messages (#585)
9e05982 Adding register_is_from_calibrated_layout and is_calibrated_layout to Device (#586)
c08dfa8 Adding dmm config and modulation to sequence (#564)
5270944 Clarify the Conventions in Pulser (#573)
2315989 Give access to all EOM block parameters and allow for phase drift correction (#566)
d5ac020 Adding  DetuningMap, DMM (#539)
f56a19f Remove expired deprecations in pulser-pasqal
@HGSilveri HGSilveri deleted the compare_layouts branch December 29, 2023 11:33
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.

Add function to validate that a given sequence's register matches the pre calibrated layout of a device
3 participants