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

Separate draw_samples and draw_sequence #533

Merged
merged 32 commits into from
Jun 19, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
0f32556
separate draw_samples and draw_sequence
dakk Jun 7, 2023
daafc55
rebase
dakk Jun 7, 2023
4501e77
restore target rendering
dakk Jun 7, 2023
91166cf
fix linters and types
dakk Jun 7, 2023
2fb542d
move measurement drawing and draw_interp_pts to draw_sequenece
dakk Jun 8, 2023
76276e1
- add time_slots of type target to ChannelSamples
dakk Jun 9, 2023
9ee018f
Fix samples.py typing
dakk Jun 9, 2023
63ab9e4
remove useless comments
dakk Jun 9, 2023
807c8e8
- fix _seq_drawer parameters names
dakk Jun 9, 2023
0bcbf57
fix linting
dakk Jun 9, 2023
ab4f2e3
move optional register drawing to draw_samples
dakk Jun 9, 2023
09c580e
splitting of drawing of target regions
dakk Jun 12, 2023
1363f2c
fix linters
dakk Jun 12, 2023
b7b725f
move draw_phase_shifts outside the loop
dakk Jun 12, 2023
3f4afd4
remove duplicate code from draw_sequence
dakk Jun 12, 2023
6757303
separate draw_channel_content from draw_samples
dakk Jun 12, 2023
2bd97b6
restore _seq_drawer boxes definition position
dakk Jun 12, 2023
70b3d2c
minor edits on seq_drawer
dakk Jun 12, 2023
652484d
adapt draw_phase_area for using sampled_seq in _seq_drawer
dakk Jun 13, 2023
e89d060
- move gather_data to draw_channel_content
dakk Jun 13, 2023
0309a42
- add _basis_ref to SequenceSamples
dakk Jun 13, 2023
3f56a89
- move phase_str into _draw_channel_content
dakk Jun 13, 2023
69e9a1f
refactoring of _seq_drawer
dakk Jun 13, 2023
2a7cf7e
Refactoring of _seq_drawer.py
dakk Jun 13, 2023
ae3b974
fix typo
dakk Jun 13, 2023
4706247
fix EOM drawing in draw_sequence
dakk Jun 13, 2023
33b598e
remove useless if
dakk Jun 13, 2023
38834ab
- test_draw_samples
dakk Jun 16, 2023
f67d642
- add eom_start_buffers and eom_end_buffers in ChannelSamples
dakk Jun 19, 2023
a0c3692
preserve backward compatibility for _TargetSlot
dakk Jun 19, 2023
6c22203
Pin numpy version to < 1.25
dakk Jun 19, 2023
b39a25d
use eom_blocks for eom_intervals_ti creation
dakk Jun 19, 2023
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: 2 additions & 0 deletions pulser-core/pulser/sampler/samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ class ChannelSamples:
phase: np.ndarray
slots: list[_PulseTargetSlot] = field(default_factory=list)
eom_blocks: list[_EOMSettings] = field(default_factory=list)
eom_start_buffers: list[tuple[int, int]] = field(default_factory=list)
eom_end_buffers: list[tuple[int, int]] = field(default_factory=list)
target_time_slots: list[_TimeSlot] = field(default_factory=list)
HGSilveri marked this conversation as resolved.
Show resolved Hide resolved

