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 27 commits
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
1 change: 1 addition & 0 deletions pulser-core/pulser/sampler/sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,6 @@ def sample(
list(seq.declared_channels.keys()),
samples_list,
seq.declared_channels,
seq._basis_ref,
**optionals,
)
38 changes: 36 additions & 2 deletions pulser-core/pulser/sampler/samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
from pulser.channels.base_channel import Channel
from pulser.channels.eom import BaseEOM
from pulser.register import QubitId
from pulser.sequence._basis_ref import _QubitRef

if TYPE_CHECKING:
from pulser.sequence._schedule import _EOMSettings
from pulser.sequence._schedule import _EOMSettings, _TimeSlot

"""Literal constants for addressing."""
_GLOBAL = "Global"
Expand Down Expand Up @@ -91,7 +92,7 @@ class ChannelSamples:
phase: np.ndarray
slots: list[_TargetSlot] = field(default_factory=list)
eom_blocks: list[_EOMSettings] = field(default_factory=list)
initial_targets: set[QubitId] = field(default_factory=set)
target_time_slots: list[_TimeSlot] = field(default_factory=list)
HGSilveri marked this conversation as resolved.
Show resolved Hide resolved

def __post_init__(self) -> None:
assert len(self.amp) == len(self.det) == len(self.phase)
Expand All @@ -102,6 +103,15 @@ def __post_init__(self) -> None:
for t1, t2 in zip(self.slots, self.slots[1:]):
assert t1.tf <= t2.ti # no overlaps on a given channel

@property
def initial_targets(self) -> set[QubitId]:
"""Returns the initial targets."""
return (
self.target_time_slots[0].targets
if self.target_time_slots
else set()
)

def extend_duration(self, new_duration: int) -> ChannelSamples:
"""Extends the duration of the samples.

Expand Down Expand Up @@ -160,6 +170,27 @@ def _generate_std_samples(self) -> ChannelSamples:

return replace(self, **new_samples)

def get_eom_mode_intervals(self) -> list[tuple[int, int]]:
"""Returns EOM mode intervals."""
return [
(
block.ti,
block.tf if block.tf is not None else self.duration,
)
for block in self.eom_blocks
]

def in_eom_mode(
self, slot: Optional[_TimeSlot | _TargetSlot] = None
HGSilveri marked this conversation as resolved.
Show resolved Hide resolved
) -> bool:
"""States if a time slot is inside an EOM mode block."""
if slot is None:
return bool(self.eom_blocks) and (self.eom_blocks[-1].tf is None)
HGSilveri marked this conversation as resolved.
Show resolved Hide resolved
return any(
start <= slot.ti < end
for start, end in self.get_eom_mode_intervals()
)

def modulate(
self, channel_obj: Channel, max_duration: Optional[int] = None
) -> ChannelSamples:
Expand Down Expand Up @@ -292,6 +323,9 @@ class SequenceSamples:
channels: list[str]
samples_list: list[ChannelSamples]
_ch_objs: dict[str, Channel]
_basis_ref: dict[str, dict[QubitId, _QubitRef]] = field(
default_factory=dict
)
_slm_mask: _SlmMask = field(default_factory=_SlmMask)
_magnetic_field: np.ndarray | None = None
_measurement: str | None = None
Expand Down
6 changes: 4 additions & 2 deletions pulser-core/pulser/sequence/_schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,9 @@ def get_samples(
dt = self.get_duration()
amp, det, phase = np.zeros(dt), np.zeros(dt), np.zeros(dt)
slots: list[_TargetSlot] = []
initial_targets = self.slots[0].targets if self.slots else set()
target_time_slots: list[_TimeSlot] = [
s for s in self.slots if s.type == "target"
]

for ind, s in enumerate(channel_slots):
pulse = cast(Pulse, s.type)
Expand Down Expand Up @@ -183,7 +185,7 @@ def get_samples(
phase[t_start:] = pulse.phase

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

@overload
Expand Down
Loading
Loading