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

Block add() on DMM channels #672

Merged
merged 1 commit into from
Apr 16, 2024
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
13 changes: 10 additions & 3 deletions pulser-core/pulser/sequence/sequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -1318,6 +1318,11 @@ def add(
block_eom_mode=True,
block_if_slm=channel.startswith("dmm_"),
)
if isinstance(self.declared_channels[channel], DMM):
raise ValueError(
"`Sequence.add()` can't be used on a DMM channel. "
"Use `Sequence.add_dmm_detuning()` instead."
)
self._add(pulse, channel, protocol)

@seq_decorators.store
Expand All @@ -1329,11 +1334,11 @@ def add_dmm_detuning(
dmm_name: str,
protocol: PROTOCOLS = "no-delay",
) -> None:
"""Add a waveform to the detuning of a dmm.
"""Add a waveform to the detuning of a DMM.

Args:
waveform: The waveform to add to the detuning of the dmm.
dmm_name: The id of the dmm to modulate.
waveform: The waveform to add to the detuning of the DMM.
dmm_name: The name of the DMM channel to modulate.
protocol: Stipulates how to deal with
eventual conflicts with other channels, specifically in terms
of having multiple channels act on the same target
Expand All @@ -1348,6 +1353,8 @@ def add_dmm_detuning(
latest pulse.
"""
self._validate_channel(dmm_name, block_if_slm=True)
if not isinstance(self.declared_channels[dmm_name], DMM):
raise ValueError(f"'{dmm_name}' is not the name of a DMM channel.")
Comment on lines +1356 to +1357
Copy link
Collaborator

Choose a reason for hiding this comment

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

Daaamn I had not thought about this

self._add(
Pulse.ConstantAmplitude(0, waveform, 0),
dmm_name,
Expand Down
16 changes: 13 additions & 3 deletions tests/test_sequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -1560,13 +1560,11 @@ def test_draw_slm_mask_in_ising(
)
seq1.draw(mode, draw_qubit_det=draw_qubit_det, draw_interp_pts=False)
seq1.add_dmm_detuning(RampWaveform(300, -10, 0), "dmm_0")
# Same function with add is longer
seq1.add(Pulse.ConstantAmplitude(0, RampWaveform(300, -10, 0), 0), "dmm_0")
# pulse is added on rydberg global with a delay (protocol is "min-delay")
seq1.add(pulse1, "ryd_glob") # slm pulse between 0 and 400
seq1.add(pulse2, "ryd_glob")
seq1.config_slm_mask(targets)
mask_time = 700 + 2 * mymockdevice.channels["rydberg_global"].rise_time
mask_time = 400 + 2 * mymockdevice.channels["rydberg_global"].rise_time
assert seq1._slm_mask_time == [0, mask_time]
assert seq1._schedule["dmm_0_1"].slots[1].type == Pulse.ConstantPulse(
mask_time, 0, -100, 0
Expand Down Expand Up @@ -2268,3 +2266,15 @@ def test_max_duration(reg, mod_device):
seq.delay(16, "ch0")
with catch_statement:
seq.add(Pulse.ConstantPulse(100, 1, 0, 0), "ch0")


def test_add_to_dmm_fails(reg, device, det_map):
seq = Sequence(reg, device)
seq.config_detuning_map(det_map, "dmm_0")
pulse = Pulse.ConstantPulse(100, 0, -1, 0)
with pytest.raises(ValueError, match="can't be used on a DMM"):
seq.add(pulse, "dmm_0")

seq.declare_channel("ryd", "rydberg_global")
with pytest.raises(ValueError, match="not the name of a DMM channel"):
seq.add_dmm_detuning(pulse.detuning, "ryd")