Skip to content

Commit

Permalink
Allow definition of a custom phase jump time + Suppress output modula…
Browse files Browse the repository at this point in the history
…tion for phase (#779)

* Adding Channel.custom_phase_jump_time

* Restrict phase jump time for EOM mode

* Eliminate modulation for phase

* Unit tests

* Improve docstring
  • Loading branch information
HGSilveri authored Dec 18, 2024
1 parent 091726a commit e2ad837
Show file tree
Hide file tree
Showing 8 changed files with 190 additions and 22 deletions.
28 changes: 25 additions & 3 deletions pulser-core/pulser/channels/base_channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@

ChannelType = TypeVar("ChannelType", bound="Channel")

OPTIONAL_ABSTR_CH_FIELDS = ("min_avg_amp", "propagation_dir")
OPTIONAL_ABSTR_CH_FIELDS = (
"min_avg_amp",
"custom_phase_jump_time",
"propagation_dir",
)

# States ranked in decreasing order of their associated eigenenergy
States = Literal["u", "d", "r", "g", "h", "x"]
Expand Down Expand Up @@ -78,6 +82,9 @@ class Channel(ABC):
min_avg_amp: The minimum average amplitude of a pulse (when not zero).
mod_bandwidth: The modulation bandwidth at -3dB (50% reduction), in
MHz.
custom_phase_jump_time: An optional custom value for the phase jump
time that overrides the default value estimated from the modulation
bandwidth. It is not enforced in EOM mode.
propagation_dir: The propagation direction of the beam associated with
the channel, given as a vector in 3D space.
Expand All @@ -97,6 +104,7 @@ class Channel(ABC):
max_duration: Optional[int] = int(1e8) # ns
min_avg_amp: float = 0
mod_bandwidth: Optional[float] = None # MHz
custom_phase_jump_time: int | None = None
eom_config: Optional[BaseEOM] = field(init=False, default=None)
propagation_dir: tuple[float, float, float] | None = None

Expand Down Expand Up @@ -172,13 +180,15 @@ def __post_init__(self) -> None:
"max_duration",
"mod_bandwidth",
"min_avg_amp",
"custom_phase_jump_time",
]
non_negative = [
"max_amp",
"max_abs_detuning",
"min_retarget_interval",
"fixed_retarget_t",
"min_avg_amp",
"custom_phase_jump_time",
]
local_only = [
"min_retarget_interval",
Expand All @@ -191,6 +201,7 @@ def __post_init__(self) -> None:
"max_duration",
"mod_bandwidth",
"max_targets",
"custom_phase_jump_time",
]

if self.addressing == "Global":
Expand Down Expand Up @@ -280,9 +291,14 @@ def rise_time(self) -> int:
def phase_jump_time(self) -> int:
"""Time taken to change the phase between consecutive pulses (in ns).
Corresponds to two times the rise time.
Corresponds to two times the rise time when `custom_phase_jump_time`
is not defined.
"""
return self.rise_time * 2
return int(
self.rise_time * 2
if self.custom_phase_jump_time is None
else self.custom_phase_jump_time
)

