Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replacing semantic version with Version #5754

Merged
merged 5 commits into from
May 29, 2024

Conversation

PietropaoloFrisoni
Copy link
Contributor

@PietropaoloFrisoni PietropaoloFrisoni commented May 28, 2024

Context: This bug is related to the fact that semantic_version cannot handle a string ending with .post4. Without installing a different pytorch version, it can simply be reproduced as follows.

This is the code snippet to reproduce the error

import semantic_version
string_to_test = '2.1.2.post4'
>>> semantic_version.match(">=1.10.0", string_to_test)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
(....)
ValueError: Invalid version string: '2.1.2.post4'

which is fixed by:

from packaging.version import Version
string_to_test = '2.1.2.post4'
>>> Version(string_to_test) >= Version("1.10.0")
True

Description of the Change: We replace semantic_version with Version, which can handle such a string.

Benefits: The bug does not arise if the user has a torch installation ending with .post4

Possible Drawbacks: None that I can think of.

Related GitHub Issues: #5689

Related Shortcut Stories [sc-63356]

Copy link

codecov bot commented May 28, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.67%. Comparing base (5b192e6) to head (8894bd5).
Report is 264 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5754      +/-   ##
==========================================
- Coverage   99.67%   99.67%   -0.01%     
==========================================
  Files         416      416              
  Lines       38686    38393     -293     
==========================================
- Hits        38562    38268     -294     
- Misses        124      125       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@PietropaoloFrisoni PietropaoloFrisoni marked this pull request as ready for review May 29, 2024 12:44
@PennyLaneAI PennyLaneAI deleted a comment from github-actions bot May 29, 2024
Copy link
Contributor

@albi3ro albi3ro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@PietropaoloFrisoni PietropaoloFrisoni merged commit f5b805b into master May 29, 2024
40 checks passed
@PietropaoloFrisoni PietropaoloFrisoni deleted the bugfix-PauliRot_torch_interface branch May 29, 2024 18:29
PietropaoloFrisoni added a commit that referenced this pull request May 31, 2024
**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].
PietropaoloFrisoni added a commit that referenced this pull request Jun 9, 2024
**Context:** After #5769 and #5754, we can potentially replace all the
occurrences of the `semantic_version` package with `packaging` in the
PennyLane source code, and remove `semantic_version` from the required
Python packages.

**Description of the Change:** As stated above, we replace the remaining
occurrences of `semantic_version` with `packaging` and remove
`semantic_version` from the required packages in PennyLane.

**Benefits:** One package less to keep track of in the dependencies.

**Possible Drawbacks:** None that I can think of, providing that there
are no incompatibilities with the previous workflow (in which case, we
can always revert this PR)

**Related GitHub Issues:** None.

**Related ShortCut Stories:** [sc-64659]
PietropaoloFrisoni added a commit that referenced this pull request Aug 1, 2024
**Context:** After #5769 and #5754, we can potentially replace all the
occurrences of the `semantic_version` package with `packaging` in the
PennyLane source code, and remove `semantic_version` from the required
Python packages. A similar attempt was performed in #5782, but it was
reverted due to some errors in the plugin-matrix tests.

**Description of the Change:** We replace the remaining occurrences of
`semantic_version` with `packaging` and remove `semantic_version` from
the required packages in PennyLane. With respect to #5782, now the
plugins can be correctly instantiated as:

```
dev = qml.device("qiskit.aer", wires=2)

dev = qml.device("cirq.simulator", wires=1)
```
etc.

Specifically, the reason was the usage of `packaging` to replace
`semantic_version`in the `pennylane/__init__.py` file. There was an
incompatibility between the workflow of the two packages. Right now, the
replacement has been performed to maintain the workflow. For example,

```
from packaging.specifiers import SpecifierSet, Specifier
from packaging.version import Version

pennylane_requires = ">=0.37.0"
version = "0.38.0.dev0"
>>> Version(version) in SpecifierSet(pennylane_requires)
False
>>> Version(version) in SpecifierSet(pennylane_requires, prereleases=True)
True
```

**Benefits:** One package less to keep track of in the dependencies.

**Possible Drawbacks:** Errors in the plugin-text matrix. If they
happen, we'll react as quickly as possible.

**Related GitHub Issues:** None.

**Related Shortcut Stories** [sc-64659]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants