Skip to content

Commit

Permalink
Drop support for Python 3.8 (#743)
Browse files Browse the repository at this point in the history
* Drop support for python 3.8

* Relax matplotlib requirement

* Incorporate matplotlib type hints
  • Loading branch information
HGSilveri authored Oct 4, 2024
1 parent 96ab5c4 commit f04682b
Show file tree
Hide file tree
Showing 16 changed files with 114 additions and 61 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.8", "3.12"]
python-version: ["3.9", "3.12"]
with-torch: ["with-torch", "no-torch"]
steps:
- name: Check out Pulser
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
python-version: ["3.9", "3.10", "3.11", "3.12"]
steps:
- name: Check out Pulser
uses: actions/checkout@v4
Expand Down
8 changes: 3 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,12 @@ jobs:
strategy:
fail-fast: false
matrix:
# Python 3.8 and 3.9 does not run on macos-latest (14)
# Uses macos-13 for 3.8 and 3.9 and macos-latest for >=3.10
# Python 3.9 does not run on macos-latest (14)
# Uses macos-13 for 3.9 and macos-latest for >=3.10
os: [ubuntu-latest, macos-13, macos-latest, windows-latest]
with-torch: ["with-torch", "no-torch"]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
python-version: ["3.9", "3.10", "3.11", "3.12"]
exclude:
- os: macos-latest
python-version: "3.8"
- os: macos-latest
python-version: "3.9"
- os: macos-13
Expand Down
2 changes: 1 addition & 1 deletion .mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ warn_unused_ignores = True
disallow_untyped_defs = True

# 3rd-party libs without type hints nor stubs
[mypy-matplotlib.*,scipy.*,qutip.*,jsonschema.*,py.*]
[mypy-scipy.*,qutip.*,jsonschema.*,py.*]
follow_imports = silent
ignore_missing_imports = True

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ For a comprehensive overview of Pulser, check out [Pulser's white paper](https:/

**Note**: *Pulser v0.6 introduced a split of the ``pulser`` package that prevents it from being correctly upgraded. If you have an older version of ``pulser`` installed and wish to upgrade, make sure to uninstall it first by running ``pip uninstall pulser``.*

To install the latest release of ``pulser``, have Python 3.8 or higher installed, then use ``pip``:
To install the latest release of ``pulser``, have Python 3.9 or higher installed, then use ``pip``:

```bash
pip install pulser
Expand Down
2 changes: 1 addition & 1 deletion docs/source/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Installation

before proceeding to any of the steps below.

To install the latest release of ``pulser``, have Python 3.8 or higher
To install the latest release of ``pulser``, have Python 3.9 or higher
installed, then use ``pip``: ::

pip install pulser
Expand Down
56 changes: 40 additions & 16 deletions pulser-core/pulser/register/_reg_drawer.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from collections.abc import Mapping
from collections.abc import Sequence as abcSequence
from itertools import combinations
from typing import TYPE_CHECKING, Optional
from typing import TYPE_CHECKING, Any, Optional, Tuple, cast

import matplotlib.pyplot as plt
import numpy as np
Expand Down Expand Up @@ -48,15 +48,15 @@ def default_qubit_color() -> str:

@staticmethod
def _draw_2D(
ax: plt.axes._subplots.AxesSubplot,
ax: plt.Axes,
pos: np.ndarray,
ids: abcSequence[QubitId],
plane: tuple = (0, 1),
with_labels: bool = True,
blockade_radius: Optional[float] = None,
draw_graph: bool = True,
draw_half_radius: bool = False,
qubit_colors: Mapping[QubitId, str] = dict(),
qubit_colors: Mapping[QubitId, Any] = dict(),
masked_qubits: set[QubitId] = set(),
are_traps: bool = False,
dmm_qubits: Mapping[QubitId, float] = {},
Expand All @@ -68,6 +68,7 @@ def _draw_2D(

ix, iy = plane

params: dict[str, Any]
if are_traps:
params = dict(
s=50,
Expand Down Expand Up @@ -107,7 +108,7 @@ def _draw_2D(
dmm_arr[:, iy],
marker="s",
s=1200,
alpha=alpha,
alpha=alpha, # type: ignore[arg-type]
c="black" if not qubit_colors else ordered_qubit_colors,
)
axes = "xyz"
Expand Down Expand Up @@ -194,12 +195,12 @@ def _draw_2D(
fontsize=12 if i not in final_plot_det_map else 8.3,
multialignment="right",
)
txt._get_wrap_line_width = lambda: 50.0
txt._get_wrap_line_width = lambda: 50.0 # type: ignore

if draw_half_radius and blockade_radius is not None:
for p, color in zip(pos, ordered_qubit_colors):
circle = plt.Circle(
tuple(p[[ix, iy]]),
(p[ix], p[iy]),
blockade_radius / 2,
alpha=0.1,
color=color,
Expand All @@ -214,7 +215,11 @@ def _draw_2D(
lines = bonds[:, :, (ix, iy)]
else:
lines = np.array([])
lc = mc.LineCollection(lines, linewidths=0.6, colors="grey")
lc = mc.LineCollection(
cast(abcSequence[np.ndarray], lines),
linewidths=0.6,
colors="grey",
)
ax.add_collection(lc)

else:
Expand Down Expand Up @@ -258,9 +263,14 @@ def _draw_3D(
blockade_radius=blockade_radius,
draw_half_radius=draw_half_radius,
)
fig.get_layout_engine().set(w_pad=6.5)

for ax, (ix, iy) in zip(axes, combinations(np.arange(3), 2)):
_layout_engine = fig.get_layout_engine()
assert _layout_engine is not None
_layout_engine.set(w_pad=6.5) # type: ignore[call-arg]

for ax, (ix, iy) in zip(
cast(abcSequence[plt.Axes], axes),
combinations(np.arange(3), 2),
):
RegDrawer._draw_2D(
ax,
pos,
Expand All @@ -284,7 +294,12 @@ def _draw_3D(
)

else:
fig = plt.figure(figsize=2 * plt.figaspect(0.5))
fig = plt.figure(
figsize=cast(
Tuple[float, float],
tuple(2 * np.array(plt.figaspect(0.5))),
)
)

if draw_graph and blockade_radius is not None:
bonds = {}
Expand All @@ -293,6 +308,7 @@ def _draw_3D(
xj, yj, zj = pos[j]
bonds[(i, j)] = [[xi, xj], [yi, yj], [zi, zj]]

params: dict[str, Any]
if are_traps:
params = dict(s=50, c="white", edgecolors="black")
else:
Expand All @@ -313,7 +329,7 @@ def _draw_3D(
coords[0],
coords[1],
coords[2],
q,
q, # type: ignore[arg-type]
fontsize=12,
ha="left",
va="bottom",
Expand All @@ -336,15 +352,21 @@ def _draw_3D(
y = radius * np.sin(u) * np.sin(v) + y0
z = radius * np.cos(v) + z0
# alpha controls opacity
ax.plot_surface(x, y, z, color=color, alpha=0.1)
ax.plot_surface( # type: ignore[attr-defined]
x,
y,
z,
color=color,
alpha=0.1,
)

if draw_graph and blockade_radius is not None:
for x, y, z in bonds.values():
ax.plot(x, y, z, linewidth=1.5, color="grey")

ax.set_xlabel("x (µm)")
ax.set_ylabel("y (µm)")
ax.set_zlabel("z (µm)")
ax.set_zlabel("z (µm)") # type: ignore[attr-defined]

@staticmethod
def _register_dims(
Expand All @@ -367,7 +389,7 @@ def _initialize_fig_axes(
blockade_radius: Optional[float] = None,
draw_half_radius: bool = False,
nregisters: int = 1,
) -> tuple[plt.figure.Figure, plt.axes.Axes]:
) -> tuple[plt.Figure, plt.Axes | abcSequence[plt.Axes]]:
"""Creates the Figure and Axes for drawing the register."""
diffs = RegDrawer._register_dims(
pos,
Expand All @@ -394,7 +416,9 @@ def _initialize_fig_axes_projection(
blockade_radius: Optional[float] = None,
draw_half_radius: bool = False,
nregisters: int = 1,
) -> tuple[plt.figure.Figure, plt.axes.Axes]:
) -> tuple[
plt.Figure, abcSequence[plt.Axes] | abcSequence[abcSequence[plt.Axes]]
]:
"""Creates the Figure and Axes for drawing the register projections."""
diffs = RegDrawer._register_dims(
pos,
Expand Down
13 changes: 8 additions & 5 deletions pulser-core/pulser/register/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import warnings
from collections.abc import Mapping
from typing import Any, Optional, Union
from typing import Any, Optional, Union, cast

import matplotlib.pyplot as plt
import numpy as np
Expand Down Expand Up @@ -408,10 +408,13 @@ def draw(

pos = self._coords_arr.as_array(detach=True)
if custom_ax is None:
_, custom_ax = self._initialize_fig_axes(
pos,
blockade_radius=blockade_radius,
draw_half_radius=draw_half_radius,
custom_ax = cast(
plt.Axes,
self._initialize_fig_axes(
pos,
blockade_radius=blockade_radius,
draw_half_radius=draw_half_radius,
)[1],
)
super()._draw_2D(
custom_ax,
Expand Down
4 changes: 2 additions & 2 deletions pulser-core/pulser/register/register_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from collections.abc import Sequence as abcSequence
from dataclasses import dataclass
from operator import itemgetter
from typing import Any, Optional
from typing import Any, Optional, cast

import matplotlib.pyplot as plt
import numpy as np
Expand Down Expand Up @@ -180,7 +180,7 @@ def draw(
draw_half_radius=draw_half_radius,
)
self._draw_2D(
ax,
cast(plt.Axes, ax),
coords,
ids,
blockade_radius=blockade_radius,
Expand Down
3 changes: 1 addition & 2 deletions pulser-core/pulser/register/weight_maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,7 @@ def draw(
need to set this flag to False.
"""
pos = self.trap_coordinates
if custom_ax is None:
_, custom_ax = self._initialize_fig_axes(pos)
custom_ax = custom_ax or cast(Axes, self._initialize_fig_axes(pos)[1])

labels_ = labels if labels is not None else list(range(len(pos)))

Expand Down
Loading

0 comments on commit f04682b

Please sign in to comment.