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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃悰 Fix deprecated Loader.load_module() #728

Merged
merged 1 commit into from
Nov 4, 2022

Conversation

burgholzer
Copy link
Contributor

Any package that imports retworkx (such as qiskit-terra) under Python>=3.10 currently raises

ImportWarning: RetworkxLoader.exec_module() not found; falling back to load_module()

Any system that uses pytest and sets the filterwarnings feature to error will fail loudly as a consequence of this (see, e.g., https://github.com/cda-tum/qcec/actions/runs/3394728729/jobs/5643660360#step:4:453).

Loader.load_module() has been deprecated since Python 3.4 (https://docs.python.org/3/library/importlib.html#importlib.abc.Loader.load_module) and starting with 3.10, Python has started to actually raise the above ImportWarning.

This PR works around this issue by providing (rather straight-forward) implementations of the required Loader.create_module() and Loader.exec_module() methods. The fix is inspired by benjaminp/six#343.
With this PR, rustworkx and, in turn, qiskit can be used without errors under Python>=3.10.

burgholzer added a commit to cda-tum/mqt-qcec that referenced this pull request Nov 4, 2022
the errors were the result of an ImportWarning in rustworkx which pytest interprets as an error. See See Qiskit/rustworkx#728
Until that is fixed, this PR just ignores the corresponding warning.

Signed-off-by: burgholzer <burgholzer@me.com>
@IvanIsCoding
Copy link
Collaborator

I am pretty confident we copied this code from Qiskit/qiskit#5089 (so it does also impact Qiskit Terra). I'll let @mtreinish review it

@IvanIsCoding IvanIsCoding added the stable-backport-potential This PR or issue is potentially worth backporting for inclusion in a stable branch label Nov 4, 2022
Copy link
Member

@mtreinish mtreinish left a comment

Choose a reason for hiding this comment

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

Thanks for fixing this, I think this should do the trick and maintain compatibility with the new import API to avoid the warnings.

As @IvanIsCoding said I did just copy this from what I ended up doing in qiskit-terra. The warning has actually been reported in an issue on the qiskit already: Qiskit/qiskit#8853 and I had forgot to circle back and write a fix for it there. If you have the bandwidth would you mind push a similar PR to qiskit-terra to fix the same issue in its loader class (if not no worries).

@mtreinish mtreinish added the automerge Queue a approved PR for merging label Nov 4, 2022
@burgholzer
Copy link
Contributor Author

Sure. I'll do that over the weekend 馃憤馃徎

@coveralls
Copy link

Pull Request Test Coverage Report for Build 3395316397

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 3 unchanged lines in 2 files lost coverage.
  • Overall coverage increased (+0.05%) to 96.972%

Files with Coverage Reduction New Missed Lines %
src/shortest_path/all_pairs_bellman_ford.rs 1 99.44%
src/shortest_path/all_pairs_dijkstra.rs 2 98.54%
Totals Coverage Status
Change from base Build 3390761019: 0.05%
Covered Lines: 13641
Relevant Lines: 14067

馃挍 - Coveralls

@mergify mergify bot merged commit 53f0e31 into Qiskit:main Nov 4, 2022
mergify bot pushed a commit that referenced this pull request Nov 4, 2022
mergify bot added a commit that referenced this pull request Nov 4, 2022
(cherry picked from commit 53f0e31)

Co-authored-by: Lukas Burgholzer <lukas.burgholzer@jku.at>
@burgholzer
Copy link
Contributor Author

See Qiskit/qiskit#9078.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge Queue a approved PR for merging stable-backport-potential This PR or issue is potentially worth backporting for inclusion in a stable branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants