Skip to content

Commit c8ae82d

Browse files
authored
Drop python 3.8 support, add python 3.12 tests, and pin qiskit<2 (#639)
* Bump minimum supported python version to 3.9 * avoid too-many-positional-arguments * addresses numpy 2 behavior * update tox.ini and pyproject.toml * black * reno * add Python 3.13 support * remove 3.13 support since qiskit-algorithms dependecy does not support the latest scipy 0.15 * simplify dependency versions * update constraints.txt * pin qiskit<2 * update cplex constraint * simplify gurobi constraint
1 parent 999ad95 commit c8ae82d

File tree

13 files changed

+67
-57
lines changed

13 files changed

+67
-57
lines changed

.github/actions/run-tests/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ runs:
4040
if [ "${{ inputs.event-name }}" == "schedule" ] || [ "${{ inputs.run-slow }}" == "true" ]; then
4141
export QISKIT_TESTS="run_slow"
4242
fi
43-
if [ "${{ inputs.os }}" == "ubuntu-latest" ] && [ "${{ inputs.python-version }}" == "3.8" ]; then
43+
if [ "${{ inputs.os }}" == "ubuntu-latest" ] && [ "${{ inputs.python-version }}" == "3.9" ]; then
4444
export PYTHON="coverage3 run --source qiskit_optimization --parallel-mode"
4545
fi
4646
stestr --test-path test run 2> >(tee /dev/stderr out.txt > /dev/null)

.github/workflows/deploy-code.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
id-token: write
2626
strategy:
2727
matrix:
28-
python-version: [3.8]
28+
python-version: [3.9]
2929
steps:
3030
- uses: actions/checkout@v4
3131
- uses: actions/setup-python@v5

.github/workflows/deploy-docs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
strategy:
2727
matrix:
2828
os: [ubuntu-latest]
29-
python-version: [3.8]
29+
python-version: [3.9]
3030
steps:
3131
- uses: actions/checkout@v4
3232
with:

.github/workflows/main.yml

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
strategy:
3737
matrix:
3838
os: [ubuntu-latest]
39-
python-version: [3.8]
39+
python-version: [3.9]
4040
steps:
4141
- name: Print Concurrency Group
4242
env:
@@ -119,16 +119,16 @@ jobs:
119119
fail-fast: false
120120
matrix:
121121
os: [ubuntu-latest]
122-
python-version: [3.8, 3.9, '3.10', 3.11, 3.12]
122+
python-version: [3.9, '3.10', 3.11, 3.12]
123123
include:
124124
- os: macos-latest
125-
python-version: 3.8
125+
python-version: 3.9
126126
- os: macos-latest
127127
python-version: 3.11
128128
- os: windows-latest
129-
python-version: 3.8
129+
python-version: 3.9
130130
- os: windows-latest
131-
python-version: 3.11
131+
python-version: 3.12
132132
steps:
133133
- uses: actions/checkout@v4
134134
- uses: actions/setup-python@v5
@@ -197,7 +197,7 @@ jobs:
197197
fi
198198
coverage3 combine
199199
mv .coverage ./ci-artifact-data/opt.dat
200-
if: ${{ matrix.os == 'ubuntu-latest' && matrix.python-version == 3.8 }}
200+
if: ${{ matrix.os == 'ubuntu-latest' && matrix.python-version == 3.9 }}
201201
shell: bash
202202
- uses: actions/upload-artifact@v4
203203
with:
@@ -225,7 +225,7 @@ jobs:
225225
fail-fast: false
226226
matrix:
227227
os: [ubuntu-latest]
228-
python-version: [3.8, 3.11]
228+
python-version: [3.9, 3.12]
229229
steps:
230230
- uses: actions/checkout@v4
231231
with:
@@ -290,30 +290,26 @@ jobs:
290290
cd docs/_build/html
291291
mkdir artifacts
292292
tar -zcvf artifacts/tutorials.tar.gz --exclude=./artifacts .
293-
if: ${{ matrix.python-version == 3.8 && !startsWith(github.ref, 'refs/heads/stable') && !startsWith(github.base_ref, 'stable/') }}
293+
if: ${{ matrix.python-version == 3.9 && !startsWith(github.ref, 'refs/heads/stable') && !startsWith(github.base_ref, 'stable/') }}
294294
shell: bash
295295
- name: Run upload stable tutorials
296296
uses: actions/upload-artifact@v4
297297
with:
298298
name: tutorials-stable${{ matrix.python-version }}
299299
path: docs/_build/html/artifacts/tutorials.tar.gz
300-
if: ${{ matrix.python-version == 3.8 && !startsWith(github.ref, 'refs/heads/stable') && !startsWith(github.base_ref, 'stable/') }}
300+
if: ${{ matrix.python-version == 3.9 && !startsWith(github.ref, 'refs/heads/stable') && !startsWith(github.base_ref, 'stable/') }}
301301
Deprecation_Messages_and_Coverage:
302302
if: github.repository_owner == 'qiskit-community'
303303
needs: [Checks, Optimization, Tutorials]
304304
runs-on: ubuntu-latest
305305
strategy:
306306
matrix:
307-
python-version: [3.8]
307+
python-version: [3.9]
308308
steps:
309309
- uses: actions/checkout@v4
310310
- uses: actions/setup-python@v5
311311
with:
312312
python-version: ${{ matrix.python-version }}
313-
- uses: actions/download-artifact@v4
314-
with:
315-
name: ubuntu-latest-3.8
316-
path: /tmp/o38
317313
- uses: actions/download-artifact@v4
318314
with:
319315
name: ubuntu-latest-3.9
@@ -332,29 +328,29 @@ jobs:
332328
path: /tmp/o312
333329
- uses: actions/download-artifact@v4
334330
with:
335-
name: macos-latest-3.8
336-
path: /tmp/m38
331+
name: macos-latest-3.9
332+
path: /tmp/m39
337333
- uses: actions/download-artifact@v4
338334
with:
339335
name: macos-latest-3.11
340-
path: /tmp/m311
336+
path: /tmp/m312
341337
- uses: actions/download-artifact@v4
342338
with:
343-
name: windows-latest-3.8
344-
path: /tmp/w38
339+
name: windows-latest-3.9
340+
path: /tmp/w39
345341
- uses: actions/download-artifact@v4
346342
with:
347-
name: windows-latest-3.11
348-
path: /tmp/w311
343+
name: windows-latest-3.12
344+
path: /tmp/w312
349345
- name: Install Dependencies
350346
run: pip install -U coverage coveralls diff-cover
351347
shell: bash
352348
- name: Combined Deprecation Messages
353349
run: |
354-
sort -f -u /tmp/o38/opt.dep /tmp/o39/opt.dep /tmp/o310/opt.dep /tmp/o311/opt.dep /tmp/o312/opt.dep /tmp/m38/opt.dep /tmp/m311/opt.dep /tmp/w38/opt.dep /tmp/w311/opt.dep || true
350+
sort -f -u /tmp/o39/opt.dep /tmp/o310/opt.dep /tmp/o311/opt.dep /tmp/o312/opt.dep /tmp/m39/opt.dep /tmp/m311/opt.dep /tmp/w39/opt.dep /tmp/w312/opt.dep || true
355351
shell: bash
356352
- name: Coverage combine
357-
run: coverage3 combine /tmp/o38/opt.dat
353+
run: coverage3 combine /tmp/o39/opt.dat
358354
shell: bash
359355
- name: Upload to Coveralls
360356
env:

constraints.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
numpy>=1.20.0
2-
ipython<8.13;python_version<'3.9'

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ build-backend = "setuptools.build_meta"
44

55
[tool.black]
66
line-length = 100
7-
target-version = ['py38', 'py39', 'py310', 'py311']
7+
target-version = ['py39', 'py310', 'py311', 'py312']

qiskit_optimization/algorithms/optimization_algorithm.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,9 @@ def __init__( # pylint: disable=too-many-positional-arguments
131131
f"variables: size {len(variables)} {[v.name for v in variables]}"
132132
)
133133
self._x = np.asarray(x)
134-
self._variables_dict = dict(zip(self._variable_names, self._x))
134+
self._variables_dict = {
135+
name: val.item() for name, val in zip(self._variable_names, self._x)
136+
}
135137

136138
self._fval = fval
137139
self._raw_results = raw_results
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
upgrade:
3+
- |
4+
Support for running with Python 3.8 has been removed.
5+
To run Qiskit Optimization you need a minimum Python version of 3.9.
6+

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
qiskit>=0.44
1+
qiskit>=0.44,<2
22
qiskit-algorithms>=0.2.0
33
scipy>=1.9.0,<1.14
44
numpy>=1.17,<2.2.0

setup.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This code is part of a Qiskit project.
22
#
3-
# (C) Copyright IBM 2021, 2024.
3+
# (C) Copyright IBM 2021, 2025.
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,7 +61,6 @@
6161
"Operating System :: MacOS",
6262
"Operating System :: POSIX :: Linux",
6363
"Programming Language :: Python :: 3 :: Only",
64-
"Programming Language :: Python :: 3.8",
6564
"Programming Language :: Python :: 3.9",
6665
"Programming Language :: Python :: 3.10",
6766
"Programming Language :: Python :: 3.11",
@@ -72,14 +71,14 @@
7271
packages=setuptools.find_packages(include=["qiskit_optimization", "qiskit_optimization.*"]),
7372
install_requires=REQUIREMENTS,
7473
include_package_data=True,
75-
python_requires=">=3.8",
74+
python_requires=">=3.9",
7675
extras_require={
77-
"cplex": ["cplex; python_version < '3.12' and platform_machine != 'arm64'"],
76+
"cplex": [
77+
"cplex; (python_version < '3.13' and platform_system != 'Darwin') or (python_version < '3.12' and platform_system == 'Darwin')"
78+
],
7879
"cvx": ["cvxpy"],
7980
"matplotlib": ["matplotlib"],
80-
"gurobi": [
81-
"gurobipy; platform_machine != 'arm64' or python_version >= '3.9' and platform_machine == 'arm64'"
82-
],
81+
"gurobi": ["gurobipy"],
8382
},
8483
project_urls={
8584
"Bug Tracker": "https://github.com/qiskit-community/qiskit-optimization/issues",

test/problems/test_quadratic_program.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This code is part of a Qiskit project.
22
#
3-
# (C) Copyright IBM 2020, 2023.
3+
# (C) Copyright IBM 2020, 2024.
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
@@ -857,18 +857,20 @@ def test_write_to_lp_file(self):
857857
with tempfile.TemporaryDirectory() as tmp:
858858
temp_output_path = path.join(tmp, "temp.lp")
859859
q_p.write_to_lp_file(temp_output_path)
860-
with open(reference_file_name, encoding="utf8") as reference, open(
861-
temp_output_path, encoding="utf8"
862-
) as temp_output_file:
860+
with (
861+
open(reference_file_name, encoding="utf8") as reference,
862+
open(temp_output_path, encoding="utf8") as temp_output_file,
863+
):
863864
lines1 = temp_output_file.readlines()
864865
lines2 = reference.readlines()
865866
self.assertListEqual(lines1, lines2)
866867

867868
with tempfile.TemporaryDirectory() as temp_problem_dir:
868869
q_p.write_to_lp_file(temp_problem_dir)
869-
with open(path.join(temp_problem_dir, "my_problem.lp"), encoding="utf8") as file1, open(
870-
reference_file_name, encoding="utf8"
871-
) as file2:
870+
with (
871+
open(path.join(temp_problem_dir, "my_problem.lp"), encoding="utf8") as file1,
872+
open(reference_file_name, encoding="utf8") as file2,
873+
):
872874
lines1 = file1.readlines()
873875
lines2 = file2.readlines()
874876
self.assertListEqual(lines1, lines2)

test/translators/test_prettyprint.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -495,43 +495,49 @@ def test_error(self):
495495
q_p = QuadraticProgram(name)
496496
_ = q_p.prettyprint()
497497

498-
with self.subTest("linear variable name - func"), self.assertRaises(
499-
QiskitOptimizationError
498+
with (
499+
self.subTest("linear variable name - func"),
500+
self.assertRaises(QiskitOptimizationError),
500501
):
501502
q_p = QuadraticProgram()
502503
q_p.binary_var(name)
503504
_ = prettyprint(q_p)
504505

505-
with self.subTest("linear variable name - meth"), self.assertRaises(
506-
QiskitOptimizationError
506+
with (
507+
self.subTest("linear variable name - meth"),
508+
self.assertRaises(QiskitOptimizationError),
507509
):
508510
q_p = QuadraticProgram()
509511
q_p.binary_var(name)
510512
_ = q_p.prettyprint()
511513

512-
with self.subTest("linear constraint name - func"), self.assertRaises(
513-
QiskitOptimizationError
514+
with (
515+
self.subTest("linear constraint name - func"),
516+
self.assertRaises(QiskitOptimizationError),
514517
):
515518
q_p = QuadraticProgram()
516519
q_p.linear_constraint(name=name)
517520
_ = prettyprint(q_p)
518521

519-
with self.subTest("linear constraint name - meth"), self.assertRaises(
520-
QiskitOptimizationError
522+
with (
523+
self.subTest("linear constraint name - meth"),
524+
self.assertRaises(QiskitOptimizationError),
521525
):
522526
q_p = QuadraticProgram()
523527
q_p.linear_constraint(name=name)
524528
_ = q_p.prettyprint()
525529

526-
with self.subTest("quadratic constraint name - func"), self.assertRaises(
527-
QiskitOptimizationError
530+
with (
531+
self.subTest("quadratic constraint name - func"),
532+
self.assertRaises(QiskitOptimizationError),
528533
):
529534
q_p = QuadraticProgram()
530535
q_p.quadratic_constraint(name=name)
531536
_ = prettyprint(q_p)
532537

533-
with self.subTest("quadratic constraint name - meth"), self.assertRaises(
534-
QiskitOptimizationError
538+
with (
539+
self.subTest("quadratic constraint name - meth"),
540+
self.assertRaises(QiskitOptimizationError),
535541
):
536542
q_p = QuadraticProgram()
537543
q_p.quadratic_constraint(name=name)

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tox]
22
minversion = 3.3.0
3-
envlist = py38, py39, py310, py311, py312, lint
3+
envlist = py39, py310, py311, py312, py313, lint
44
skipsdist = True
55

66
[testenv]

0 commit comments

Comments
 (0)