Add support for Python 3.11 (#9028)

* Add support for Python 3.11

Python 3.11.0 was released on 10-24-2022, this commit marks the start of
support for Python 3.11 in qiskit. It adds the supported Python version in
the package metadata and updates the CI configuration to run test jobs
on Python 3.11 and build Python 3.11 wheels on release.

* Fix inspect.Parameter usage for API change in 3.11

Per the Python 3.11.0 release notes inspect.Parameter now raises a
ValueError if the name argument is a Python identifier. This was causing a
test failure in one case where a parameter named `lambda` was used.
This commit adjusts the parameter name in the tests to be lam to avoid
this issue.

* Set a version cap on the jax dev requirement

Currently jax doesn't publish Python 3.11 wheels which is blocking test
runs with python 3.11. Since jax is an optional package only used for
the gradient package we can just skip it as isn't a full blocker for
using python 3.11. This commit sets an environment marker on the jax
dev requirements to only try to install it on Python < 3.11.

* Set python version cap on cplex in CI

* DNM: Test wheel builds work

* Skip tests on i686/win32 wheel buids with python 3.11

* Revert "DNM: Test wheel builds work"

This reverts commit 725c21b465.

* Run QPY backwards compat tests on trailing edge Python version

This commit moves the qpy backwards compatibility testing from the
leading edge python version, which in this PR branch is Python 3.11, to
the trailing edge Python version which is currently 3.7. Trying to add
support for a new Python version has demonstrated that we can't use the
leading edge version as historical versions of Qiskit used to generate
old QPY payloads are not going to be generally installable with newer
Python versions. So by using the trailing edge version instead we can
install all the older versions of Qiskit as there is Python
compatibility for those Qiskit versions. Eventually we will need to
raise the minimum Qiskit version we use in the QPY tests, when Python
3.9 goes EoL in October 2025 and Qiskit Terra 0.18.0 no longer has any
supported versions of Python it was released for. We probably could
get by another year until Python 3.10 goes EoL in 2026 it just means
we're building 0.18.x and 0.19.x from source for the testing, but when
Python 3.11 becomes our oldest supported version we'll likely have to
bump the minimum version.

This does go a bit counter to the intent of the test matrix to make the
first stage return fast and do a more through check in the second stage.
But, in this case the extra runtime is worth the longer term stability
in the tests.

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
This commit is contained in:
Matthew Treinish 2022-11-03 12:58:14 -04:00 committed by GitHub
parent 94bccd55a5
commit 75d66dd8ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 18 additions and 17 deletions

View File

@ -80,7 +80,7 @@ jobs:
- bash: | - bash: |
set -e set -e
source test-job/bin/activate source test-job/bin/activate
pip install -U "cplex" "qiskit-aer" "z3-solver" -c constraints.txt pip install -U "cplex;python_version < '3.11'" "qiskit-aer" "z3-solver" -c constraints.txt
mkdir -p /tmp/terra-tests mkdir -p /tmp/terra-tests
cp -r test /tmp/terra-tests/. cp -r test /tmp/terra-tests/.
cp .stestr.conf /tmp/terra-tests/. cp .stestr.conf /tmp/terra-tests/.

View File

@ -4,7 +4,7 @@ parameters:
- name: pool - name: pool
type: object type: object
- name: env - name: env
type: object type: object
default: {} default: {}
@ -25,7 +25,7 @@ jobs:
- bash: | - bash: |
set -e set -e
python -m pip install --upgrade pip python -m pip install --upgrade pip
pip install cibuildwheel==2.3.1 pip install cibuildwheel==2.11.2
pip install -U twine pip install -U twine
cibuildwheel --output-dir wheelhouse . cibuildwheel --output-dir wheelhouse .

View File

@ -26,7 +26,7 @@ jobs:
with: with:
platforms: all platforms: all
- name: Build wheels - name: Build wheels
uses: pypa/cibuildwheel@v2.3.1 uses: pypa/cibuildwheel@v2.11.2
env: env:
CIBW_ARCHS_LINUX: s390x CIBW_ARCHS_LINUX: s390x
CIBW_TEST_SKIP: "cp*" CIBW_TEST_SKIP: "cp*"
@ -61,7 +61,7 @@ jobs:
with: with:
platforms: all platforms: all
- name: Build wheels - name: Build wheels
uses: pypa/cibuildwheel@v2.3.1 uses: pypa/cibuildwheel@v2.11.2
env: env:
CIBW_ARCHS_LINUX: ppc64le CIBW_ARCHS_LINUX: ppc64le
CIBW_TEST_SKIP: "cp*" CIBW_TEST_SKIP: "cp*"
@ -96,7 +96,7 @@ jobs:
with: with:
platforms: all platforms: all
- name: Build wheels - name: Build wheels
uses: pypa/cibuildwheel@v2.3.1 uses: pypa/cibuildwheel@v2.11.2
env: env:
CIBW_ARCHS_LINUX: aarch64 CIBW_ARCHS_LINUX: aarch64
- uses: actions/upload-artifact@v2 - uses: actions/upload-artifact@v2

View File

@ -33,7 +33,7 @@ parameters:
- name: "supportedPythonVersions" - name: "supportedPythonVersions"
displayName: "All supported versions of Python" displayName: "All supported versions of Python"
type: object type: object
default: ["3.7", "3.8", "3.9", "3.10"] default: ["3.7", "3.8", "3.9", "3.10", "3.11"]
- name: "minimumPythonVersion" - name: "minimumPythonVersion"
displayName: "Minimum supported version of Python" displayName: "Minimum supported version of Python"
@ -43,7 +43,7 @@ parameters:
- name: "maximumPythonVersion" - name: "maximumPythonVersion"
displayName: "Maximum supported version of Python" displayName: "Maximum supported version of Python"
type: string type: string
default: "3.10" default: "3.11"
- name: "minimumRustVersion" - name: "minimumRustVersion"
displayName: "Minimum supported version of Rust" displayName: "Minimum supported version of Rust"
@ -151,7 +151,7 @@ stages:
- template: ".azure/test-linux.yml" - template: ".azure/test-linux.yml"
parameters: parameters:
pythonVersion: ${{ parameters.minimumPythonVersion }} pythonVersion: ${{ parameters.minimumPythonVersion }}
testQPY: false testQPY: true
testImages: false testImages: false
rustVersion: ${{ parameters.minimumRustVersion }} rustVersion: ${{ parameters.minimumRustVersion }}
@ -171,7 +171,7 @@ stages:
- template: ".azure/test-linux.yml" - template: ".azure/test-linux.yml"
parameters: parameters:
pythonVersion: ${{ parameters.maximumPythonVersion }} pythonVersion: ${{ parameters.maximumPythonVersion }}
testQPY: true testQPY: false
testImages: true testImages: true
installFromSdist: true installFromSdist: true

View File

@ -10,7 +10,7 @@ target-version = ['py37', 'py38', 'py39', 'py310']
manylinux-x86_64-image = "manylinux2014" manylinux-x86_64-image = "manylinux2014"
manylinux-i686-image = "manylinux2014" manylinux-i686-image = "manylinux2014"
skip = "pp* cp36-* *musllinux*" skip = "pp* cp36-* *musllinux*"
test-skip = "cp310-win32 cp310-manylinux_i686" test-skip = "cp310-win32 cp310-manylinux_i686 cp311-win32 cp311-manylinux_i686"
test-command = "python {project}/examples/python/stochastic_swap.py" test-command = "python {project}/examples/python/stochastic_swap.py"
# We need to use pre-built versions of Numpy and Scipy in the tests; they have a # We need to use pre-built versions of Numpy and Scipy in the tests; they have a
# tendency to crash if they're installed from source by `pip install`, and since # tendency to crash if they're installed from source by `pip install`, and since

View File

@ -281,7 +281,7 @@ class InstructionScheduleMap:
parameters = [] parameters = []
for argname in ordered_names: for argname in ordered_names:
param_signature = inspect.Parameter( param_signature = inspect.Parameter(
name=argname, argname,
kind=inspect.Parameter.POSITIONAL_OR_KEYWORD, kind=inspect.Parameter.POSITIONAL_OR_KEYWORD,
) )
parameters.append(param_signature) parameters.append(param_signature)

View File

@ -24,6 +24,6 @@ sphinx-design>=0.2.0
pygments>=2.4 pygments>=2.4
scikit-learn>=0.20.0 scikit-learn>=0.20.0
scikit-quant<=0.7;platform_system != 'Windows' scikit-quant<=0.7;platform_system != 'Windows'
jax;platform_system != 'Windows' jax;platform_system != 'Windows' and python_version < '3.11'
jaxlib;platform_system != 'Windows' jaxlib;platform_system != 'Windows' and python_version < '3.11'
docplex docplex

View File

@ -72,6 +72,7 @@ setup(
"Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Topic :: Scientific/Engineering", "Topic :: Scientific/Engineering",
], ],
keywords="qiskit sdk quantum", keywords="qiskit sdk quantum",

