From ea0cc42a089549305ff8877180c0e38fc35500d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrique=20Silv=C3=A9rio?= Date: Tue, 2 May 2023 17:13:38 +0200 Subject: [PATCH] Drop support for Python 3.7 (#513) * Dropping support for python 3.7 * Using pos-only arguments in binary operators --------- Co-authored-by: Antoine Cornillot <61453516+a-corni@users.noreply.github.com> --- .github/workflows/ci.yml | 2 +- .github/workflows/publish.yml | 2 +- .github/workflows/test.yml | 2 +- README.md | 2 +- docs/source/installation.rst | 2 +- pulser-core/pulser/channels/base_channel.py | 15 +--------- pulser-core/pulser/devices/_device_datacls.py | 15 +--------- pulser-core/pulser/parametrized/paramobj.py | 29 +++++++++---------- .../pulser/register/register_layout.py | 14 +-------- pulser-core/pulser/sequence/sequence.py | 15 ++-------- pulser-core/pulser/waveforms.py | 14 +-------- pulser-core/requirements.txt | 2 -- pulser-core/setup.py | 2 +- pulser-pasqal/setup.py | 2 +- .../pulser_simulation/simconfig.py | 15 +--------- pulser-simulation/requirements.txt | 1 - pulser-simulation/setup.py | 2 +- setup.py | 2 +- 18 files changed, 30 insertions(+), 108 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 00b9b3a13..e42cf5a9b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -58,7 +58,7 @@ jobs: strategy: fail-fast: false matrix: - python-version: ["3.7", "3.11"] + python-version: ["3.8", "3.11"] steps: - name: Check out Pulser uses: actions/checkout@v3 diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 35c608225..84bdc322a 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -66,7 +66,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest, macos-latest, windows-latest] - python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"] + python-version: ["3.8", "3.9", "3.10", "3.11"] steps: - name: Check out Pulser uses: actions/checkout@v3 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 31c3b491d..270785a45 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -16,7 +16,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest, macos-latest, windows-latest] - python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"] + python-version: ["3.8", "3.9", "3.10", "3.11"] steps: - name: Check out Pulser uses: actions/checkout@v3 diff --git a/README.md b/README.md index 00b8e5af1..65c677742 100644 --- a/README.md +++ b/README.md @@ -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.7.0 or higher installed, then use ``pip``: +To install the latest release of ``pulser``, have Python 3.8 or higher installed, then use ``pip``: ```bash pip install pulser diff --git a/docs/source/installation.rst b/docs/source/installation.rst index 36d348199..57a7905c7 100644 --- a/docs/source/installation.rst +++ b/docs/source/installation.rst @@ -10,7 +10,7 @@ Installation before proceeding to any of the steps below. -To install the latest release of ``pulser``, have Python 3.7.0 or higher +To install the latest release of ``pulser``, have Python 3.8 or higher installed, then use ``pip``: :: pip install pulser diff --git a/pulser-core/pulser/channels/base_channel.py b/pulser-core/pulser/channels/base_channel.py index c8cd61dfc..5b9ba3a22 100644 --- a/pulser-core/pulser/channels/base_channel.py +++ b/pulser-core/pulser/channels/base_channel.py @@ -18,8 +18,7 @@ import warnings from abc import ABC, abstractmethod from dataclasses import dataclass, field, fields -from sys import version_info -from typing import Any, Optional, Type, TypeVar, cast +from typing import Any, Literal, Optional, Type, TypeVar, cast import numpy as np from numpy.typing import ArrayLike @@ -29,18 +28,6 @@ from pulser.json.utils import obj_to_dict from pulser.pulse import Pulse -if version_info[:2] >= (3, 8): # pragma: no cover - from typing import Literal -else: # pragma: no cover - try: - from typing_extensions import Literal # type: ignore - except ImportError: - raise ImportError( - "Using pulser with Python version 3.7 requires the" - " `typing_extensions` module. Install it by running" - " `pip install typing-extensions`." - ) - # Warnings of adjusted waveform duration appear just once warnings.filterwarnings("once", "A duration of") diff --git a/pulser-core/pulser/devices/_device_datacls.py b/pulser-core/pulser/devices/_device_datacls.py index c04e239af..e685e96af 100644 --- a/pulser-core/pulser/devices/_device_datacls.py +++ b/pulser-core/pulser/devices/_device_datacls.py @@ -18,8 +18,7 @@ from abc import ABC, abstractmethod from collections import Counter from dataclasses import dataclass, field, fields -from sys import version_info -from typing import Any, cast +from typing import Any, Literal, cast, get_args import numpy as np from scipy.spatial.distance import pdist, squareform @@ -32,18 +31,6 @@ from pulser.register.mappable_reg import MappableRegister from pulser.register.register_layout import COORD_PRECISION, RegisterLayout -if version_info[:2] >= (3, 8): # pragma: no cover - from typing import Literal, get_args -else: # pragma: no cover - try: - from typing_extensions import Literal, get_args # type: ignore - except ImportError: - raise ImportError( - "Using pulser with Python version 3.7 requires the" - " `typing_extensions` module. Install it by running" - " `pip install typing-extensions`." - ) - DIMENSIONS = Literal[2, 3] diff --git a/pulser-core/pulser/parametrized/paramobj.py b/pulser-core/pulser/parametrized/paramobj.py index 60675d05d..d730bee3e 100644 --- a/pulser-core/pulser/parametrized/paramobj.py +++ b/pulser-core/pulser/parametrized/paramobj.py @@ -42,7 +42,6 @@ class OpSupport: """Methods for supporting operators on parametrized objects.""" - # TODO: Make operator methods' args pos-only when python 3.7 is dropped # Unary operators def __neg__(self) -> ParamObj: return ParamObj(operator.neg, self) @@ -93,46 +92,46 @@ def tan(self) -> ParamObj: return ParamObj(np.tan, self) # Binary operators - def __add__(self, other: Union[int, float]) -> ParamObj: + def __add__(self, other: Union[int, float], /) -> ParamObj: return ParamObj(operator.add, self, other) - def __radd__(self, other: Union[int, float]) -> ParamObj: + def __radd__(self, other: Union[int, float], /) -> ParamObj: return ParamObj(operator.add, other, self) - def __sub__(self, other: Union[int, float]) -> ParamObj: + def __sub__(self, other: Union[int, float], /) -> ParamObj: return ParamObj(operator.sub, self, other) - def __rsub__(self, other: Union[int, float]) -> ParamObj: + def __rsub__(self, other: Union[int, float], /) -> ParamObj: return ParamObj(operator.sub, other, self) - def __mul__(self, other: Union[int, float]) -> ParamObj: + def __mul__(self, other: Union[int, float], /) -> ParamObj: return ParamObj(operator.mul, self, other) - def __rmul__(self, other: Union[int, float]) -> ParamObj: + def __rmul__(self, other: Union[int, float], /) -> ParamObj: return ParamObj(operator.mul, other, self) - def __truediv__(self, other: Union[int, float]) -> ParamObj: + def __truediv__(self, other: Union[int, float], /) -> ParamObj: return ParamObj(operator.truediv, self, other) - def __rtruediv__(self, other: Union[int, float]) -> ParamObj: + def __rtruediv__(self, other: Union[int, float], /) -> ParamObj: return ParamObj(operator.truediv, other, self) - def __floordiv__(self, other: Union[int, float]) -> ParamObj: + def __floordiv__(self, other: Union[int, float], /) -> ParamObj: return (self / other).__floor__() - def __rfloordiv__(self, other: Union[int, float]) -> ParamObj: + def __rfloordiv__(self, other: Union[int, float], /) -> ParamObj: return (other / self).__floor__() - def __pow__(self, other: Union[int, float]) -> ParamObj: + def __pow__(self, other: Union[int, float], /) -> ParamObj: return ParamObj(operator.pow, self, other) - def __rpow__(self, other: Union[int, float]) -> ParamObj: + def __rpow__(self, other: Union[int, float], /) -> ParamObj: return ParamObj(operator.pow, other, self) - def __mod__(self, other: Union[int, float]) -> ParamObj: + def __mod__(self, other: Union[int, float], /) -> ParamObj: return ParamObj(operator.mod, self, other) - def __rmod__(self, other: Union[int, float]) -> ParamObj: + def __rmod__(self, other: Union[int, float], /) -> ParamObj: return ParamObj(operator.mod, other, self) diff --git a/pulser-core/pulser/register/register_layout.py b/pulser-core/pulser/register/register_layout.py index 41c72c8dd..a8aa8143a 100644 --- a/pulser-core/pulser/register/register_layout.py +++ b/pulser-core/pulser/register/register_layout.py @@ -17,8 +17,8 @@ from collections.abc import Sequence as abcSequence from dataclasses import dataclass +from functools import cached_property from hashlib import sha256 -from sys import version_info from typing import Any, Optional, cast import matplotlib.pyplot as plt @@ -32,18 +32,6 @@ from pulser.register.register import Register from pulser.register.register3d import Register3D -if version_info[:2] >= (3, 8): # pragma: no cover - from functools import cached_property -else: # pragma: no cover - try: - from backports.cached_property import cached_property # type: ignore - except ImportError: - raise ImportError( - "Using pulser with Python version 3.7 requires the" - " `backports.cached-property` module. Install it by running" - " `pip install backports.cached-property`." - ) - COORD_PRECISION = 6 diff --git a/pulser-core/pulser/sequence/sequence.py b/pulser-core/pulser/sequence/sequence.py index 62df7f30d..f343dae55 100644 --- a/pulser-core/pulser/sequence/sequence.py +++ b/pulser-core/pulser/sequence/sequence.py @@ -20,15 +20,16 @@ import os import warnings from collections.abc import Iterable, Mapping -from sys import version_info from typing import ( Any, Generic, + Literal, Optional, Tuple, TypeVar, Union, cast, + get_args, overload, ) @@ -58,18 +59,6 @@ from pulser.sequence._seq_drawer import Figure, draw_sequence from pulser.sequence._seq_str import seq_to_str -if version_info[:2] >= (3, 8): # pragma: no cover - from typing import Literal, get_args -else: # pragma: no cover - try: - from typing_extensions import Literal, get_args # type: ignore - except ImportError: - raise ImportError( - "Using pulser with Python version 3.7 requires the" - " `typing_extensions` module. Install it by running" - " `pip install typing-extensions`." - ) - DeviceType = TypeVar("DeviceType", bound=BaseDevice) PROTOCOLS = Literal["min-delay", "no-delay", "wait-for-all"] diff --git a/pulser-core/pulser/waveforms.py b/pulser-core/pulser/waveforms.py index 4ac25e0f1..44f8b668f 100644 --- a/pulser-core/pulser/waveforms.py +++ b/pulser-core/pulser/waveforms.py @@ -21,7 +21,7 @@ import sys import warnings from abc import ABC, abstractmethod -from sys import version_info +from functools import cached_property from types import FunctionType from typing import TYPE_CHECKING, Any, Optional, Tuple, Union, cast @@ -40,18 +40,6 @@ if TYPE_CHECKING: from pulser.channels.base_channel import Channel -if version_info[:2] >= (3, 8): # pragma: no cover - from functools import cached_property -else: # pragma: no cover - try: - from backports.cached_property import cached_property # type: ignore - except ImportError: - raise ImportError( - "Using pulser with Python version 3.7 requires the" - " `backports.cached-property` module. Install it by running" - " `pip install backports.cached-property`." - ) - class Waveform(ABC): """The abstract class for a pulse's waveform.""" diff --git a/pulser-core/requirements.txt b/pulser-core/requirements.txt index a1424abcb..2621a2ccb 100644 --- a/pulser-core/requirements.txt +++ b/pulser-core/requirements.txt @@ -3,5 +3,3 @@ matplotlib # Numpy 1.20 introduces type hints, 1.24.0 breaks matplotlib < 3.6.1 numpy >= 1.20, != 1.24.0 scipy -backports.cached-property; python_version == '3.7' -typing-extensions; python_version == '3.7' diff --git a/pulser-core/setup.py b/pulser-core/setup.py index 7667c387e..0928bed64 100644 --- a/pulser-core/setup.py +++ b/pulser-core/setup.py @@ -50,7 +50,7 @@ long_description=open("README.md").read(), long_description_content_type="text/markdown", author="Pulser Development Team", - python_requires=">=3.7.0", + python_requires=">=3.8", license="Apache 2.0", classifiers=[ "Development Status :: 3 - Alpha", diff --git a/pulser-pasqal/setup.py b/pulser-pasqal/setup.py index 8629b4de0..228289bbe 100644 --- a/pulser-pasqal/setup.py +++ b/pulser-pasqal/setup.py @@ -55,7 +55,7 @@ long_description=open("README.md").read(), long_description_content_type="text/markdown", author="Pulser Development Team", - python_requires=">=3.7.0", + python_requires=">=3.8", license="Apache 2.0", classifiers=[ "Development Status :: 3 - Alpha", diff --git a/pulser-simulation/pulser_simulation/simconfig.py b/pulser-simulation/pulser_simulation/simconfig.py index 78d02a287..aa9c7816e 100644 --- a/pulser-simulation/pulser_simulation/simconfig.py +++ b/pulser-simulation/pulser_simulation/simconfig.py @@ -16,24 +16,11 @@ from __future__ import annotations from dataclasses import dataclass, field -from sys import version_info -from typing import Any, Optional, Union +from typing import Any, Literal, Optional, Union, get_args import numpy as np import qutip -if version_info[:2] >= (3, 8): # pragma: no cover - from typing import Literal, get_args -else: # pragma: no cover - try: - from typing_extensions import Literal, get_args # type: ignore - except ImportError: - raise ImportError( - "Using pulser with Python version 3.7 requires the" - " `typing_extensions` module. Install it by running" - " `pip install typing-extensions`." - ) - NOISE_TYPES = Literal[ "doppler", "amplitude", "SPAM", "dephasing", "depolarizing", "eff_noise" ] diff --git a/pulser-simulation/requirements.txt b/pulser-simulation/requirements.txt index e296eb4a3..59c46d8fc 100644 --- a/pulser-simulation/requirements.txt +++ b/pulser-simulation/requirements.txt @@ -1,2 +1 @@ qutip>=4.7.1 -typing-extensions; python_version == '3.7' diff --git a/pulser-simulation/setup.py b/pulser-simulation/setup.py index bd9ec0476..421dffdec 100644 --- a/pulser-simulation/setup.py +++ b/pulser-simulation/setup.py @@ -51,7 +51,7 @@ long_description=open("README.md").read(), long_description_content_type="text/markdown", author="Pulser Development Team", - python_requires=">=3.7.0", + python_requires=">=3.8", license="Apache 2.0", classifiers=[ "Development Status :: 3 - Alpha", diff --git a/setup.py b/setup.py index d58354def..25f8faf96 100644 --- a/setup.py +++ b/setup.py @@ -37,7 +37,7 @@ long_description=open("README.md").read(), long_description_content_type="text/markdown", author="Pulser Development Team", - python_requires=">=3.7.0", + python_requires=">=3.8", license="Apache 2.0", classifiers=[ "Development Status :: 3 - Alpha",