From 723db6bbdedce3375cf1063df185b2c7f8c9aca6 Mon Sep 17 00:00:00 2001 From: Takashi Imamichi Date: Thu, 17 Oct 2024 14:41:41 +0900 Subject: [PATCH 1/6] Bump minimum supported python version to 3.9 --- .github/actions/run-tests/action.yml | 2 +- .github/workflows/deploy-code.yml | 2 +- .github/workflows/deploy-docs.yml | 2 +- .github/workflows/main.yml | 34 ++++++++++++---------------- 4 files changed, 18 insertions(+), 22 deletions(-) diff --git a/.github/actions/run-tests/action.yml b/.github/actions/run-tests/action.yml index 2d39a1041..f91afe488 100644 --- a/.github/actions/run-tests/action.yml +++ b/.github/actions/run-tests/action.yml @@ -40,7 +40,7 @@ runs: if [ "${{ inputs.event-name }}" == "schedule" ] || [ "${{ inputs.run-slow }}" == "true" ]; then export QISKIT_TESTS="run_slow" fi - if [ "${{ inputs.os }}" == "ubuntu-latest" ] && [ "${{ inputs.python-version }}" == "3.8" ]; then + if [ "${{ inputs.os }}" == "ubuntu-latest" ] && [ "${{ inputs.python-version }}" == "3.9" ]; then export PYTHON="coverage3 run --source qiskit_optimization --parallel-mode" fi stestr --test-path test run 2> >(tee /dev/stderr out.txt > /dev/null) diff --git a/.github/workflows/deploy-code.yml b/.github/workflows/deploy-code.yml index 27830026d..163e75b87 100644 --- a/.github/workflows/deploy-code.yml +++ b/.github/workflows/deploy-code.yml @@ -25,7 +25,7 @@ jobs: id-token: write strategy: matrix: - python-version: [3.8] + python-version: [3.9] steps: - uses: actions/checkout@v4 - uses: actions/setup-python@v5 diff --git a/.github/workflows/deploy-docs.yml b/.github/workflows/deploy-docs.yml index d981d58e5..4dc91f8d7 100644 --- a/.github/workflows/deploy-docs.yml +++ b/.github/workflows/deploy-docs.yml @@ -26,7 +26,7 @@ jobs: strategy: matrix: os: [ubuntu-latest] - python-version: [3.8] + python-version: [3.9] steps: - uses: actions/checkout@v4 with: diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 83a63f6d2..1f37f747d 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -36,7 +36,7 @@ jobs: strategy: matrix: os: [ubuntu-latest] - python-version: [3.8] + python-version: [3.9] steps: - name: Print Concurrency Group env: @@ -119,14 +119,14 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest] - python-version: [3.8, 3.9, '3.10', 3.11, 3.12] + python-version: [3.9, '3.10', 3.11, 3.12] include: - os: macos-latest - python-version: 3.8 + python-version: 3.9 - os: macos-latest python-version: 3.11 - os: windows-latest - python-version: 3.8 + python-version: 3.9 - os: windows-latest python-version: 3.11 steps: @@ -197,7 +197,7 @@ jobs: fi coverage3 combine mv .coverage ./ci-artifact-data/opt.dat - if: ${{ matrix.os == 'ubuntu-latest' && matrix.python-version == 3.8 }} + if: ${{ matrix.os == 'ubuntu-latest' && matrix.python-version == 3.9 }} shell: bash - uses: actions/upload-artifact@v4 with: @@ -225,7 +225,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest] - python-version: [3.8, 3.11] + python-version: [3.9, 3.11] steps: - uses: actions/checkout@v4 with: @@ -290,30 +290,26 @@ jobs: cd docs/_build/html mkdir artifacts tar -zcvf artifacts/tutorials.tar.gz --exclude=./artifacts . - if: ${{ matrix.python-version == 3.8 && !startsWith(github.ref, 'refs/heads/stable') && !startsWith(github.base_ref, 'stable/') }} + if: ${{ matrix.python-version == 3.9 && !startsWith(github.ref, 'refs/heads/stable') && !startsWith(github.base_ref, 'stable/') }} shell: bash - name: Run upload stable tutorials uses: actions/upload-artifact@v4 with: name: tutorials-stable${{ matrix.python-version }} path: docs/_build/html/artifacts/tutorials.tar.gz - if: ${{ matrix.python-version == 3.8 && !startsWith(github.ref, 'refs/heads/stable') && !startsWith(github.base_ref, 'stable/') }} + if: ${{ matrix.python-version == 3.9 && !startsWith(github.ref, 'refs/heads/stable') && !startsWith(github.base_ref, 'stable/') }} Deprecation_Messages_and_Coverage: if: github.repository_owner == 'qiskit-community' needs: [Checks, Optimization, Tutorials] runs-on: ubuntu-latest strategy: matrix: - python-version: [3.8] + python-version: [3.9] steps: - uses: actions/checkout@v4 - uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} - - uses: actions/download-artifact@v4 - with: - name: ubuntu-latest-3.8 - path: /tmp/o38 - uses: actions/download-artifact@v4 with: name: ubuntu-latest-3.9 @@ -332,16 +328,16 @@ jobs: path: /tmp/o312 - uses: actions/download-artifact@v4 with: - name: macos-latest-3.8 - path: /tmp/m38 + name: macos-latest-3.9 + path: /tmp/m39 - uses: actions/download-artifact@v4 with: name: macos-latest-3.11 path: /tmp/m311 - uses: actions/download-artifact@v4 with: - name: windows-latest-3.8 - path: /tmp/w38 + name: windows-latest-3.9 + path: /tmp/w39 - uses: actions/download-artifact@v4 with: name: windows-latest-3.11 @@ -351,10 +347,10 @@ jobs: shell: bash - name: Combined Deprecation Messages run: | - 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 + 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/w311/opt.dep || true shell: bash - name: Coverage combine - run: coverage3 combine /tmp/o38/opt.dat + run: coverage3 combine /tmp/o39/opt.dat shell: bash - name: Upload to Coveralls env: From 55cb492c638041cd27e0209eb56230103d0d0565 Mon Sep 17 00:00:00 2001 From: Takashi Imamichi Date: Thu, 17 Oct 2024 14:51:10 +0900 Subject: [PATCH 2/6] avoid too-many-positional-arguments --- .pylintrc | 1 + 1 file changed, 1 insertion(+) diff --git a/.pylintrc b/.pylintrc index 00c2fd1af..dbf8602e3 100644 --- a/.pylintrc +++ b/.pylintrc @@ -71,6 +71,7 @@ disable=fixme, # disabled as TODOs would show up as warnings no-else-return, # relax "elif" after a clause with a return docstring-first-line-empty, # relax docstring style import-outside-toplevel, + unknown-option-value, [REPORTS] From abe554dacdb093a08509b6d30c30dbcd98dfdc9b Mon Sep 17 00:00:00 2001 From: Takashi Imamichi Date: Thu, 17 Oct 2024 15:03:11 +0900 Subject: [PATCH 3/6] addresses numpy 2 behavior --- qiskit_optimization/algorithms/optimization_algorithm.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/qiskit_optimization/algorithms/optimization_algorithm.py b/qiskit_optimization/algorithms/optimization_algorithm.py index 0b5b6ef0c..50bfe1a8a 100644 --- a/qiskit_optimization/algorithms/optimization_algorithm.py +++ b/qiskit_optimization/algorithms/optimization_algorithm.py @@ -1,6 +1,6 @@ # This code is part of a Qiskit project. # -# (C) Copyright IBM 2020, 2023. +# (C) Copyright IBM 2020, 2024. # # This code is licensed under the Apache License, Version 2.0. You may # obtain a copy of this license in the LICENSE.txt file in the root directory @@ -131,7 +131,9 @@ def __init__( f"variables: size {len(variables)} {[v.name for v in variables]}" ) self._x = np.asarray(x) - self._variables_dict = dict(zip(self._variable_names, self._x)) + self._variables_dict = { + name: val.item() for name, val in zip(self._variable_names, self._x) + } self._fval = fval self._raw_results = raw_results From e54c4586059bf83d72cb1d3a6a00de28941ef92c Mon Sep 17 00:00:00 2001 From: Takashi Imamichi Date: Fri, 18 Oct 2024 12:18:07 +0900 Subject: [PATCH 4/6] update tox.ini and pyproject.toml --- pyproject.toml | 2 +- setup.py | 3 +-- tox.ini | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index f9728a2be..c38b9a3dc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,4 +4,4 @@ build-backend = "setuptools.build_meta" [tool.black] line-length = 100 -target-version = ['py38', 'py39', 'py310', 'py311'] +target-version = ['py39', 'py310', 'py311', 'py312'] diff --git a/setup.py b/setup.py index 691b414a3..05b14cec7 100644 --- a/setup.py +++ b/setup.py @@ -61,7 +61,6 @@ "Operating System :: MacOS", "Operating System :: POSIX :: Linux", "Programming Language :: Python :: 3 :: Only", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -72,7 +71,7 @@ packages=setuptools.find_packages(include=["qiskit_optimization", "qiskit_optimization.*"]), install_requires=REQUIREMENTS, include_package_data=True, - python_requires=">=3.8", + python_requires=">=3.9", extras_require={ "cplex": ["cplex; python_version < '3.12' and platform_machine != 'arm64'"], "cvx": ["cvxpy"], diff --git a/tox.ini b/tox.ini index b917bc540..ed001cf6e 100644 --- a/tox.ini +++ b/tox.ini @@ -1,6 +1,6 @@ [tox] minversion = 3.3.0 -envlist = py38, py39, py310, py311, py312, lint +envlist = py39, py310, py311, py312, lint skipsdist = True [testenv] From d17d0d3cfcca639e5696901ff53f8590795e6765 Mon Sep 17 00:00:00 2001 From: Takashi Imamichi Date: Fri, 18 Oct 2024 14:45:11 +0900 Subject: [PATCH 5/6] black --- test/problems/test_quadratic_program.py | 16 +++++++------ test/translators/test_prettyprint.py | 32 +++++++++++++++---------- 2 files changed, 28 insertions(+), 20 deletions(-) diff --git a/test/problems/test_quadratic_program.py b/test/problems/test_quadratic_program.py index a98aba9e8..1fdb2c1a1 100644 --- a/test/problems/test_quadratic_program.py +++ b/test/problems/test_quadratic_program.py @@ -1,6 +1,6 @@ # This code is part of a Qiskit project. # -# (C) Copyright IBM 2020, 2023. +# (C) Copyright IBM 2020, 2024. # # This code is licensed under the Apache License, Version 2.0. You may # 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): with tempfile.TemporaryDirectory() as tmp: temp_output_path = path.join(tmp, "temp.lp") q_p.write_to_lp_file(temp_output_path) - with open(reference_file_name, encoding="utf8") as reference, open( - temp_output_path, encoding="utf8" - ) as temp_output_file: + with ( + open(reference_file_name, encoding="utf8") as reference, + open(temp_output_path, encoding="utf8") as temp_output_file, + ): lines1 = temp_output_file.readlines() lines2 = reference.readlines() self.assertListEqual(lines1, lines2) with tempfile.TemporaryDirectory() as temp_problem_dir: q_p.write_to_lp_file(temp_problem_dir) - with open(path.join(temp_problem_dir, "my_problem.lp"), encoding="utf8") as file1, open( - reference_file_name, encoding="utf8" - ) as file2: + with ( + open(path.join(temp_problem_dir, "my_problem.lp"), encoding="utf8") as file1, + open(reference_file_name, encoding="utf8") as file2, + ): lines1 = file1.readlines() lines2 = file2.readlines() self.assertListEqual(lines1, lines2) diff --git a/test/translators/test_prettyprint.py b/test/translators/test_prettyprint.py index 6fead2566..751c5a432 100644 --- a/test/translators/test_prettyprint.py +++ b/test/translators/test_prettyprint.py @@ -1,6 +1,6 @@ # This code is part of a Qiskit project. # -# (C) Copyright IBM 2022, 2023. +# (C) Copyright IBM 2022, 2024. # # This code is licensed under the Apache License, Version 2.0. You may # obtain a copy of this license in the LICENSE.txt file in the root directory @@ -495,43 +495,49 @@ def test_error(self): q_p = QuadraticProgram(name) _ = q_p.prettyprint() - with self.subTest("linear variable name - func"), self.assertRaises( - QiskitOptimizationError + with ( + self.subTest("linear variable name - func"), + self.assertRaises(QiskitOptimizationError), ): q_p = QuadraticProgram() q_p.binary_var(name) _ = prettyprint(q_p) - with self.subTest("linear variable name - meth"), self.assertRaises( - QiskitOptimizationError + with ( + self.subTest("linear variable name - meth"), + self.assertRaises(QiskitOptimizationError), ): q_p = QuadraticProgram() q_p.binary_var(name) _ = q_p.prettyprint() - with self.subTest("linear constraint name - func"), self.assertRaises( - QiskitOptimizationError + with ( + self.subTest("linear constraint name - func"), + self.assertRaises(QiskitOptimizationError), ): q_p = QuadraticProgram() q_p.linear_constraint(name=name) _ = prettyprint(q_p) - with self.subTest("linear constraint name - meth"), self.assertRaises( - QiskitOptimizationError + with ( + self.subTest("linear constraint name - meth"), + self.assertRaises(QiskitOptimizationError), ): q_p = QuadraticProgram() q_p.linear_constraint(name=name) _ = q_p.prettyprint() - with self.subTest("quadratic constraint name - func"), self.assertRaises( - QiskitOptimizationError + with ( + self.subTest("quadratic constraint name - func"), + self.assertRaises(QiskitOptimizationError), ): q_p = QuadraticProgram() q_p.quadratic_constraint(name=name) _ = prettyprint(q_p) - with self.subTest("quadratic constraint name - meth"), self.assertRaises( - QiskitOptimizationError + with ( + self.subTest("quadratic constraint name - meth"), + self.assertRaises(QiskitOptimizationError), ): q_p = QuadraticProgram() q_p.quadratic_constraint(name=name) From 9492c35055523077d478992146f1eefb4dfe90d2 Mon Sep 17 00:00:00 2001 From: Takashi Imamichi Date: Mon, 25 Nov 2024 18:41:20 +0900 Subject: [PATCH 6/6] reno --- releasenotes/notes/drop-python-38-9acf65912c73ad58.yaml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 releasenotes/notes/drop-python-38-9acf65912c73ad58.yaml diff --git a/releasenotes/notes/drop-python-38-9acf65912c73ad58.yaml b/releasenotes/notes/drop-python-38-9acf65912c73ad58.yaml new file mode 100644 index 000000000..255ab088d --- /dev/null +++ b/releasenotes/notes/drop-python-38-9acf65912c73ad58.yaml @@ -0,0 +1,6 @@ +--- +upgrade: + - | + Support for running with Python 3.8 has been removed. + To run Qiskit Optimization you need a minimum Python version of 3.9. +