Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pylint and Mypy fixes to solve CI errors. Remove Python 3.8 support #1374

Merged
merged 21 commits into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .github/actions/install-psi4/action.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This code is part of a Qiskit project.
#
# (C) Copyright IBM 2021, 2023.
# (C) Copyright IBM 2021, 2025.
#
# 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
Expand All @@ -25,6 +25,11 @@ runs:
- run : |
source "$CONDA/etc/profile.d/conda.sh"
conda activate psi4env
py_requires_libecpint=("3.9" "3.10")
if [[ "${{ inputs.os }}" == "ubuntu-latest" && " ${py_requires_libecpint[@]} " =~ "${{ inputs.python-version }}" ]]; then
echo "installs libecpint"
conda install -c conda-forge libecpint
fi
echo "installs psi4 stable release"
conda install -y psi4 python=${{ inputs.python-version }} -c conda-forge/label/libint_dev -c conda-forge
shell: bash
2 changes: 1 addition & 1 deletion .github/actions/run-tests/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,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_nature --omit */gauopen/* --parallel-mode"
fi
stestr --test-path test run 2> >(tee /dev/stderr out.txt > /dev/null)
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy-code.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.8]
python-version: [3.9]
steps:
- uses: actions/checkout@v4
with:
Expand Down
47 changes: 22 additions & 25 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This code is part of a Qiskit project.
#
# (C) Copyright IBM 2021, 2024.
# (C) Copyright IBM 2021, 2025.
#
# 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
Expand Down Expand Up @@ -36,7 +36,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
python-version: [3.8]
python-version: [3.9]
steps:
- name: Print Concurrency Group
env:
Expand Down Expand Up @@ -149,14 +149,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.12
- os: windows-latest
python-version: 3.8
python-version: 3.9
- os: windows-latest
python-version: 3.12
steps:
Expand All @@ -169,6 +169,12 @@ jobs:
setup.py
requirements.txt
requirements-dev.txt
- uses: conda-incubator/setup-miniconda@v3
id: setup-miniforge
continue-on-error: true
with:
miniforge-version: latest
if: ${{ matrix.os == 'macos-latest' }}
- name: Create conda environment
run: |
if [ "${{ matrix.os }}" == "macos-latest" ]; then
Expand All @@ -195,11 +201,6 @@ jobs:
- uses: ./.github/actions/install-nature
with:
use-conda: "true"
- name: Set up problem matches
run: |
echo "::add-matcher::./.github/problem_matchers/pylint.json"
echo "::add-matcher::./.github/problem_matchers/mypy.json"
if: ${{ matrix.os == 'ubuntu-latest' && matrix.python-version == 3.8 }}
- name: Run lint
run: |
source "$CONDA/etc/profile.d/conda.sh"
Expand Down Expand Up @@ -245,7 +246,7 @@ jobs:
conda activate psi4env
coverage3 combine
mv .coverage ./ci-artifact-data/nat.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:
Expand Down Expand Up @@ -274,7 +275,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest]
python-version: [3.8, 3.12]
python-version: [3.9, 3.12]
steps:
- uses: actions/checkout@v4
with:
Expand Down Expand Up @@ -341,30 +342,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, Nature, 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/u38
- uses: actions/download-artifact@v4
with:
name: ubuntu-latest-3.9
Expand All @@ -383,16 +380,16 @@ jobs:
path: /tmp/u312
- 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.12
path: /tmp/m312
- 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.12
Expand All @@ -402,10 +399,10 @@ jobs:
shell: bash
- name: Combined Deprecation Messages
run: |
sort -f -u /tmp/u38/nat.dep /tmp/u39/nat.dep /tmp/u310/nat.dep /tmp/u311/nat.dep /tmp/u312/nat.dep /tmp/m38/nat.dep /tmp/m312/nat.dep /tmp/w38/nat.dep /tmp/w312/nat.dep || true
sort -f -u /tmp/u39/nat.dep /tmp/u310/nat.dep /tmp/u311/nat.dep /tmp/u312/nat.dep /tmp/m39/nat.dep /tmp/m312/nat.dep /tmp/w39/nat.dep /tmp/w312/nat.dep || true
shell: bash
- name: Coverage combine
run: coverage3 combine /tmp/u38/nat.dat
run: coverage3 combine /tmp/u39/nat.dat
shell: bash
- name: Upload to Coveralls
env:
Expand Down
8 changes: 4 additions & 4 deletions .mergify.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
queue_rules:
- name: automerge
conditions:
- check-success=Deprecation_Messages_and_Coverage (3.8)
queue_conditions:
- check-success=Deprecation_Messages_and_Coverage (3.9)
merge_method: squash

pull_request_rules:
- name: automatic merge on CI success and review
conditions:
- check-success=Deprecation_Messages_and_Coverage (3.8)
- check-success=Deprecation_Messages_and_Coverage (3.9)
- "#approved-reviews-by>=1"
- label=automerge
- label!=on hold
actions:
queue:
name: automerge
method: squash
- name: backport
conditions:
- label=stable backport potential
Expand Down
1 change: 1 addition & 0 deletions .pylintdict
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,7 @@ tran
translational
transpilation
transpile
transpiler
trotterization
tryptophan
tuple
Expand Down
5 changes: 3 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,9 @@ please ensure that:
that change and that the PR is tagged for the changelog.

5. Ensure all code, including unit tests, has the copyright header. The copyright
date will be checked by CI build. The format of the date(s) is _year of creation,
last year changed_. So for example:
date will be checked by CI build. You can automatically fix the copyright dates
by running `make copyright`.
The format of the date(s) is _year of creation, last year changed_. So for example:

> \# (C) Copyright IBM 2018, 2021.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This code is part of a Qiskit project.
#
# (C) Copyright IBM 2020, 2024.
# (C) Copyright IBM 2020, 2025.
#
# 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
Expand Down Expand Up @@ -946,6 +946,7 @@ def _evaluate_observables_excited_states(

return aux_operators_eigenvalues, transition_amplitudes

# pylint: disable=too-many-positional-arguments
def _build_qeom_result(
self,
problem,
Expand Down
24 changes: 14 additions & 10 deletions qiskit_nature/second_q/circuit/library/ansatzes/ucc.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This code is part of a Qiskit project.
#
# (C) Copyright IBM 2021, 2024.
# (C) Copyright IBM 2021, 2025.
#
# 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
Expand All @@ -18,7 +18,7 @@
import logging
from functools import partial
from itertools import chain
from typing import Callable, Sequence
from typing import Callable, Sequence, Dict, Any

from qiskit.circuit import QuantumCircuit
from qiskit.circuit.library import EvolvedOperatorAnsatz
Expand Down Expand Up @@ -456,12 +456,14 @@ def _get_excitation_generators(self) -> list[Callable]:
logger.debug("Gathering excitation generators...")
generators: list[Callable] = []

extra_kwargs = {
"alpha_spin": self._alpha_spin,
"beta_spin": self._beta_spin,
"max_spin_excitation": self._max_spin_excitation,
"generalized": self._generalized,
"preserve_spin": self._preserve_spin,
extra_kwargs: Dict[str, Any] = {
"alpha_spin": bool(self._alpha_spin),
"beta_spin": bool(self._beta_spin),
"max_spin_excitation": (
int(self._max_spin_excitation) if self._max_spin_excitation is not None else None
),
"generalized": bool(self._generalized),
"preserve_spin": bool(self._preserve_spin),
}

if isinstance(self.excitations, str):
Expand All @@ -480,9 +482,11 @@ def _get_excitation_generators(self) -> list[Callable]:
)
)
elif isinstance(self.excitations, list):
for exc in self.excitations: # type: ignore
for excitation in self.excitations:
generators.append(
partial(generate_fermionic_excitations, num_excitations=exc, **extra_kwargs)
partial(
generate_fermionic_excitations, num_excitations=excitation, **extra_kwargs
)
)
elif callable(self.excitations):
generators = [self.excitations]
Expand Down
6 changes: 3 additions & 3 deletions qiskit_nature/second_q/circuit/library/ansatzes/uvcc.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This code is part of a Qiskit project.
#
# (C) Copyright IBM 2021, 2024.
# (C) Copyright IBM 2021, 2025.
#
# 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
Expand Down Expand Up @@ -322,11 +322,11 @@ def _get_excitation_generators(self) -> list[Callable]:
)
)
elif isinstance(self.excitations, list):
for exc in self.excitations: # type: ignore
for excitation in self.excitations:
generators.append(
partial(
generate_vibration_excitations,
num_excitations=exc,
num_excitations=excitation,
)
)
elif callable(self.excitations):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This code is part of a Qiskit project.
#
# (C) Copyright IBM 2018, 2023.
# (C) Copyright IBM 2018, 2025.
#
# 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
Expand Down Expand Up @@ -269,8 +269,8 @@ def hartree_fock_bitstring(num_spatial_orbitals: int, num_particles: tuple[int,
raise ValueError("# of particles must be less than or equal to # of orbitals.")

half_orbitals = num_spatial_orbitals
bitstr = np.zeros(2 * num_spatial_orbitals, bool)
bitstr = np.zeros(2 * num_spatial_orbitals, dtype=bool)
bitstr[:num_alpha] = True
bitstr[half_orbitals : (half_orbitals + num_beta)] = True

return bitstr.tolist()
return [bool(x) for x in bitstr.tolist()]
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This code is part of a Qiskit project.
#
# (C) Copyright IBM 2020, 2023.
# (C) Copyright IBM 2020, 2025.
#
# 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
Expand All @@ -16,6 +16,7 @@

import logging

from typing import List
import numpy as np

from qiskit import QuantumRegister
Expand Down Expand Up @@ -208,7 +209,7 @@ def vscf_bitstring_mapped(
return bits


def vscf_bitstring(num_modals: list[int]) -> list[bool]:
def vscf_bitstring(num_modals: List[int]) -> List[bool]:
"""Compute the bitstring representing the VSCF initial state based on the modals per mode.

Args:
Expand All @@ -219,10 +220,10 @@ def vscf_bitstring(num_modals: list[int]) -> list[bool]:
The bitstring representing the state of the VSCF state as array of bools.
"""
num_qubits = sum(num_modals)
bitstr = np.zeros(num_qubits, bool)
bitstr = np.zeros(num_qubits, dtype=bool)
count = 0
for modal in num_modals:
bitstr[count] = True
count += modal

return bitstr.tolist()
return [bool(x) for x in bitstr.tolist()]
4 changes: 2 additions & 2 deletions qiskit_nature/second_q/drivers/psi4d/psi4driver.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This code is part of a Qiskit project.
#
# (C) Copyright IBM 2018, 2024.
# (C) Copyright IBM 2018, 2025.
#
# 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
Expand Down Expand Up @@ -245,5 +245,5 @@ def _run_psi4(input_file, output_file):
logger.error(line)
errmsg += line + "\n"
raise QiskitNatureError(
f"{_optionals.PSI4} process return code {process.returncode}\n{errmsg}"
f"{_optionals.PSI4} process return code {process.returncode}: {errmsg}"
)
Loading
Loading