def __post_init__(self) -> None:
Expand Down
43 changes: 42 additions & 1 deletion pulser-core/pulser/sequence/_schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,15 @@ def get_samples(
target_time_slots: list[_TimeSlot] = [
s for s in self.slots if s.type == "target"
]
# Extracting the EOM Buffers
eom_intervals_ti = [
eom_interval[0] for eom_interval in self.get_eom_mode_intervals()
]
dakk marked this conversation as resolved.
Show resolved Hide resolved
nb_eom_intervals = len(eom_intervals_ti)
eom_start_buffers = [(0, 0) for _ in range(nb_eom_intervals)]
eom_end_buffers = [(0, 0) for _ in range(nb_eom_intervals)]
in_eom_mode = False
eom_block_n = -1

for ind, s in enumerate(channel_slots):
pulse = cast(Pulse, s.type)
Expand Down Expand Up @@ -184,8 +193,40 @@ def get_samples(
# the same, so the last phase is automatically kept till the end
phase[t_start:] = pulse.phase

# Create EOM start and end buffers
for s in self.slots:
if s.ti == -1:
continue

# If slot is not the first element in schedule
if self.in_eom_mode(s):
# EOM mode starts
if not in_eom_mode:
in_eom_mode = True
eom_block_n += 1
elif in_eom_mode:
# Buffer when EOM mode is disabled and next slot has 0 amp
in_eom_mode = False
if amp[s.ti] == 0:
eom_end_buffers[eom_block_n] = (s.ti, s.tf)
if (
eom_block_n + 1 < nb_eom_intervals
and s.tf == eom_intervals_ti[eom_block_n + 1]
and det[s.tf - 1]
== self.eom_blocks[eom_block_n + 1].detuning_off
):
# Buffer if next is eom and final det matches det_off
eom_start_buffers[eom_block_n + 1] = (s.ti, s.tf)

return ChannelSamples(
amp, det, phase, slots, self.eom_blocks, target_time_slots
amp,
det,
phase,
slots,
self.eom_blocks,
eom_start_buffers,
eom_end_buffers,
target_time_slots,
)

@overload
Expand Down
54 changes: 9 additions & 45 deletions pulser-core/pulser/sequence/_seq_drawer.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import pulser
from pulser import Register, Register3D
from pulser.channels.base_channel import Channel
from pulser.channels.eom import BaseEOM
from pulser.pulse import Pulse
from pulser.register.base_register import BaseRegister
from pulser.sampler.sampler import sample
Expand Down Expand Up @@ -187,58 +186,23 @@ def gather_data(
EOMSegment(eom_interval[0], eom_interval[1])
for eom_interval in ch_samples.get_eom_mode_intervals()
]
nb_eom_intervals = len(eom_intervals)
eom_start_buffers = [EOMSegment() for _ in range(nb_eom_intervals)]
eom_end_buffers = [EOMSegment() for _ in range(nb_eom_intervals)]
in_eom_mode = False
eom_block_n = -1
# Last eom interval is extended if eom mode not disabled at the end
if (
nb_eom_intervals > 0
len(eom_intervals) > 0
and ch_samples.duration == eom_intervals[-1].tf
):
eom_intervals[-1].tf = total_duration
# sampling the channel schedule
extended_samples = ch_samples.extend_duration(total_duration)

for slot in ch_samples.slots:
# If slot is not the first element in schedule
if ch_samples.in_eom_mode(slot):
# EOM mode starts
if not in_eom_mode:
in_eom_mode = True
eom_block_n += 1
elif in_eom_mode:
# Buffer when EOM mode is disabled and next slot has 0 amp
in_eom_mode = False

tf = eom_intervals[eom_block_n].tf
if tf is not None and slot.ti != eom_intervals[eom_block_n].tf:
if np.isclose(
extended_samples.amp[
tf
+ 2
* cast(
BaseEOM, sampled_seq._ch_objs[ch].eom_config
).rise_time
],
0,
):
eom_end_buffers[eom_block_n] = EOMSegment(tf, slot.ti)

if (
eom_block_n + 1 < nb_eom_intervals
and slot.tf == eom_intervals[eom_block_n + 1].ti
and np.isclose(
extended_samples.det[slot.tf - 1],
ch_samples.eom_blocks[eom_block_n + 1].detuning_off,
0.006,
)
):
# Buffer if next is eom and final det matches det_off
eom_start_buffers[eom_block_n + 1] = EOMSegment(
slot.ti, slot.tf
)
eom_start_buffers = [
EOMSegment(eom_interval[0], eom_interval[1])
for eom_interval in ch_samples.eom_start_buffers
]
eom_end_buffers = [
EOMSegment(eom_interval[0], eom_interval[1])
for eom_interval in ch_samples.eom_end_buffers
]

for time_slot in ch_samples.target_time_slots:
if time_slot.ti == -1:
Expand Down
3 changes: 3 additions & 0 deletions tests/test_sequence_sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,9 @@ def test_eom_modulation(mod_device, disable_eom):
input_samples = sample(
seq, extended_duration=full_duration
).channel_samples["ch0"]
assert input_samples.in_eom_mode(input_samples.slots[-1]) == (
not disable_eom
)
mod_samples = sample(seq, modulation=True, extended_duration=full_duration)
chan = seq.declared_channels["ch0"]
for qty in ("amp", "det"):
Expand Down