Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
a-corni committed Dec 11, 2024
1 parent e2bc114 commit 394ddb3
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 11 deletions.
11 changes: 5 additions & 6 deletions pulser-core/pulser/register/base_register.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,13 @@ def __init__(
[pm.AbstractArray(v, dtype=float) for v in qubits.values()]
)
self._ids: tuple[QubitId, ...] = tuple(qubits.keys())
not_str = [id for id in self._ids if not isinstance(id, str)]
if not_str:
if any(not isinstance(id, str) for id in self._ids):
warnings.simplefilter("always")
warnings.warn(
"Usage of `int`s as `QubitId`s will be deprecated. Define "
"your `QubitId`s as `str`s, prefer setting `prefix='q'` "
"when using classmethods, as that will become the new "
"default once `int` qubit IDs become invalid.",
"Usage of `int`s or any non-`str`types as `QubitId`s will be "
"deprecated. Define your `QubitId`s as `str`s, prefer setting "
"`prefix='q'` when using classmethods, as that will become the"
" new default once `int` qubit IDs become invalid.",
DeprecationWarning,
stacklevel=2,
)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ filterwarnings = [
"error",
# Except these particular warnings, which are ignored
'ignore:A duration of \d+ ns is not a multiple of:UserWarning',
'ignore:Usage of `int`s as `QubitId`s will be deprecated:DeprecationWarning',
'ignore:Usage of `int`s or any non-`str`types as `QubitId`s:DeprecationWarning',
]

[build-system]
Expand Down
2 changes: 1 addition & 1 deletion tests/test_abstract_repr.py
Original file line number Diff line number Diff line change
Expand Up @@ -822,7 +822,7 @@ def test_exceptions(self, sequence):
AbstractReprError, match="Name collisions encountered"
), pytest.warns(
DeprecationWarning,
match="Usage of `int`s as `QubitId`s will be deprecated.",
match="Usage of `int`s or any non-`str`types as `QubitId`s",
):
Register({"0": (0, 0), 0: (20, 20)})._to_abstract_repr()

Expand Down
4 changes: 2 additions & 2 deletions tests/test_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,13 @@ def test_detuning_map():
def test_register_numbered_keys(reg_dict):
with pytest.warns(
DeprecationWarning,
match="Usage of `int`s as `QubitId`s will be deprecated.",
match="Usage of `int`s or any non-`str`types as `QubitId`s",
):
reg = (Register if len(reg_dict[2]) == 2 else Register3D)(reg_dict)
j = json.dumps(reg, cls=PulserEncoder)
with pytest.warns(
DeprecationWarning,
match="Usage of `int`s as `QubitId`s will be deprecated.",
match="Usage of `int`s or any non-`str`types as `QubitId`s",
):
decoded_reg = json.loads(j, cls=PulserDecoder)
assert reg == decoded_reg
Expand Down
2 changes: 1 addition & 1 deletion tests/test_sequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -1616,7 +1616,7 @@ def test_str(reg, device, mod_device, det_map):
assert seq.__str__() == msg_ch0 + msg_ch1 + msg_det_map + measure_msg
with pytest.warns(
DeprecationWarning,
match="Usage of `int`s as `QubitId`s will be deprecated.",
match="Usage of `int`s or any non-`str`types as `QubitId`s",
):
seq2 = Sequence(Register({"q0": (0, 0), 1: (5, 5)}), device)
seq2.declare_channel("ch1", "rydberg_global")
Expand Down

0 comments on commit 394ddb3

Please sign in to comment.