Skip to content

Commit 090e70c

Browse files
Add support for Python 3.11 (#512)
* Add support for Python 3.11 * fix pylint * remove dataset_helper.py * update setup.py * unpin dill * update workflow * update reno * rephrase reno --------- Co-authored-by: Anton Dekusar <[email protected]> Co-authored-by: Anton Dekusar <[email protected]>
1 parent 09e6c12 commit 090e70c

22 files changed

+171
-202
lines changed

.github/workflows/main.yml

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This code is part of Qiskit.
22
#
3-
# (C) Copyright IBM 2021, 2022.
3+
# (C) Copyright IBM 2021, 2023.
44
#
55
# This code is licensed under the Apache License, Version 2.0. You may
66
# obtain a copy of this license in the LICENSE.txt file in the root directory
@@ -63,22 +63,22 @@ jobs:
6363
- uses: ./.github/actions/install-machine-learning
6464
- name: Install Dependencies
6565
run: |
66-
pip install jupyter qiskit-terra[visualization] 'torchvision<0.10.0'
66+
pip install torchvision
6767
sudo apt-get -y install pandoc graphviz
6868
sudo apt-get -y install python3-enchant
6969
sudo apt-get -y install hunspell-en-us
7070
pip install pyenchant
7171
echo "earliest_version: 0.1.0" >> releasenotes/config.yaml
7272
shell: bash
73-
- run: pip check
73+
- run: pip check
7474
if: ${{ !cancelled() }}
7575
shell: bash
7676
- name: Copyright Check
7777
run: |
7878
python tools/check_copyright.py -check
7979
if: ${{ !cancelled() }}
8080
shell: bash
81-
- run: make spell
81+
- run: make spell
8282
if: ${{ !cancelled() }}
8383
shell: bash
8484
- name: Style Check
@@ -88,7 +88,7 @@ jobs:
8888
if: ${{ !cancelled() }}
8989
shell: bash
9090
- name: Run make html
91-
run: |
91+
run: |
9292
make clean_sphinx
9393
make html
9494
cd docs/_build/html
@@ -102,7 +102,7 @@ jobs:
102102
name: documentation
103103
path: docs/_build/html/artifacts/documentation.tar.gz
104104
if: ${{ !cancelled() }}
105-
- run: make doctest
105+
- run: make doctest
106106
if: ${{ !cancelled() }}
107107
shell: bash
108108
MachineLearning:
@@ -111,16 +111,16 @@ jobs:
111111
fail-fast: false
112112
matrix:
113113
os: [ubuntu-latest]
114-
python-version: [3.7, 3.8, 3.9, '3.10']
114+
python-version: [3.7, 3.8, 3.9, '3.10', 3.11]
115115
include:
116116
- os: macos-latest
117117
python-version: 3.8
118118
- os: macos-latest
119-
python-version: '3.10'
119+
python-version: 3.11
120120
- os: windows-2019
121121
python-version: 3.8
122122
- os: windows-2019
123-
python-version: '3.10'
123+
python-version: 3.11
124124
steps:
125125
- uses: actions/checkout@v3
126126
- uses: actions/setup-python@v4
@@ -140,12 +140,7 @@ jobs:
140140
- run: make lint
141141
shell: bash
142142
- run: make mypy
143-
if: ${{ !cancelled() && matrix.python-version != '3.10' }}
144-
shell: bash
145-
- name: Run make lint latest version
146-
run: |
147-
pip install -U -r requirements-dev.txt
148-
make lint
143+
if: ${{ !cancelled() && matrix.python-version != '3.10' && matrix.python-version != 3.11 }}
149144
shell: bash
150145
- name: Machine Learning Unit Tests under Python ${{ matrix.python-version }}
151146
uses: ./.github/actions/run-tests
@@ -186,7 +181,7 @@ jobs:
186181
fail-fast: false
187182
matrix:
188183
os: [ubuntu-latest]
189-
python-version: [3.7, 3.8]
184+
python-version: [3.8, 3.11]
190185
steps:
191186
- uses: actions/checkout@v3
192187
with:
@@ -207,7 +202,7 @@ jobs:
207202
- uses: ./.github/actions/install-machine-learning
208203
- name: Install Dependencies
209204
run: |
210-
pip install jupyter qiskit-terra[visualization] 'torchvision<0.10.0'
205+
pip install torchvision
211206
sudo apt-get install -y pandoc graphviz
212207
shell: bash
213208
- name: Run Machine Learning Tutorials
@@ -283,28 +278,32 @@ jobs:
283278
with:
284279
name: ubuntu-latest-3.10
285280
path: /tmp/u310
281+
- uses: actions/download-artifact@v3
282+
with:
283+
name: ubuntu-latest-3.11
284+
path: /tmp/u311
286285
- uses: actions/download-artifact@v3
287286
with:
288287
name: macos-latest-3.8
289288
path: /tmp/m38
290289
- uses: actions/download-artifact@v3
291290
with:
292-
name: macos-latest-3.10
293-
path: /tmp/m310
291+
name: macos-latest-3.11
292+
path: /tmp/m311
294293
- uses: actions/download-artifact@v3
295294
with:
296295
name: windows-2019-3.8
297296
path: /tmp/w38
298297
- uses: actions/download-artifact@v3
299298
with:
300-
name: windows-2019-3.10
301-
path: /tmp/w310
299+
name: windows-2019-3.11
300+
path: /tmp/w311
302301
- name: Install Dependencies
303302
run: pip install -U coverage coveralls diff-cover
304303
shell: bash
305304
- name: Combined Deprecation Messages
306305
run: |
307-
sort -f -u /tmp/u37/ml.dep /tmp/u38/ml.dep /tmp/u39/ml.dep /tmp/u310/ml.dep /tmp/m38/ml.dep /tmp/m310/ml.dep /tmp/w38/ml.dep /tmp/w310/ml.dep || true
306+
sort -f -u /tmp/u37/ml.dep /tmp/u38/ml.dep /tmp/u39/ml.dep /tmp/u310/ml.dep /tmp/u311/ml.dep /tmp/m38/ml.dep /tmp/m311/ml.dep /tmp/w38/ml.dep /tmp/w311/ml.dep || true
308307
shell: bash
309308
- name: Coverage combine
310309
run: coverage3 combine /tmp/u37/ml.dat

.pylintrc

Lines changed: 1 addition & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,7 @@ confidence=
5858
# --enable=similarities". If you want to run only the classes checker, but have
5959
# no Warning level messages displayed, use"--disable=all --enable=classes
6060
# --disable=W"
61-
disable=no-self-use, # disabled as it is too verbose
62-
fixme, # disabled as TODOs would show up as warnings
61+
disable=fixme, # disabled as TODOs would show up as warnings
6362
protected-access, # disabled as we don't follow the public vs private
6463
# convention strictly
6564
duplicate-code, # disabled as it is too verbose
@@ -72,9 +71,6 @@ disable=no-self-use, # disabled as it is too verbose
7271
no-else-return, # relax "elif" after a clause with a return
7372
docstring-first-line-empty, # relax docstring style
7473
import-outside-toplevel,
75-
bad-continuation, bad-whitespace, # differences of opinion with black
76-
77-
7874

7975

8076
[REPORTS]
@@ -84,12 +80,6 @@ disable=no-self-use, # disabled as it is too verbose
8480
# mypackage.mymodule.MyReporterClass.
8581
output-format=text
8682

87-
# Put messages in a separate file for each module / package specified on the
88-
# command line instead of printing them on stdout. Reports (if any) will be
89-
# written in a file name "pylint_global.[txt|html]". This option is deprecated
90-
# and it will be removed in Pylint 2.0.
91-
files-output=no
92-
9383
# Tells whether to display a full report or only the messages
9484
reports=yes
9585

@@ -138,63 +128,33 @@ property-classes=abc.abstractproperty
138128
# Regular expression matching correct module names
139129
module-rgx=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$
140130

141-
# Naming hint for module names
142-
module-name-hint=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$
143-
144131
# Regular expression matching correct constant names
145132
const-rgx=(([A-Z_][A-Z0-9_]*)|(__.*__))$
146133

147-
# Naming hint for constant names
148-
const-name-hint=(([A-Z_][A-Z0-9_]*)|(__.*__))$
149-
150134
# Regular expression matching correct class names
151135
class-rgx=[A-Z_][a-zA-Z0-9]+$
152136

153-
# Naming hint for class names
154-
class-name-hint=[A-Z_][a-zA-Z0-9]+$
155-
156137
# Regular expression matching correct function names
157138
function-rgx=[a-z_][a-z0-9_]{2,30}$
158139

159-
# Naming hint for function names
160-
function-name-hint=[a-z_][a-z0-9_]{2,30}$
161-
162140
# Regular expression matching correct method names
163141
method-rgx=(([a-z_][a-z0-9_]{2,49})|(assert[A-Z][a-zA-Z0-9]{2,43})|(test_[_a-zA-Z0-9]{2,}))$
164142

165-
# Naming hint for method names
166-
method-name-hint=[a-z_][a-z0-9_]{2,30}$ or camelCase `assert*` in tests.
167-
168143
# Regular expression matching correct attribute names
169144
attr-rgx=[a-z_][a-z0-9_]{2,30}$
170145

171-
# Naming hint for attribute names
172-
attr-name-hint=[a-z_][a-z0-9_]{2,30}$
173-
174146
# Regular expression matching correct argument names
175147
argument-rgx=[a-z_][a-z0-9_]{2,30}|ax|dt$
176148

177-
# Naming hint for argument names
178-
argument-name-hint=[a-z_][a-z0-9_]{2,30}$
179-
180149
# Regular expression matching correct variable names
181150
variable-rgx=[a-z_][a-z0-9_]{2,30}$
182151

183-
# Naming hint for variable names
184-
variable-name-hint=[a-z_][a-z0-9_]{2,30}$
185-
186152
# Regular expression matching correct class attribute names
187153
class-attribute-rgx=([A-Za-z_][A-Za-z0-9_]{2,30}|(__.*__))$
188154

189-
# Naming hint for class attribute names
190-
class-attribute-name-hint=([A-Za-z_][A-Za-z0-9_]{2,30}|(__.*__))$
191-
192155
# Regular expression matching correct inline iteration names
193156
inlinevar-rgx=[A-Za-z_][A-Za-z0-9_]*$
194157

195-
# Naming hint for inline iteration names
196-
inlinevar-name-hint=[A-Za-z_][A-Za-z0-9_]*$
197-
198158
# Regular expression which should only match function or class names that do
199159
# not require a docstring.
200160
no-docstring-rgx=^_
@@ -222,12 +182,6 @@ ignore-long-lines=^\s*(# )?<?https?://\S+>?$
222182
# else.
223183
single-line-if-stmt=no
224184

225-
# List of optional constructs for which whitespace checking is disabled. `dict-
226-
# separator` is used to allow tabulation in dicts, etc.: {1 : 1,\n222: 2}.
227-
# `trailing-comma` allows a space between comma and closing bracket: (a, ).
228-
# `empty-line` allows space-only lines.
229-
no-space-check=trailing-comma,dict-separator
230-
231185
# Maximum number of lines in a module
232186
max-module-lines=1000
233187

constraints.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
1-
astroid==2.5.6
2-
pylint==2.8.3
31
numpy>=1.20.0
42
ipython<8.13;python_version<'3.9'

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[tool.black]
22
line-length = 100
3-
target-version = ['py37', 'py38', 'py39', 'py310']
3+
target-version = ['py37', 'py38', 'py39', 'py310', 'py311']
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
fixes:
3+
- |
4+
Compatibility fix to support Python 3.11.

requirements-dev.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ coverage>=4.4.0
22
matplotlib>=2.1
33
seaborn
44
black[jupyter]~=22.0
5-
pylint>=2.8.3,<2.14.0
5+
pylint>=2.15.0
66
pylatexenc>=1.4
77
stestr>=2.0.0
88
ddt>=1.2.0,!=1.4.0
@@ -13,7 +13,7 @@ sphinx-gallery
1313
sphinxcontrib-spelling
1414
jupyter-sphinx
1515
discover
16-
qiskit-aer>=0.11
16+
qiskit-aer>=0.11.2
1717
mypy>=0.981
1818
mypy-extensions>=0.4.3
1919
nbsphinx

requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
qiskit-terra>=0.22
1+
qiskit-terra>=0.22.2
22
scipy>=1.4
33
numpy>=1.17
44
psutil>=5
55
scikit-learn>=0.20.0
66
fastdtw
77
setuptools>=40.1.0
8-
dill>=0.3.4,<0.3.6
8+
dill>=0.3.4

setup.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This code is part of Qiskit.
22
#
3-
# (C) Copyright IBM 2021, 2022.
3+
# (C) Copyright IBM 2021, 2023.
44
#
55
# This code is licensed under the Apache License, Version 2.0. You may
66
# obtain a copy of this license in the LICENSE.txt file in the root directory
@@ -61,6 +61,7 @@
6161
"Programming Language :: Python :: 3.8",
6262
"Programming Language :: Python :: 3.9",
6363
"Programming Language :: Python :: 3.10",
64+
"Programming Language :: Python :: 3.11",
6465
"Topic :: Scientific/Engineering"
6566
],
6667
keywords='qiskit sdk quantum machine learning ml',
@@ -69,7 +70,7 @@
6970
include_package_data=True,
7071
python_requires=">=3.7",
7172
extras_require={
72-
'torch': ["torch; python_version < '3.10'"],
73+
'torch': ["torch"],
7374
'sparse': ["sparse"],
7475
},
7576
zip_safe=False

test/connectors/test_torch.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"""Test Torch Base."""
1414

1515
import unittest
16+
import builtins
1617
import warnings
1718
from abc import ABC, abstractmethod
1819
from qiskit.utils import QuantumInstance, algorithm_globals, optionals
@@ -62,44 +63,44 @@ def tear_down(self):
6263
def subTest(self, msg, **kwargs):
6364
# pylint: disable=invalid-name
6465
"""Sub test."""
65-
raise Exception("Abstract method")
66+
raise builtins.Exception("Abstract method")
6667

6768
@abstractmethod
6869
def assertAlmostEqual(self, first, second, places=None, msg=None, delta=None):
6970
"""Assert almost equal."""
70-
raise Exception("Abstract method")
71+
raise builtins.Exception("Abstract method")
7172

7273
@abstractmethod
7374
def assertEqual(self, first, second, msg=None):
7475
"""Assert equal."""
75-
raise Exception("Abstract method")
76+
raise builtins.Exception("Abstract method")
7677

7778
@abstractmethod
7879
def assertTrue(self, expr, msg=None):
7980
"""Assert true."""
80-
raise Exception("Abstract method")
81+
raise builtins.Exception("Abstract method")
8182

8283
@abstractmethod
8384
def assertFalse(self, expr, msg=None):
8485
"""assert False"""
85-
raise Exception("Abstract method")
86+
raise builtins.Exception("Abstract method")
8687

8788
@abstractmethod
8889
def skipTest(self, reason): # pylint: disable=invalid-name
8990
"""Skip test."""
90-
raise Exception("Abstract method")
91+
raise builtins.Exception("Abstract method")
9192

9293
@abstractmethod
9394
def assertLogs(self, logger=None, level=None):
9495
"""Assert logs."""
95-
raise Exception("Abstract method")
96+
raise builtins.Exception("Abstract method")
9697

9798
@abstractmethod
9899
def assertListEqual(self, list1, list2, msg=None):
99100
"""Assert list equal."""
100-
raise Exception("Abstract method")
101+
raise builtins.Exception("Abstract method")
101102

102103
@abstractmethod
103104
def assertRaises(self, expected_exception):
104105
"""Assert raises an exception."""
105-
raise Exception("Abstract method")
106+
raise builtins.Exception("Abstract method")

0 commit comments

Comments
 (0)