def is_virtual(self) -> bool:
"""Whether the channel is virtual (i.e. partially defined)."""
Expand Down Expand Up @@ -336,6 +352,9 @@ def Local(
bandwidth at -3dB (50% reduction), in MHz.
min_avg_amp: The minimum average amplitude of a pulse (when not
zero).
custom_phase_jump_time: An optional custom value for the phase jump
time that overrides the default value estimated from the
modulation bandwidth. It is not enforced in EOM mode.
"""
# Can't initialize a channel whose addressing is determined internally
for cls_field in fields(cls):
Expand Down Expand Up @@ -382,6 +401,9 @@ def Global(
bandwidth at -3dB (50% reduction), in MHz.
min_avg_amp: The minimum average amplitude of a pulse (when not
zero).
custom_phase_jump_time: An optional custom value for the phase jump
time that overrides the default value estimated from the
modulation bandwidth. It is not enforced in EOM mode.
propagation_dir: The propagation direction of the beam associated
with the channel, given as a vector in 3D space.
"""
Expand Down
98 changes: 98 additions & 0 deletions pulser-core/pulser/json/abstract_repr/schemas/device-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@
"description": "The duration of a clock cycle (in ns).",
"type": "number"
},
"custom_phase_jump_time": {
"description": "An optional custom value for the phase jump time that overrides the default value estimated from the modulation bandwidth.",
"type": [
"number",
"null"
]
},
"eom_config": {
"description": "Configuration of an associated EOM.",
"type": "null"
Expand Down Expand Up @@ -417,6 +424,13 @@
"description": "The duration of a clock cycle (in ns).",
"type": "number"
},
"custom_phase_jump_time": {
"description": "An optional custom value for the phase jump time that overrides the default value estimated from the modulation bandwidth.",
"type": [
"number",
"null"
]
},
"eom_config": {
"anyOf": [
{
Expand Down Expand Up @@ -587,6 +601,13 @@
"description": "The duration of a clock cycle (in ns).",
"type": "number"
},
"custom_phase_jump_time": {
"description": "An optional custom value for the phase jump time that overrides the default value estimated from the modulation bandwidth.",
"type": [
"number",
"null"
]
},
"eom_config": {
"description": "Configuration of an associated EOM.",
"type": "null"
Expand Down Expand Up @@ -693,6 +714,13 @@
"description": "The duration of a clock cycle (in ns).",
"type": "number"
},
"custom_phase_jump_time": {
"description": "An optional custom value for the phase jump time that overrides the default value estimated from the modulation bandwidth.",
"type": [
"number",
"null"
]
},
"eom_config": {
"description": "Configuration of an associated EOM.",
"type": "null"
Expand Down Expand Up @@ -799,6 +827,13 @@
"description": "The duration of a clock cycle (in ns).",
"type": "number"
},
"custom_phase_jump_time": {
"description": "An optional custom value for the phase jump time that overrides the default value estimated from the modulation bandwidth.",
"type": [
"number",
"null"
]
},
"eom_config": {
"anyOf": [
{
Expand Down Expand Up @@ -972,6 +1007,13 @@
"description": "The duration of a clock cycle (in ns).",
"type": "number"
},
"custom_phase_jump_time": {
"description": "An optional custom value for the phase jump time that overrides the default value estimated from the modulation bandwidth.",
"type": [
"number",
"null"
]
},
"eom_config": {
"description": "Configuration of an associated EOM.",
"type": "null"
Expand Down Expand Up @@ -1081,6 +1123,13 @@
"description": "The duration of a clock cycle (in ns).",
"type": "number"
},
"custom_phase_jump_time": {
"description": "An optional custom value for the phase jump time that overrides the default value estimated from the modulation bandwidth.",
"type": [
"number",
"null"
]
},
"eom_config": {
"description": "Configuration of an associated EOM.",
"type": "null"
Expand Down Expand Up @@ -1195,6 +1244,13 @@
"description": "The duration of a clock cycle (in ns).",
"type": "number"
},
"custom_phase_jump_time": {
"description": "An optional custom value for the phase jump time that overrides the default value estimated from the modulation bandwidth.",
"type": [
"number",
"null"
]
},
"eom_config": {
"anyOf": [
{
Expand Down Expand Up @@ -1356,6 +1412,13 @@
"description": "The duration of a clock cycle (in ns).",
"type": "number"
},
"custom_phase_jump_time": {
"description": "An optional custom value for the phase jump time that overrides the default value estimated from the modulation bandwidth.",
"type": [
"number",
"null"
]
},
"eom_config": {
"description": "Configuration of an associated EOM.",
"type": "null"
Expand Down Expand Up @@ -1453,6 +1516,13 @@
"description": "The duration of a clock cycle (in ns).",
"type": "number"
},
"custom_phase_jump_time": {
"description": "An optional custom value for the phase jump time that overrides the default value estimated from the modulation bandwidth.",
"type": [
"number",
"null"
]
},
"eom_config": {
"description": "Configuration of an associated EOM.",
"type": "null"
Expand Down Expand Up @@ -1550,6 +1620,13 @@
"description": "The duration of a clock cycle (in ns).",
"type": "number"
},
"custom_phase_jump_time": {
"description": "An optional custom value for the phase jump time that overrides the default value estimated from the modulation bandwidth.",
"type": [
"number",
"null"
]
},
"eom_config": {
"anyOf": [
{
Expand Down Expand Up @@ -1711,6 +1788,13 @@
"description": "The duration of a clock cycle (in ns).",
"type": "number"
},
"custom_phase_jump_time": {
"description": "An optional custom value for the phase jump time that overrides the default value estimated from the modulation bandwidth.",
"type": [
"number",
"null"
]
},
"eom_config": {
"description": "Configuration of an associated EOM.",
"type": "null"
Expand Down Expand Up @@ -1808,6 +1892,13 @@
"description": "The duration of a clock cycle (in ns).",
"type": "number"
},
"custom_phase_jump_time": {
"description": "An optional custom value for the phase jump time that overrides the default value estimated from the modulation bandwidth.",
"type": [
"number",
"null"
]
},
"eom_config": {
"description": "Configuration of an associated EOM.",
"type": "null"
Expand Down Expand Up @@ -1911,6 +2002,13 @@
"description": "The duration of a clock cycle (in ns).",
"type": "number"
},
"custom_phase_jump_time": {
"description": "An optional custom value for the phase jump time that overrides the default value estimated from the modulation bandwidth.",
"type": [
"number",
"null"
]
},
"eom_config": {
"description": "Configuration of an associated EOM.",
"type": "null"
Expand Down
13 changes: 10 additions & 3 deletions pulser-core/pulser/sampler/samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,9 +424,16 @@ def masked(
new_samples["amp"] = channel_obj.modulate(self.amp)
new_samples["det"] = channel_obj.modulate(self.det, keep_ends=True)

new_samples["phase"] = channel_obj.modulate(self.phase, keep_ends=True)
new_samples["_centered_phase"] = channel_obj.modulate(
self.centered_phase, keep_ends=True
new_len_ = len(new_samples["amp"])
new_samples["phase"] = pm.pad(
self.phase,
(0, new_len_ - len(self.phase)),
mode="edge",
)
new_samples["_centered_phase"] = pm.pad(
self.centered_phase,
(0, new_len_ - len(self.centered_phase)),
mode="edge",
)
for key in new_samples:
new_samples[key] = new_samples[key].astype(float)[
Expand Down
9 changes: 6 additions & 3 deletions pulser-core/pulser/sequence/_schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,11 +434,14 @@ def corrected_phase(tf: int) -> pm.AbstractArray:
# last pulse from the phase_jump_time and adds the
# fall_time to let the last pulse ramp down
ch_obj = self[channel].channel_obj
in_eom_mode = self[channel].in_eom_mode()
phase_jump_buffer = (
ch_obj.phase_jump_time
+ last_pulse.fall_time(
ch_obj, in_eom_mode=self[channel].in_eom_mode()
max(
ch_obj.phase_jump_time,
# In EOM mode, we must wait at least 2*rise_time
2 * ch_obj.rise_time * in_eom_mode,
)
+ last_pulse.fall_time(ch_obj, in_eom_mode=in_eom_mode)
- (t0 - last_pulse_slot.tf)
)
except RuntimeError:
Expand Down
1 change: 1 addition & 0 deletions tests/test_abstract_repr.py
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,7 @@ def test_optional_device_fields(self, og_device, field, value):
[
Rydberg.Global(None, None, min_avg_amp=1),
Rydberg.Global(None, None, propagation_dir=(1, 0, 0)),
Rydberg.Global(None, None, custom_phase_jump_time=0),
Rydberg.Global(
None,
None,
Expand Down
2 changes: 2 additions & 0 deletions tests/test_channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
("min_avg_amp", -1e-3),
("propagation_dir", (0, 0, 0)),
("propagation_dir", [1, 0]),
("custom_phase_jump_time", -10),
],
)
def test_bad_init_global_channel(bad_param, bad_value):
Expand Down Expand Up @@ -66,6 +67,7 @@ def test_bad_init_global_channel(bad_param, bad_value):
("mod_bandwidth", MODBW_TO_TR * 1e3 + 1),
("min_avg_amp", -1e-3),
("propagation_dir", (1, 0, 0)),
("custom_phase_jump_time", -0.5),
],
)
def test_bad_init_local_channel(bad_param, bad_value):
Expand Down
Loading

0 comments on commit e2ad837

Please sign in to comment.