Skip to content

Commit

Permalink
Add support for Python 3.12 (#11262)
Browse files Browse the repository at this point in the history
* Add support for Python 3.12

Python 3.12.0 was released on 10-02-2023, this commit marks the start of
support for Python 3.12 in Qiskit. It adds the supported Pythonv ersion
in the package metadata and updates the CI configuration to run test
jobs on Python 3.12 and build Python 3.12 wheels on release.

Fixes: #10887

* Add release note

* Avoid deprecated `datetime.datetime.utcnow()` usage

In Python 3.12 `datetime.datetime.utcnow()` has been deprecated, being
replaced by: `datetime.datetime.now(datetime.UTC)`. This commit updates
the usage of `utcnow()` to follow the new convention.

* Adjust UTC usage to support Python 3.8

The recommended alternative for using utcnow() in the deprecation
warnings emitted by Python 3.12 are not compatible with Python 3.8. The
datetime.UTC alias was not added to Python until Python 3.11. To ensure
that the code is compatible with Python < 3.11 this commit updates all
the usage of datetime.UTC to use datetime.timezone.utc instead, which is
what datetime.UTC aliases to in Python >=3.11.

(cherry picked from commit 5a5c9e3)
  • Loading branch information
mtreinish authored and jakelishman committed Nov 23, 2023
1 parent 5fef2b5 commit a0b3f2c
Show file tree
Hide file tree
Showing 12 changed files with 31 additions and 28 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
python-version: '3.10'
- uses: dtolnay/rust-toolchain@stable
- name: Build wheels
uses: pypa/cibuildwheel@v2.13.0
uses: pypa/cibuildwheel@v2.16.2
- uses: actions/upload-artifact@v3
with:
path: ./wheelhouse/*.whl
Expand All @@ -42,7 +42,7 @@ jobs:
python-version: '3.10'
- uses: dtolnay/rust-toolchain@stable
- name: Build wheels
uses: pypa/cibuildwheel@v2.13.0
uses: pypa/cibuildwheel@v2.16.2
env:
CIBW_BEFORE_ALL: rustup target add aarch64-apple-darwin
CIBW_ARCHS_MACOS: arm64 universal2
Expand Down Expand Up @@ -91,7 +91,7 @@ jobs:
with:
platforms: all
- name: Build wheels
uses: pypa/cibuildwheel@v2.13.0
uses: pypa/cibuildwheel@v2.16.2
env:
CIBW_ARCHS_LINUX: s390x
CIBW_TEST_SKIP: "cp*"
Expand Down Expand Up @@ -124,7 +124,7 @@ jobs:
with:
platforms: all
- name: Build wheels
uses: pypa/cibuildwheel@v2.13.0
uses: pypa/cibuildwheel@v2.16.2
env:
CIBW_ARCHS_LINUX: ppc64le
CIBW_TEST_SKIP: "cp*"
Expand Down Expand Up @@ -157,7 +157,7 @@ jobs:
with:
platforms: all
- name: Build wheels
uses: pypa/cibuildwheel@v2.13.0
uses: pypa/cibuildwheel@v2.16.2
env:
CIBW_ARCHS_LINUX: aarch64
- uses: actions/upload-artifact@v3
Expand Down
4 changes: 2 additions & 2 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ parameters:
- name: "supportedPythonVersions"
displayName: "All supported versions of Python"
type: object
default: ["3.8", "3.9", "3.10", "3.11"]
default: ["3.8", "3.9", "3.10", "3.11", "3.12"]

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

# These two versions of Python can be chosen somewhat arbitrarily, but we get
# slightly better coverage per PR if they're neither the maximum nor minimum
Expand Down
4 changes: 2 additions & 2 deletions constraints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ jsonschema==3.2.0
# Numpy 1.25 deprecated some behaviours that we used, and caused the isometry
# tests to flake. See https://github.com/Qiskit/qiskit-terra/issues/10305,
# remove pin when resolving that.
numpy<1.25
numpy<1.25; python_version<'3.12'

# Scipy 1.11 seems to have caused an instability in the Weyl coordinates
# eigensystem code for one of the test cases. See
# https://github.com/Qiskit/qiskit-terra/issues/10345 for current details.
scipy<1.11
scipy<1.11; python_version<'3.12'

# Aer 0.13 causes several randomised tests to begin failing, and some
# `QuantumInstance` use of noise models to raise exceptions. These need fixes
Expand Down
6 changes: 3 additions & 3 deletions qiskit/providers/fake_provider/fake_backend_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def __init__(self):
None,
name="FakeV2",
description="A fake BackendV2 example",
online_date=datetime.datetime.utcnow(),
online_date=datetime.datetime.now(datetime.timezone.utc),
backend_version="0.0.1",
)
self._qubit_properties = [
Expand Down Expand Up @@ -116,7 +116,7 @@ def __init__(self, bidirectional=True):
None,
name="Fake5QV2",
description="A fake BackendV2 example",
online_date=datetime.datetime.utcnow(),
online_date=datetime.datetime.now(datetime.timezone.utc),
backend_version="0.0.1",
)
qubit_properties = [
Expand Down Expand Up @@ -188,7 +188,7 @@ def __init__(self):
None,
name="FakeSimpleV2",
description="A fake simple BackendV2 example",
online_date=datetime.datetime.utcnow(),
online_date=datetime.datetime.now(datetime.timezone.utc),
backend_version="0.0.1",
)
self._lam = Parameter("lambda")
Expand Down
2 changes: 1 addition & 1 deletion qiskit/providers/fake_provider/fake_mumbai_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def __init__(self):
super().__init__(
name="FakeMumbaiFractionalCX",
description="A fake BackendV2 example based on IBM Mumbai",
online_date=datetime.datetime.utcnow(),
online_date=datetime.datetime.now(datetime.timezone.utc),
backend_version="0.0.1",
)
dt = 0.2222222222222222e-9
Expand Down
8 changes: 4 additions & 4 deletions qiskit/transpiler/target.py
Original file line number Diff line number Diff line change
Expand Up @@ -1477,7 +1477,7 @@ def target_to_backend_properties(target: Target):
if getattr(props, "duration", None) is not None:
property_list.append(
{
"date": datetime.datetime.utcnow(),
"date": datetime.datetime.now(datetime.timezone.utc),
"name": "gate_length",
"unit": "s",
"value": props.duration,
Expand All @@ -1486,7 +1486,7 @@ def target_to_backend_properties(target: Target):
if getattr(props, "error", None) is not None:
property_list.append(
{
"date": datetime.datetime.utcnow(),
"date": datetime.datetime.now(datetime.timezone.utc),
"name": "gate_error",
"unit": "",
"value": props.error,
Expand All @@ -1511,7 +1511,7 @@ def target_to_backend_properties(target: Target):
if getattr(props, "error", None) is not None:
props_list.append(
{
"date": datetime.datetime.utcnow(),
"date": datetime.datetime.now(datetime.timezone.utc),
"name": "readout_error",
"unit": "",
"value": props.error,
Expand All @@ -1520,7 +1520,7 @@ def target_to_backend_properties(target: Target):
if getattr(props, "duration", None) is not None:
props_list.append(
{
"date": datetime.datetime.utcnow(),
"date": datetime.datetime.now(datetime.timezone.utc),
"name": "readout_length",
"unit": "s",
"value": props.duration,
Expand Down
1 change: 1 addition & 0 deletions qiskit_pkg/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Topic :: Scientific/Engineering",
],
keywords="qiskit sdk quantum",
Expand Down
4 changes: 4 additions & 0 deletions releasenotes/notes/add-py312-support-7077426af34ac5da.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
features:
- |
Added support for using Qiskit with Python 3.12.
5 changes: 1 addition & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,4 @@ dill>=0.3
python-dateutil>=2.8.0
stevedore>=3.0.0
typing-extensions; python_version<'3.11'
# symengine pinning needed due lowered precision handling complex
# multiplication in version 0.10 wich breaks parameter assignment test
# (can be removed once issue is fix)
symengine>=0.9, <0.10; platform_machine == 'x86_64' or platform_machine == 'aarch64' or platform_machine == 'ppc64le' or platform_machine == 'amd64' or platform_machine == 'arm64'
symengine>=0.9,!=0.10.0; platform_machine == 'x86_64' or platform_machine == 'aarch64' or platform_machine == 'ppc64le' or platform_machine == 'amd64' or platform_machine == 'arm64'
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Topic :: Scientific/Engineering",
],
keywords="qiskit sdk quantum",
Expand Down
12 changes: 6 additions & 6 deletions test/python/providers/test_fake_backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ def test_filter_faulty_qubits_backend_v2_converter(self):
props_dict = backend.properties().to_dict()
for i in range(62, 67):
non_operational = {
"date": datetime.datetime.utcnow(),
"date": datetime.datetime.now(datetime.timezone.utc),
"name": "operational",
"unit": "",
"value": 0,
Expand All @@ -518,7 +518,7 @@ def test_filter_faulty_qubits_backend_v2_converter_with_delay(self):
props_dict = backend.properties().to_dict()
for i in range(62, 67):
non_operational = {
"date": datetime.datetime.utcnow(),
"date": datetime.datetime.now(datetime.timezone.utc),
"name": "operational",
"unit": "",
"value": 0,
Expand All @@ -539,7 +539,7 @@ def test_filter_faulty_qubits_and_gates_backend_v2_converter(self):
props_dict = backend.properties().to_dict()
for i in range(62, 67):
non_operational = {
"date": datetime.datetime.utcnow(),
"date": datetime.datetime.now(datetime.timezone.utc),
"name": "operational",
"unit": "",
"value": 0,
Expand All @@ -556,7 +556,7 @@ def test_filter_faulty_qubits_and_gates_backend_v2_converter(self):
(34, 24),
}
non_operational_gate = {
"date": datetime.datetime.utcnow(),
"date": datetime.datetime.now(datetime.timezone.utc),
"name": "operational",
"unit": "",
"value": 0,
Expand Down Expand Up @@ -591,7 +591,7 @@ def test_filter_faulty_gates_v2_converter(self):
(34, 24),
}
non_operational_gate = {
"date": datetime.datetime.utcnow(),
"date": datetime.datetime.now(datetime.timezone.utc),
"name": "operational",
"unit": "",
"value": 0,
Expand All @@ -618,7 +618,7 @@ def test_filter_faulty_no_faults_v2_converter(self):
def test_faulty_full_path_transpile_connected_cmap(self, opt_level):
backend = FakeYorktown()
non_operational_gate = {
"date": datetime.datetime.utcnow(),
"date": datetime.datetime.now(datetime.timezone.utc),
"name": "operational",
"unit": "",
"value": 0,
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 = py38, py39, py310, py311, lint-incr
envlist = py38, py39, py310, py311, py312, lint-incr
isolated_build = true

[testenv]
Expand Down

0 comments on commit a0b3f2c

Please sign in to comment.