Skip to content

Commit

Permalink
Release v0.10.0
Browse files Browse the repository at this point in the history
**Main Changes:**
- Generalize effective noise channels (#443)
- Update Pulser-Pasqal to the latest cloud-sdk syntax (#474)
- Highlight EOM buffers in Sequence drawings (#475)

**Expired deprecations:**
- `BaseDevice._channels` has been removed - using `BaseDevice.channel_objects` and (optionally) `BaseDevice.channel_ids` is now mandatory
  • Loading branch information
HGSilveri authored Mar 2, 2023
2 parents fee422d + 4b089d0 commit f7a1746
Show file tree
Hide file tree
Showing 37 changed files with 768 additions and 233 deletions.
11 changes: 5 additions & 6 deletions .github/workflows/version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: version
on:
pull_request:
paths:
- 'VERSION.txt'
- "VERSION.txt"

jobs:
validate-version:
Expand All @@ -12,15 +12,15 @@ jobs:
- name: Check out base branch
uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.base.ref }}
ref: ${{ github.event.pull_request.base.ref }}
- name: Get old version
run: |
old_version="$(head -1 VERSION.txt)"
echo "Old version: $old_version"
echo "old_version=$old_version" >> $GITHUB_ENV
- name: Check out head branch
uses: actions/checkout@v3
- name: Get new version
- name: Get new version
run: |
new_version="$(head -1 VERSION.txt)"
echo "New version: $new_version"
Expand All @@ -30,7 +30,7 @@ jobs:
- name: Check stable version validity
if: github.event.pull_request.base.ref == 'master'
run: |
pattern=^\(0\|[1-9]\d*\)\.\(0\|[1-9]\d*\)\.\(0\|[1-9]\d*\)$
pattern=^\(0\|[1-9][0-9]*\)\.\(0\|[1-9][0-9]*\)\.\(0\|[1-9][0-9]*\)$
if [[ ${{ env.new_version }} =~ $pattern ]]; then
echo "New version is valid."; exit 0
else
Expand All @@ -39,10 +39,9 @@ jobs:
- name: Check development version validity
if: github.event.pull_request.base.ref != 'master'
run: |
pattern=^\(0\|[1-9]\d*\)\.\(0\|[1-9]\d*\)dev\(0\|[1-9]\d*\)$
pattern=^\(0\|[1-9][0-9]*\)\.\(0\|[1-9][0-9]*\)dev\(0\|[1-9][0-9]*\)$
if [[ ${{ env.new_version }} =~ $pattern ]]; then
echo "New version is valid."; exit 0
else
echo "New version is invalid."; exit 1
fi
2 changes: 1 addition & 1 deletion VERSION.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.9.3
0.10.0
2 changes: 1 addition & 1 deletion dev_requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# tests
black[jupyter] < 23.1
black[jupyter] ~= 23.1
flake8
flake8-docstrings
isort
Expand Down
2 changes: 1 addition & 1 deletion docs/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ sphinx-rtd-theme # documentation theme
sphinx_autodoc_typehints == 1.21.3
nbsphinx
nbsphinx-link
ipython != 8.7.0 # Avoids bug with code highlighting
ipython >= 8.10 # Avoids bug with code highlighting

# Not on PyPI
# pandoc
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
28 changes: 1 addition & 27 deletions pulser-core/pulser/devices/_device_datacls.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
from __future__ import annotations

import json
import warnings
from abc import ABC, abstractmethod
from collections import Counter
from dataclasses import dataclass, field, fields
Expand Down Expand Up @@ -87,7 +86,6 @@ class BaseDevice(ABC):
reusable_channels: bool = field(default=False, init=False)
channel_ids: tuple[str, ...] | None = None
channel_objects: tuple[Channel, ...] = field(default_factory=tuple)
_channels: tuple[tuple[str, Channel], ...] = field(default_factory=tuple)

def __post_init__(self) -> None:
def type_check(
Expand Down Expand Up @@ -152,30 +150,6 @@ def type_check(
f"not {self.max_layout_filling}."
)

if self._channels:
warnings.warn(
"Specifying the channels of a device through the '_channels'"
" argument is deprecated since v0.9.0 and will be removed in"
" v0.10.0. Instead, use 'channel_objects' to specify the"
" channels and, optionally, 'channel_ids' to specify custom"
" channel IDs.",
DeprecationWarning,
stacklevel=2,
)
if self.channel_objects or self.channel_ids:
raise ValueError(
"'_channels' can't be specified when 'channel_objects'"
" or 'channel_ids' are also provided."
)
ch_objs = []
ch_ids = []
for ch_id, ch_obj in self._channels:
ch_ids.append(ch_id)
ch_objs.append(ch_obj)
object.__setattr__(self, "channel_ids", tuple(ch_ids))
object.__setattr__(self, "channel_objects", tuple(ch_objs))
object.__setattr__(self, "_channels", ())

for ch_obj in self.channel_objects:
type_check("All channels", Channel, value_override=ch_obj)

Expand Down Expand Up @@ -436,7 +410,7 @@ def _to_dict(self) -> dict[str, Any]:

@abstractmethod
def _to_abstract_repr(self) -> dict[str, Any]:
ex_params = ("_channels", "channel_objects", "channel_ids")
ex_params = ("channel_objects", "channel_ids")
params = self._params()
for p in ex_params:
params.pop(p, None)
Expand Down
3 changes: 1 addition & 2 deletions pulser-core/pulser/json/abstract_repr/deserializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ def _deserialize_parameter(


def _deserialize_waveform(obj: dict, vars: dict) -> Waveform:

if obj["kind"] == "constant":
return ConstantWaveform(
duration=_deserialize_parameter(obj["duration"], vars),
Expand Down Expand Up @@ -302,7 +301,7 @@ def _deserialize_device_object(obj: dict[str, Any]) -> Device | VirtualDevice:
params: dict[str, Any] = dict(
channel_ids=tuple(ch_ids), channel_objects=tuple(ch_objs)
)
ex_params = ("_channels", "channel_objects", "channel_ids")
ex_params = ("channel_objects", "channel_ids")
for param in dataclasses.fields(device_cls):
if not param.init or param.name in ex_params:
continue
Expand Down
4 changes: 2 additions & 2 deletions pulser-core/pulser/parametrized/paramobj.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,8 @@ def __call__(self, *args: Any, **kwargs: Any) -> ParamObj:
def __getattr__(self, name: str) -> ParamObj:
if hasattr(self.cls, name):
warnings.warn(
"Serialization of 'getattr' calls to parametrized "
"objects is not supported, so this object can't be serialied.",
"Serialization of 'getattr' calls to parametrized objects "
"is not supported, so this object can't be serialized.",
stacklevel=2,
)
return ParamObj(getattr, self, name)
Expand Down
2 changes: 1 addition & 1 deletion pulser-core/pulser/register/_reg_drawer.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ def _initialize_fig_axes_projection(
)

proportions = []
for (ix, iy) in combinations(np.arange(3), 2):
for ix, iy in combinations(np.arange(3), 2):
big_side = max(diffs[[ix, iy]])
Ls = diffs[[ix, iy]] / big_side
Ls *= max(
Expand Down
28 changes: 21 additions & 7 deletions pulser-core/pulser/register/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import matplotlib.pyplot as plt
import numpy as np
from matplotlib.axes import Axes
from numpy.typing import ArrayLike

import pulser
Expand Down Expand Up @@ -296,6 +297,8 @@ def draw(
draw_half_radius: bool = False,
fig_name: str = None,
kwargs_savefig: dict = {},
custom_ax: Optional[Axes] = None,
show: bool = True,
) -> None:
"""Draws the entire register.
Expand All @@ -315,6 +318,13 @@ def draw(
kwargs_savefig: Keywords arguments for
``matplotlib.pyplot.savefig``. Not applicable if `fig_name`
is ``None``.
custom_ax: If present, instead of creating its own Axes object,
the function will use the provided one. Warning: if fig_name
is set, it may save content beyond what is drawn in this
function.
show: Whether or not to call `plt.show()` before returning. When
combining this plot with other ones in a single figure, one may
need to set this flag to False.
Note:
When drawing half the blockade radius, we say there is a blockade
Expand All @@ -328,14 +338,16 @@ def draw(
draw_graph=draw_graph,
draw_half_radius=draw_half_radius,
)

pos = np.array(self._coords)
fig, ax = self._initialize_fig_axes(
pos,
blockade_radius=blockade_radius,
draw_half_radius=draw_half_radius,
)
if custom_ax is None:
_, custom_ax = self._initialize_fig_axes(
pos,
blockade_radius=blockade_radius,
draw_half_radius=draw_half_radius,
)
super()._draw_2D(
ax,
custom_ax,
pos,
self._ids,
with_labels=with_labels,
Expand All @@ -345,7 +357,9 @@ def draw(
)
if fig_name is not None:
plt.savefig(fig_name, **kwargs_savefig)
plt.show()

if show:
plt.show()

def _to_dict(self) -> dict[str, Any]:
return super()._to_dict()
Expand Down
12 changes: 8 additions & 4 deletions pulser-core/pulser/sequence/_decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"""Custom decorators used by the Sequence class."""
from __future__ import annotations

from collections.abc import Callable, Iterable
from collections.abc import Callable
from functools import wraps
from itertools import chain
from typing import TYPE_CHECKING, Any, TypeVar, cast
Expand Down Expand Up @@ -58,10 +58,14 @@ def verify_variable(seq: Sequence, x: Any) -> None:
"Sequence's 'declare_variable' method as your"
"variables."
)
elif isinstance(x, Iterable) and not isinstance(x, str):
elif not isinstance(x, str):
# Recursively look for parametrized objs inside the arguments
for y in x:
verify_variable(seq, y)
try:
for y in x:
verify_variable(seq, y)
except TypeError:
# x is not iterable, do nothing
pass


def verify_parametrization(func: F) -> F:
Expand Down
Loading

0 comments on commit f7a1746

Please sign in to comment.