View File

@ -393,7 +393,7 @@ class TestInstructionScheduleMap(QiskitTestCase):
"""Test adding and getting schedule with non obvious parameter ordering.""" """Test adding and getting schedule with non obvious parameter ordering."""
theta = Parameter("theta") theta = Parameter("theta")
phi = Parameter("phi") phi = Parameter("phi")
lamb = Parameter("lambda") lamb = Parameter("lam")
target_sched = Schedule() target_sched = Schedule()
target_sched.insert(0, ShiftPhase(theta, DriveChannel(0)), inplace=True) target_sched.insert(0, ShiftPhase(theta, DriveChannel(0)), inplace=True)
@ -401,7 +401,7 @@ class TestInstructionScheduleMap(QiskitTestCase):
target_sched.insert(20, ShiftPhase(lamb, DriveChannel(0)), inplace=True) target_sched.insert(20, ShiftPhase(lamb, DriveChannel(0)), inplace=True)
inst_map = InstructionScheduleMap() inst_map = InstructionScheduleMap()
inst_map.add("target_sched", (0,), target_sched, arguments=["theta", "phi", "lambda"]) inst_map.add("target_sched", (0,), target_sched, arguments=["theta", "phi", "lam"])
ref_sched = Schedule() ref_sched = Schedule()
ref_sched.insert(0, ShiftPhase(0, DriveChannel(0)), inplace=True) ref_sched.insert(0, ShiftPhase(0, DriveChannel(0)), inplace=True)

View File

@ -1,6 +1,6 @@
[tox] [tox]
minversion = 3.3.0 minversion = 3.3.0
envlist = py37, py38, py39, py310, lint-incr envlist = py37, py38, py39, py310, py311, lint-incr
isolated_build = true isolated_build = true
[testenv] [testenv]