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

Improvements to Sequence.switch_device() #563

Merged
merged 2 commits into from
Jul 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion VERSION.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.14.0
0.14.1
21 changes: 15 additions & 6 deletions pulser-core/pulser/sequence/sequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,11 @@ def check_retarget(ch_obj: Channel) -> bool:
channel_match: dict[str, Any] = {}
strict_error_message = ""
ch_match_err = ""
active_eom_channels = [
{**dict(zip(("channel",), call.args)), **call.kwargs}["channel"]
HGSilveri marked this conversation as resolved.
Show resolved Hide resolved
for call in self._calls + self._to_build_calls
if call.name == "enable_eom_mode"
]
for old_ch_name, old_ch_obj in self.declared_channels.items():
channel_match[old_ch_name] = None
# Find the corresponding channel on the new device
Expand All @@ -509,27 +514,31 @@ def check_retarget(ch_obj: Channel) -> bool:

# We verify the channel class then
# check whether the addressing is Global or Local
type_match = type(old_ch_obj) == type(new_ch_obj)
HGSilveri marked this conversation as resolved.
Show resolved Hide resolved
basis_match = old_ch_obj.basis == new_ch_obj.basis
addressing_match = (
old_ch_obj.addressing == new_ch_obj.addressing
)
base_msg = f"No match for channel {old_ch_name}"
if not (basis_match and addressing_match):
if not (type_match and basis_match and addressing_match):
# If there already is a message, keeps it
ch_match_err = ch_match_err or (
base_msg + " with the right basis and addressing."
base_msg
+ " with the right type, basis and addressing."
)
continue
if any(
call.name == "enable_eom_mode"
for call in self._calls + self._to_build_calls
):
if old_ch_name in active_eom_channels:
# Uses EOM mode, so the new device needs a matching
# EOM configuration
if new_ch_obj.eom_config is None:
ch_match_err = base_msg + " with an EOM configuration."
continue
if (
# TODO: Improvements to this check:
# 1. multiple_beam_control doesn't matter when there
# is only one beam
HGSilveri marked this conversation as resolved.
Show resolved Hide resolved
# 2. custom_buffer_time doesn't have to match as long
# as `Channel_eom_buffer_time`` does
new_ch_obj.eom_config != old_ch_obj.eom_config
and strict
):
Expand Down
6 changes: 3 additions & 3 deletions tests/test_sequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ def test_switch_device_down(reg, devices, pulses, mappable_reg, parametrized):
with pytest.raises(
TypeError,
match="No match for channel global2 with the"
" right basis and addressing.",
" right type, basis and addressing.",
):
# Can't find a match for the 2nd rydberg_global
seq.switch_device(Chadoq2)
Expand Down Expand Up @@ -402,13 +402,13 @@ def test_switch_device_down(reg, devices, pulses, mappable_reg, parametrized):
mappable_reg=mappable_reg,
)
for dev_ in (
Chadoq2, # Different Channels basis
Chadoq2, # Different Channels type / basis
devices[1], # Different addressing channels
):
with pytest.raises(
TypeError,
match="No match for channel ising with the"
+ " right basis and addressing.",
+ " right type, basis and addressing.",
):
seq.switch_device(dev_)

Expand Down