Skip to content

Commit

Permalink
Introduce upper bound mod_bandwidth (#473)
Browse files Browse the repository at this point in the history
  • Loading branch information
a-corni authored Mar 1, 2023
1 parent ce239a8 commit d32a5a8
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 7 deletions.
7 changes: 7 additions & 0 deletions pulser-core/pulser/channels/base_channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,13 @@ def __post_init__(self) -> None:
" greater than or equal to 'min_duration'"
f"({self.min_duration})."
)
if (
self.mod_bandwidth is not None
and self.mod_bandwidth > MODBW_TO_TR * 1e3
):
raise NotImplementedError(
f"'mod_bandwidth' must be lower than {MODBW_TO_TR*1e3} MHz"
)

@property
def rise_time(self) -> int:
Expand Down
4 changes: 4 additions & 0 deletions pulser-core/pulser/channels/eom.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ def __post_init__(self) -> None:
"'mod_bandwidth' must be greater than zero, not"
f" {self.mod_bandwidth}."
)
elif self.mod_bandwidth > MODBW_TO_TR * 1e3:
raise NotImplementedError(
f"'mod_bandwidth' must be lower than {MODBW_TO_TR*1e3} MHz"
)

@property
def rise_time(self) -> int:
Expand Down
16 changes: 13 additions & 3 deletions tests/test_channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import pulser
from pulser.channels import Microwave, Raman, Rydberg
from pulser.channels.eom import BaseEOM, RydbergBeam, RydbergEOM
from pulser.channels.eom import MODBW_TO_TR, BaseEOM, RydbergBeam, RydbergEOM
from pulser.waveforms import BlackmanWaveform, ConstantWaveform


Expand All @@ -32,12 +32,17 @@
("min_duration", 0),
("max_duration", 0),
("mod_bandwidth", 0),
("mod_bandwidth", MODBW_TO_TR * 1e3 + 1),
],
)
def test_bad_init_global_channel(bad_param, bad_value):
kwargs = dict(max_abs_detuning=None, max_amp=None)
kwargs[bad_param] = bad_value
with pytest.raises(ValueError, match=f"'{bad_param}' must be"):
if bad_param == "mod_bandwidth" and bad_value > 1:
error_type = NotImplementedError
else:
error_type = ValueError
with pytest.raises(error_type, match=f"'{bad_param}' must be"):
Microwave.Global(**kwargs)


Expand All @@ -53,12 +58,17 @@ def test_bad_init_global_channel(bad_param, bad_value):
("min_duration", -2),
("max_duration", -1),
("mod_bandwidth", -1e4),
("mod_bandwidth", MODBW_TO_TR * 1e3 + 1),
],
)
def test_bad_init_local_channel(bad_param, bad_value):
kwargs = dict(max_abs_detuning=None, max_amp=None)
kwargs[bad_param] = bad_value
with pytest.raises(ValueError, match=f"'{bad_param}' must be"):
if bad_param == "mod_bandwidth" and bad_value > 1:
error_type = NotImplementedError
else:
error_type = ValueError
with pytest.raises(error_type, match=f"'{bad_param}' must be"):
Rydberg.Local(**kwargs)


Expand Down
15 changes: 11 additions & 4 deletions tests/test_eom.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import pytest

from pulser.channels.eom import RydbergBeam, RydbergEOM
from pulser.channels.eom import MODBW_TO_TR, RydbergBeam, RydbergEOM


@pytest.fixture
Expand All @@ -33,16 +33,23 @@ def params():
[
("mod_bandwidth", 0),
("mod_bandwidth", -3),
("mod_bandwidth", MODBW_TO_TR * 1e3 + 1),
("max_limiting_amp", 0),
("intermediate_detuning", -500),
("intermediate_detuning", 0),
],
)
def test_bad_value_init_eom(bad_param, bad_value, params):
params[bad_param] = bad_value
with pytest.raises(
ValueError, match=f"'{bad_param}' must be greater than zero"
):
if bad_param == "mod_bandwidth" and bad_value > 0:
error_type = NotImplementedError
error_message = (
f"'mod_bandwidth' must be lower than {MODBW_TO_TR*1e3} MHz"
)
else:
error_type = ValueError
error_message = f"'{bad_param}' must be greater than zero"
with pytest.raises(error_type, match=error_message):
RydbergEOM(**params)


Expand Down

0 comments on commit d32a5a8

Please sign in to comment.