Skip to content

Commit

Permalink
Add packaging as a new required package in PennyLane (#5769)
Browse files Browse the repository at this point in the history
**Context:** In #5754, we forgot to add `packaging` as a new hard
requirement for PennyLane. Some developers experienced troubles when
importing PL.

**Description of the Change:** We included `packaging` in the relevant
contexts as a new required package.

**Benefits:** The user would not experience trouble importing PennyLane
if `packaging` is not installed on his/her system.

**Possible Drawbacks:** None that I can think of, except possible issues
with external plugins for incompatibilities between the previous
workflow of `semantic_version` and the new one of `packaging` (in which
case, we can quickly restore the previous `semantic_version` usage where
it occurs).

**Related GitHub Issues:** None.

**Related Shortcut Stories:** [sc-64576].
  • Loading branch information
PietropaoloFrisoni committed May 31, 2024
1 parent ec9fd26 commit 2a36a35
Show file tree
Hide file tree
Showing 13 changed files with 28 additions and 17 deletions.
6 changes: 3 additions & 3 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@
# A comma-separated list of package or module names from where C extensions may
# be loaded. Extensions are loading into the active Python interpreter and may
# run arbitrary code
extension-pkg-whitelist=numpy,scipy,autograd,toml,appdir,autograd.numpy,autograd.numpy.linalg,autograd.numpy.builtins,semantic_version,torch,tensorflow,tensorflow.contrib,tensorflow.contrib.eager,LazyLoader,networkx,networkx.dag
extension-pkg-whitelist=numpy,scipy,autograd,toml,appdir,autograd.numpy,autograd.numpy.linalg,autograd.numpy.builtins,semantic_version,packaging,torch,tensorflow,tensorflow.contrib,tensorflow.contrib.eager,LazyLoader,networkx,networkx.dag

[TYPECHECK]

# List of module names for which member attributes should not be checked
# (useful for modules/projects where namespaces are manipulated during runtime
# and thus existing member attributes cannot be deduced by static analysis. It
# supports qualified module names, as well as Unix pattern matching.
ignored-modules=numpy,scipy,autograd,toml,appdir,autograd.numpy,autograd.numpy.linalg,autograd.numpy.builtins,semantic_version,torch,tensorflow,tensorflow.contrib,tensorflow.contrib.eager,LazyLoader,networkx,networkx.dag,math,pennylane.numpy
ignored-modules=numpy,scipy,autograd,toml,appdir,autograd.numpy,autograd.numpy.linalg,autograd.numpy.builtins,semantic_version,packaging,torch,tensorflow,tensorflow.contrib,tensorflow.contrib.eager,LazyLoader,networkx,networkx.dag,math,pennylane.numpy

# List of classes names for which member attributes should not be checked
# (useful for classes with attributes dynamically set). This supports can work
# with qualified names.
ignored-classes=numpy,scipy,autograd,toml,appdir,autograd.numpy,autograd.numpy.linalg,autograd.numpy.builtins,semantic_version,torch,tensorflow,tensorflow.contrib,tensorflow.contrib.eager,LazyLoader,networkx,networkx.dag,math,pennylane.numpy,pennylane.numpy.random,pennylane.numpy.linalg,pennylane.numpy.builtins,pennylane.operation,rustworkx,kahypar
ignored-classes=numpy,scipy,autograd,toml,appdir,autograd.numpy,autograd.numpy.linalg,autograd.numpy.builtins,semantic_version,packaging,torch,tensorflow,tensorflow.contrib,tensorflow.contrib.eager,LazyLoader,networkx,networkx.dag,math,pennylane.numpy,pennylane.numpy.random,pennylane.numpy.linalg,pennylane.numpy.builtins,pennylane.operation,rustworkx,kahypar

[MESSAGES CONTROL]

Expand Down
1 change: 1 addition & 0 deletions doc/development/guide/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ be installed alongside PennyLane:
* `appdirs <https://github.com/ActiveState/appdirs>`_
* `semantic-version <https://github.com/rbarrois/python-semanticversion>`_ >= 2.7
* `autoray <https://github.com/jcmgray/autoray>`__ >= 0.6.11
* `packaging <https://github.com/pypa/packaging>`_

The following Python packages are optional:

Expand Down
3 changes: 3 additions & 0 deletions doc/releases/changelog-dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@

<h3>Improvements 🛠</h3>

* Added `packaging` in the required list of packages.
[(#5769)](https://github.com/PennyLaneAI/pennylane/pull/5769).

* Logging now allows for an easier opt-in across the stack, and also extends control support to `catalyst`.
[(#5528)](https://github.com/PennyLaneAI/pennylane/pull/5528).

Expand Down
1 change: 1 addition & 0 deletions doc/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ m2r2
numpy
pygments-github-lexers
semantic_version==2.10
packaging
scipy
docutils==0.16
sphinx~=3.5.0; python_version < "3.10"
Expand Down
3 changes: 2 additions & 1 deletion pennylane/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2018-2021 Xanadu Quantum Technologies Inc.
# Copyright 2018-2024 Xanadu Quantum Technologies Inc.

# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -20,6 +20,7 @@


import numpy as _np

from semantic_version import SimpleSpec, Version

from pennylane.boolean_fn import BooleanFn
Expand Down
2 changes: 1 addition & 1 deletion pennylane/compiler/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from sys import version_info
from typing import List, Optional

from semantic_version import Version
from packaging.version import Version

PL_CATALYST_MIN_VERSION = Version("0.6.0")

Expand Down
6 changes: 3 additions & 3 deletions pennylane/devices/default_qubit_tf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2018-2021 Xanadu Quantum Technologies Inc.
# Copyright 2018-2024 Xanadu Quantum Technologies Inc.

# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -17,7 +17,7 @@
import itertools

import numpy as np
import semantic_version
from packaging.version import Version

import pennylane as qml

Expand All @@ -29,7 +29,7 @@

from tensorflow.python.framework.errors_impl import InvalidArgumentError

SUPPORTS_APPLY_OPS = semantic_version.match(">=2.3.0", tf.__version__)
SUPPORTS_APPLY_OPS = Version(tf.__version__) >= Version("2.3.0")

except ImportError as e: # pragma: no cover
raise ImportError("default.qubit.tf device requires TensorFlow>=2.0") from e
Expand Down
8 changes: 5 additions & 3 deletions pennylane/devices/default_qubit_torch.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2018-2021 Xanadu Quantum Technologies Inc.
# Copyright 2018-2024 Xanadu Quantum Technologies Inc.

# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -18,12 +18,14 @@
import logging
import warnings

import semantic_version
from packaging.version import Version

try:
import torch

VERSION_SUPPORT = semantic_version.match(">=1.8.1", torch.__version__)
VERSION_SUPPORT = Version(torch.__version__) >= Version(
"1.8.1",
)
if not VERSION_SUPPORT: # pragma: no cover
raise ImportError("default.qubit.torch device requires Torch>=1.8.1")

Expand Down
4 changes: 2 additions & 2 deletions pennylane/qnn/keras.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2018-2021 Xanadu Quantum Technologies Inc.
# Copyright 2018-2024 Xanadu Quantum Technologies Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -17,7 +17,7 @@
from collections.abc import Iterable
from typing import Optional, Text

from semantic_version import Version
from packaging.version import Version

try:
import tensorflow as tf
Expand Down
1 change: 1 addition & 0 deletions requirements-ci.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ autograd
toml
appdirs
semantic_version
packaging
autoray>=0.6.1,<0.6.10
matplotlib
requests
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ autograd~=1.4
toml~=0.10
appdirs~=1.4
semantic_version~=2.10
packaging
autoray>=0.6.11
matplotlib~=3.5
opt_einsum~=3.3
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2018-2020 Xanadu Quantum Technologies Inc.
# Copyright 2018-2024 Xanadu Quantum Technologies Inc.

# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -34,6 +34,7 @@
"pennylane-lightning>=0.36",
"requests",
"typing_extensions",
"packaging",
]

info = {
Expand Down
6 changes: 3 additions & 3 deletions tests/.pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@
# A comma-separated list of package or module names from where C extensions may
# be loaded. Extensions are loading into the active Python interpreter and may
# run arbitrary code
extension-pkg-whitelist=numpy,scipy,autograd,toml,appdir,autograd.numpy,autograd.numpy.linalg,autograd.numpy.builtins,semantic_version,torch,tensorflow,tensorflow.contrib,tensorflow.contrib.eager,LazyLoader,networkx,networkx.dag
extension-pkg-whitelist=numpy,scipy,autograd,toml,appdir,autograd.numpy,autograd.numpy.linalg,autograd.numpy.builtins,semantic_version,packaging,torch,tensorflow,tensorflow.contrib,tensorflow.contrib.eager,LazyLoader,networkx,networkx.dag

[TYPECHECK]

# List of module names for which member attributes should not be checked
# (useful for modules/projects where namespaces are manipulated during runtime
# and thus existing member attributes cannot be deduced by static analysis. It
# supports qualified module names, as well as Unix pattern matching.
ignored-modules=numpy,scipy,autograd,toml,appdir,autograd.numpy,autograd.numpy.linalg,autograd.numpy.builtins,semantic_version,torch,tensorflow,tensorflow.contrib,tensorflow.contrib.eager,LazyLoader,networkx,networkx.dag,math,pennylane.numpy
ignored-modules=numpy,scipy,autograd,toml,appdir,autograd.numpy,autograd.numpy.linalg,autograd.numpy.builtins,semantic_version,packaging,torch,tensorflow,tensorflow.contrib,tensorflow.contrib.eager,LazyLoader,networkx,networkx.dag,math,pennylane.numpy

# List of classes names for which member attributes should not be checked
# (useful for classes with attributes dynamically set). This supports can work
# with qualified names.
ignored-classes=numpy,scipy,autograd,toml,appdir,autograd.numpy,autograd.numpy.linalg,autograd.numpy.builtins,semantic_version,torch,tensorflow,tensorflow.contrib,tensorflow.contrib.eager,LazyLoader,networkx,networkx.dag,math,pennylane.numpy,pennylane.numpy.random,pennylane.numpy.linalg,pennylane.numpy.builtins,pennylane.operation,rustworkx,kahypar
ignored-classes=numpy,scipy,autograd,toml,appdir,autograd.numpy,autograd.numpy.linalg,autograd.numpy.builtins,semantic_version,packaging,torch,tensorflow,tensorflow.contrib,tensorflow.contrib.eager,LazyLoader,networkx,networkx.dag,math,pennylane.numpy,pennylane.numpy.random,pennylane.numpy.linalg,pennylane.numpy.builtins,pennylane.operation,rustworkx,kahypar

[MESSAGES CONTROL]

Expand Down

0 comments on commit 2a36a35

Please sign in to comment.