Skip to content

Commit

Permalink
Add support for Python 3.11 (#9028)
Browse files Browse the repository at this point in the history
* 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 725c21b.

* 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>
  • Loading branch information
mtreinish and mergify[bot] authored Nov 3, 2022
1 parent 94bccd5 commit 75d66dd
Show file tree
Hide file tree
Showing 10 changed files with 18 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .azure/test-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ jobs:
- bash: |
set -e
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
cp -r test /tmp/terra-tests/.
cp .stestr.conf /tmp/terra-tests/.
Expand Down
4 changes: 2 additions & 2 deletions .azure/wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ parameters:

- name: pool
type: object

- name: env
type: object
default: {}
Expand All @@ -25,7 +25,7 @@ jobs:
- bash: |
set -e
python -m pip install --upgrade pip
pip install cibuildwheel==2.3.1
pip install cibuildwheel==2.11.2
pip install -U twine
cibuildwheel --output-dir wheelhouse .
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
with:
platforms: all
- name: Build wheels
uses: pypa/cibuildwheel@v2.3.1
uses: pypa/cibuildwheel@v2.11.2
env:
CIBW_ARCHS_LINUX: s390x
CIBW_TEST_SKIP: "cp*"
Expand Down Expand Up @@ -61,7 +61,7 @@ jobs:
with:
platforms: all
- name: Build wheels
uses: pypa/cibuildwheel@v2.3.1
uses: pypa/cibuildwheel@v2.11.2
env:
CIBW_ARCHS_LINUX: ppc64le
CIBW_TEST_SKIP: "cp*"
Expand Down Expand Up @@ -96,7 +96,7 @@ jobs:
with:
platforms: all
- name: Build wheels
uses: pypa/cibuildwheel@v2.3.1
uses: pypa/cibuildwheel@v2.11.2
env:
CIBW_ARCHS_LINUX: aarch64
- uses: actions/upload-artifact@v2
Expand Down
8 changes: 4 additions & 4 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ parameters:
- name: "supportedPythonVersions"
displayName: "All supported versions of Python"
type: object
default: ["3.7", "3.8", "3.9", "3.10"]
default: ["3.7", "3.8", "3.9", "3.10", "3.11"]

- name: "minimumPythonVersion"
displayName: "Minimum supported version of Python"
Expand All @@ -43,7 +43,7 @@ parameters:
- name: "maximumPythonVersion"
displayName: "Maximum supported version of Python"
type: string
default: "3.10"
default: "3.11"

- name: "minimumRustVersion"
displayName: "Minimum supported version of Rust"
Expand Down Expand Up @@ -151,7 +151,7 @@ stages:
- template: ".azure/test-linux.yml"
parameters:
pythonVersion: ${{ parameters.minimumPythonVersion }}
testQPY: false
testQPY: true
testImages: false
rustVersion: ${{ parameters.minimumRustVersion }}

Expand All @@ -171,7 +171,7 @@ stages:
- template: ".azure/test-linux.yml"
parameters:
pythonVersion: ${{ parameters.maximumPythonVersion }}
testQPY: true
testQPY: false
testImages: true
installFromSdist: true

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ target-version = ['py37', 'py38', 'py39', 'py310']
manylinux-x86_64-image = "manylinux2014"
manylinux-i686-image = "manylinux2014"
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"
# 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
Expand Down
2 changes: 1 addition & 1 deletion qiskit/pulse/instruction_schedule_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ def add(
parameters = []
for argname in ordered_names:
param_signature = inspect.Parameter(
name=argname,
argname,
kind=inspect.Parameter.POSITIONAL_OR_KEYWORD,
)
parameters.append(param_signature)
Expand Down
4 changes: 2 additions & 2 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ sphinx-design>=0.2.0
pygments>=2.4
scikit-learn>=0.20.0
scikit-quant<=0.7;platform_system != 'Windows'
jax;platform_system != 'Windows'
jaxlib;platform_system != 'Windows'
jax;platform_system != 'Windows' and python_version < '3.11'
jaxlib;platform_system != 'Windows' and python_version < '3.11'
docplex
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Topic :: Scientific/Engineering",
],
keywords="qiskit sdk quantum",
Expand Down
4 changes: 2 additions & 2 deletions test/python/pulse/test_instruction_schedule_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,15 +393,15 @@ def test_schedule_with_non_alphanumeric_ordering(self):
"""Test adding and getting schedule with non obvious parameter ordering."""
theta = Parameter("theta")
phi = Parameter("phi")
lamb = Parameter("lambda")
lamb = Parameter("lam")

target_sched = Schedule()
target_sched.insert(0, ShiftPhase(theta, DriveChannel(0)), inplace=True)
target_sched.insert(10, ShiftPhase(phi, DriveChannel(0)), inplace=True)
target_sched.insert(20, ShiftPhase(lamb, DriveChannel(0)), inplace=True)

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.insert(0, ShiftPhase(0, DriveChannel(0)), inplace=True)
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tox]
minversion = 3.3.0
envlist = py37, py38, py39, py310, lint-incr
envlist = py37, py38, py39, py310, py311, lint-incr
isolated_build = true

[testenv]
Expand Down

0 comments on commit 75d66dd

Please sign in to comment.