Skip to content

Commit

Permalink
Block add() on DMM channels (#672)
Browse files Browse the repository at this point in the history
  • Loading branch information
HGSilveri authored Apr 16, 2024
1 parent 0f6e3dd commit 7df66e3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
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.")
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")

0 comments on commit 7df66e3

Please sign in to comment.