From cd29321ac7e12d79e02d6c536c4619bf3b68eb43 Mon Sep 17 00:00:00 2001 From: ftroisi Date: Wed, 15 Jan 2025 11:57:50 +0100 Subject: [PATCH 01/21] Fixed pylint warnings --- .../second_q/algorithms/excited_states_solvers/qeom.py | 1 + qiskit_nature/second_q/hamiltonians/electronic_energy.py | 2 +- .../second_q/hamiltonians/fermi_hubbard_model.py | 2 ++ .../second_q/hamiltonians/lattices/kagome_lattice.py | 1 + .../second_q/hamiltonians/lattices/square_lattice.py | 1 + .../second_q/hamiltonians/lattices/triangular_lattice.py | 1 + qiskit_nature/second_q/mappers/bksf.py | 7 ++++--- .../second_q/mappers/bosonic_logarithmic_mapper.py | 8 ++++---- qiskit_nature/second_q/operators/electronic_integrals.py | 2 +- qiskit_nature/second_q/problems/harmonic_basis.py | 1 + qiskit_nature/second_q/problems/vibrational_basis.py | 1 + .../second_q/transformers/active_space_transformer.py | 5 +++++ .../ansatzes/utils/test_fermionic_excitation_generator.py | 2 ++ .../drivers/gaussiand/test_driver_gaussian_forces.py | 1 + test/second_q/drivers/test_driver.py | 1 + test/second_q/formats/fcidump/test_fcidump.py | 1 + test/second_q/formats/fcidump/test_fcidump_dumper.py | 1 + test/second_q/hamiltonians/lattices/test_lattice.py | 1 + test/second_q/operators/test_commutators.py | 1 + 19 files changed, 31 insertions(+), 9 deletions(-) diff --git a/qiskit_nature/second_q/algorithms/excited_states_solvers/qeom.py b/qiskit_nature/second_q/algorithms/excited_states_solvers/qeom.py index 03b7e02a1..b22b902a8 100644 --- a/qiskit_nature/second_q/algorithms/excited_states_solvers/qeom.py +++ b/qiskit_nature/second_q/algorithms/excited_states_solvers/qeom.py @@ -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, diff --git a/qiskit_nature/second_q/hamiltonians/electronic_energy.py b/qiskit_nature/second_q/hamiltonians/electronic_energy.py index 7d92ded7d..c28f9c3c5 100644 --- a/qiskit_nature/second_q/hamiltonians/electronic_energy.py +++ b/qiskit_nature/second_q/hamiltonians/electronic_energy.py @@ -139,7 +139,7 @@ def nuclear_repulsion_energy(self, e_nuc: float | None) -> None: else: self.constants["nuclear_repulsion_energy"] = e_nuc - # pylint: disable=invalid-name + # pylint: disable=invalid-name, disable=too-many-positional-arguments @classmethod def from_raw_integrals( cls, diff --git a/qiskit_nature/second_q/hamiltonians/fermi_hubbard_model.py b/qiskit_nature/second_q/hamiltonians/fermi_hubbard_model.py index fdab0be01..dbf74eaec 100644 --- a/qiskit_nature/second_q/hamiltonians/fermi_hubbard_model.py +++ b/qiskit_nature/second_q/hamiltonians/fermi_hubbard_model.py @@ -94,7 +94,9 @@ def second_q_op(self) -> FermionicOp: index_left = 2 * node_b + spin index_right = 2 * node_a + spin hopping_parameter = np.conjugate(weight) + # pylint: disable=possibly-used-before-assignment kinetic_ham[f"+_{index_left} -_{index_right}"] = hopping_parameter + # pylint: disable=possibly-used-before-assignment kinetic_ham[f"-_{index_left} +_{index_right}"] = -np.conjugate( hopping_parameter ) diff --git a/qiskit_nature/second_q/hamiltonians/lattices/kagome_lattice.py b/qiskit_nature/second_q/hamiltonians/lattices/kagome_lattice.py index 5625b4dde..a1ab2eb23 100644 --- a/qiskit_nature/second_q/hamiltonians/lattices/kagome_lattice.py +++ b/qiskit_nature/second_q/hamiltonians/lattices/kagome_lattice.py @@ -72,6 +72,7 @@ class KagomeLattice(Lattice): # Primitive translation vectors in each direction _basis = np.array([[2, 0], [1, np.sqrt(3)]]) + # pylint: disable=too-many-positional-arguments def __init__( self, rows: int, diff --git a/qiskit_nature/second_q/hamiltonians/lattices/square_lattice.py b/qiskit_nature/second_q/hamiltonians/lattices/square_lattice.py index ad1be151a..ee54f7035 100644 --- a/qiskit_nature/second_q/hamiltonians/lattices/square_lattice.py +++ b/qiskit_nature/second_q/hamiltonians/lattices/square_lattice.py @@ -20,6 +20,7 @@ class SquareLattice(HyperCubicLattice): """Square lattice.""" + # pylint: disable=too-many-positional-arguments def __init__( self, rows: int, diff --git a/qiskit_nature/second_q/hamiltonians/lattices/triangular_lattice.py b/qiskit_nature/second_q/hamiltonians/lattices/triangular_lattice.py index 46139f3d1..5c5c8683a 100644 --- a/qiskit_nature/second_q/hamiltonians/lattices/triangular_lattice.py +++ b/qiskit_nature/second_q/hamiltonians/lattices/triangular_lattice.py @@ -158,6 +158,7 @@ def _default_position(self) -> Dict[int, List[float]]: pos[index] = coord.tolist() return pos + # pylint: disable=too-many-positional-arguments def __init__( self, rows: int, diff --git a/qiskit_nature/second_q/mappers/bksf.py b/qiskit_nature/second_q/mappers/bksf.py index 943d09f44..694a23d0c 100644 --- a/qiskit_nature/second_q/mappers/bksf.py +++ b/qiskit_nature/second_q/mappers/bksf.py @@ -261,7 +261,8 @@ def _excitation_operator( # pylint: disable=invalid-name ## SW2018 eq 37 -def _double_excitation( # pylint: disable=invalid-name +# pylint: disable=invalid-name, disable=too-many-positional-arguments +def _double_excitation( edge_list: np.ndarray, p: int, q: int, r: int, s: int, h2_pqrs: float ) -> SparsePauliOp: """Map a double-excitation operator to a Pauli operator. @@ -303,8 +304,8 @@ def _double_excitation( # pylint: disable=invalid-name final_coeff = 0.125 return (final_coeff * h2_pqrs) * qubit_op - -def _number_excitation( # pylint: disable=invalid-name +# pylint: disable=invalid-name, disable=too-many-positional-arguments +def _number_excitation( edge_list: np.ndarray, p: int, q: int, r: int, s: int, h2_pqrs: float ) -> SparsePauliOp: """Map a number-excitation operator to a Pauli operator. diff --git a/qiskit_nature/second_q/mappers/bosonic_logarithmic_mapper.py b/qiskit_nature/second_q/mappers/bosonic_logarithmic_mapper.py index 0e6d3d591..631a596a6 100644 --- a/qiskit_nature/second_q/mappers/bosonic_logarithmic_mapper.py +++ b/qiskit_nature/second_q/mappers/bosonic_logarithmic_mapper.py @@ -100,10 +100,10 @@ def __init__(self, max_occupation: int) -> None: ) max_calculated_occupation = 2**self.number_of_qubits_per_mode - 1 if max_occupation != max_calculated_occupation: - logger.warning( - f"The user requested a max occupation of {max_occupation}, but the actual " - + f"max occupation is {max_calculated_occupation}." - ) + # Use of a message variable to suppress pylint warning logging-not-lazy + warning_message = f"The user requested a max occupation of {max_occupation}, " +\ + f"but the actual max occupation is {max_calculated_occupation}." + logger.warning(warning_message) super().__init__(max_calculated_occupation) @property diff --git a/qiskit_nature/second_q/operators/electronic_integrals.py b/qiskit_nature/second_q/operators/electronic_integrals.py index a9d1151bb..c6ec573c4 100644 --- a/qiskit_nature/second_q/operators/electronic_integrals.py +++ b/qiskit_nature/second_q/operators/electronic_integrals.py @@ -616,7 +616,7 @@ def einsum( ) return cls(alpha, beta, beta_alpha, validate=validate) - # pylint: disable=invalid-name + # pylint: disable=invalid-name, disable=too-many-positional-arguments @classmethod def from_raw_integrals( cls, diff --git a/qiskit_nature/second_q/problems/harmonic_basis.py b/qiskit_nature/second_q/problems/harmonic_basis.py index b4576c653..081a4b753 100644 --- a/qiskit_nature/second_q/problems/harmonic_basis.py +++ b/qiskit_nature/second_q/problems/harmonic_basis.py @@ -34,6 +34,7 @@ class HarmonicBasis(VibrationalBasis): https://doi.org/10.1039/D0SC01908A """ + # pylint: disable=too-many-positional-arguments @lru_cache(maxsize=128) def eval_integral( self, diff --git a/qiskit_nature/second_q/problems/vibrational_basis.py b/qiskit_nature/second_q/problems/vibrational_basis.py index 6d3af800d..7c485a59c 100644 --- a/qiskit_nature/second_q/problems/vibrational_basis.py +++ b/qiskit_nature/second_q/problems/vibrational_basis.py @@ -52,6 +52,7 @@ def __init__( self.num_modals = num_modals self.threshold = threshold + # pylint: disable=too-many-positional-arguments @abstractmethod @lru_cache(maxsize=128) def eval_integral( diff --git a/qiskit_nature/second_q/transformers/active_space_transformer.py b/qiskit_nature/second_q/transformers/active_space_transformer.py index 1b9f659ca..90458a636 100644 --- a/qiskit_nature/second_q/transformers/active_space_transformer.py +++ b/qiskit_nature/second_q/transformers/active_space_transformer.py @@ -435,6 +435,11 @@ def _determine_active_space( num_alpha, num_beta = self._num_electrons elif isinstance(self._num_electrons, (int, np.integer)): num_alpha = num_beta = self._num_electrons // 2 + else: + raise QiskitNatureError( + "The number of active electrons must be an int, or a tuple thereof, not: ", + type(self._num_electrons), + ) # compute number of inactive electrons nelec_inactive = total_num_electrons - num_alpha - num_beta diff --git a/test/second_q/circuit/library/ansatzes/utils/test_fermionic_excitation_generator.py b/test/second_q/circuit/library/ansatzes/utils/test_fermionic_excitation_generator.py index da8aca7c3..f6df0985c 100644 --- a/test/second_q/circuit/library/ansatzes/utils/test_fermionic_excitation_generator.py +++ b/test/second_q/circuit/library/ansatzes/utils/test_fermionic_excitation_generator.py @@ -145,6 +145,8 @@ def test_generate_excitations( ], ), ) + + # pylint: disable=too-many-positional-arguments def test_max_spin_excitation( self, num_excitations, num_spatial_orbitals, num_particles, max_spin, expect ): diff --git a/test/second_q/drivers/gaussiand/test_driver_gaussian_forces.py b/test/second_q/drivers/gaussiand/test_driver_gaussian_forces.py index 62a892109..3c27ecde6 100644 --- a/test/second_q/drivers/gaussiand/test_driver_gaussian_forces.py +++ b/test/second_q/drivers/gaussiand/test_driver_gaussian_forces.py @@ -210,6 +210,7 @@ def _get_expected_values(self, pbe: bool = False): matched = re.search("G16Rev\\w+\\.\\w+", qne.message) if matched is not None: version = matched[0] + exp_vals = [] if version == "G16RevA.03": if pbe: exp_vals = TestDriverGaussianForces._A03_REV_PBE_EXPECTED diff --git a/test/second_q/drivers/test_driver.py b/test/second_q/drivers/test_driver.py index 4dbdb330a..fb1151fcc 100644 --- a/test/second_q/drivers/test_driver.py +++ b/test/second_q/drivers/test_driver.py @@ -49,6 +49,7 @@ def subTest(self, msg, **kwargs): """subtest""" raise builtins.Exception("Abstract method") + # pylint: disable=too-many-positional-arguments @abstractmethod def assertAlmostEqual(self, first, second, places=None, msg=None, delta=None): """assert Almost Equal""" diff --git a/test/second_q/formats/fcidump/test_fcidump.py b/test/second_q/formats/fcidump/test_fcidump.py index 6760ef871..24e8877fd 100644 --- a/test/second_q/formats/fcidump/test_fcidump.py +++ b/test/second_q/formats/fcidump/test_fcidump.py @@ -44,6 +44,7 @@ def subTest(self, msg, **kwargs): """subtest""" raise builtins.Exception("Abstract method") + # pylint: disable=too-many-positional-arguments @abstractmethod def assertAlmostEqual(self, first, second, places=None, msg=None, delta=None): """assert Almost Equal""" diff --git a/test/second_q/formats/fcidump/test_fcidump_dumper.py b/test/second_q/formats/fcidump/test_fcidump_dumper.py index bf8b2898c..05e199769 100644 --- a/test/second_q/formats/fcidump/test_fcidump_dumper.py +++ b/test/second_q/formats/fcidump/test_fcidump_dumper.py @@ -51,6 +51,7 @@ def subTest(self, msg, **kwargs): """subtest""" raise builtins.Exception("Abstract method") + # pylint: disable=too-many-positional-arguments @abstractmethod def assertAlmostEqual(self, first, second, places=None, msg=None, delta=None): """assert Almost Equal""" diff --git a/test/second_q/hamiltonians/lattices/test_lattice.py b/test/second_q/hamiltonians/lattices/test_lattice.py index 265a180f5..0947f505e 100644 --- a/test/second_q/hamiltonians/lattices/test_lattice.py +++ b/test/second_q/hamiltonians/lattices/test_lattice.py @@ -144,6 +144,7 @@ def test_to_adjacency_matrix(self): @unittest.skipIf(not _optionals.HAS_NETWORKX, "networkx not available.") def test_from_networkx(self): """Test initialization from a networkx graph.""" + # pylint: disable=possibly-used-before-assignment graph = nx.Graph() graph.add_nodes_from(range(5)) graph.add_edges_from([(i, i + 1) for i in range(4)]) diff --git a/test/second_q/operators/test_commutators.py b/test/second_q/operators/test_commutators.py index 90085403c..c45b51710 100644 --- a/test/second_q/operators/test_commutators.py +++ b/test/second_q/operators/test_commutators.py @@ -67,6 +67,7 @@ def test_anti_commutator(self, op_a: FermionicOp, op_b: FermionicOp, expected: d anti_commutator(modified_op, op_b), FermionicOp(expected, num_spin_orbitals=1) ) + # pylint: disable=too-many-positional-arguments @unpack @data( (op1, op2, op3, False, {}), From 719cdcd2c2143e7150d882331f0a7426a6b03795 Mon Sep 17 00:00:00 2001 From: ftroisi Date: Wed, 15 Jan 2025 15:31:17 +0100 Subject: [PATCH 02/21] Fixed mypy errors --- .../algorithms/excited_states_solvers/qeom.py | 8 ++++---- .../second_q/circuit/library/ansatzes/ucc.py | 19 ++++++++++--------- .../second_q/circuit/library/ansatzes/uvcc.py | 4 ++-- .../library/initial_states/hartree_fock.py | 4 ++-- .../circuit/library/initial_states/vscf.py | 7 ++++--- .../second_q/mappers/bravyi_kitaev_mapper.py | 6 +++--- .../second_q/mappers/linear_mapper.py | 3 ++- .../second_q/mappers/logarithmic_mapper.py | 3 ++- .../second_q/operators/bosonic_op.py | 2 +- .../second_q/operators/fermionic_op.py | 2 +- .../second_q/operators/majorana_op.py | 2 +- qiskit_nature/second_q/operators/spin_op.py | 2 +- .../second_q/operators/symmetric_two_body.py | 8 ++++---- qiskit_nature/second_q/operators/tensor.py | 4 ++-- .../second_q/operators/vibrational_op.py | 2 +- .../second_q/problems/vibrational_basis.py | 2 +- 16 files changed, 41 insertions(+), 37 deletions(-) diff --git a/qiskit_nature/second_q/algorithms/excited_states_solvers/qeom.py b/qiskit_nature/second_q/algorithms/excited_states_solvers/qeom.py index b22b902a8..2962605b7 100644 --- a/qiskit_nature/second_q/algorithms/excited_states_solvers/qeom.py +++ b/qiskit_nature/second_q/algorithms/excited_states_solvers/qeom.py @@ -928,9 +928,9 @@ def _evaluate_observables_excited_states( indices_diag = np.diag_indices(size + 1) indices_diag_as_list = list(zip(indices_diag[0], indices_diag[1])) for indice in indices_diag_as_list: - aux_operators_eigenvalues[indice] = {} + aux_operators_eigenvalues[indice] = {} # type: ignore[index] for aux_name in untap_aux_ops.keys(): - aux_operators_eigenvalues[indice][aux_name] = aux_measurements.get( + aux_operators_eigenvalues[indice][aux_name] = aux_measurements.get( # type: ignore (aux_name, indice[0], indice[1]), (0.0, {}) ) @@ -938,9 +938,9 @@ def _evaluate_observables_excited_states( indices_offdiag = np.triu_indices(size + 1, k=1) indices_offdiag_as_list = list(zip(indices_offdiag[0], indices_offdiag[1])) for indice in indices_offdiag_as_list: - transition_amplitudes[indice] = {} + transition_amplitudes[indice] = {} # type: ignore[index] for aux_name in untap_aux_ops.keys(): - transition_amplitudes[indice][aux_name] = aux_measurements.get( + transition_amplitudes[indice][aux_name] = aux_measurements.get( # type: ignore (aux_name, indice[0], indice[1]), (0.0, {}) ) diff --git a/qiskit_nature/second_q/circuit/library/ansatzes/ucc.py b/qiskit_nature/second_q/circuit/library/ansatzes/ucc.py index 2bc6a9366..e05a8d515 100644 --- a/qiskit_nature/second_q/circuit/library/ansatzes/ucc.py +++ b/qiskit_nature/second_q/circuit/library/ansatzes/ucc.py @@ -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 @@ -456,12 +456,13 @@ 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): @@ -480,9 +481,9 @@ 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] diff --git a/qiskit_nature/second_q/circuit/library/ansatzes/uvcc.py b/qiskit_nature/second_q/circuit/library/ansatzes/uvcc.py index e3f588cb0..e6dd802ce 100644 --- a/qiskit_nature/second_q/circuit/library/ansatzes/uvcc.py +++ b/qiskit_nature/second_q/circuit/library/ansatzes/uvcc.py @@ -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): diff --git a/qiskit_nature/second_q/circuit/library/initial_states/hartree_fock.py b/qiskit_nature/second_q/circuit/library/initial_states/hartree_fock.py index c406fe729..afc5bbde9 100644 --- a/qiskit_nature/second_q/circuit/library/initial_states/hartree_fock.py +++ b/qiskit_nature/second_q/circuit/library/initial_states/hartree_fock.py @@ -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()] diff --git a/qiskit_nature/second_q/circuit/library/initial_states/vscf.py b/qiskit_nature/second_q/circuit/library/initial_states/vscf.py index b0c3fd72a..30a6137f5 100644 --- a/qiskit_nature/second_q/circuit/library/initial_states/vscf.py +++ b/qiskit_nature/second_q/circuit/library/initial_states/vscf.py @@ -16,6 +16,7 @@ import logging +from typing import List import numpy as np from qiskit import QuantumRegister @@ -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: @@ -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()] diff --git a/qiskit_nature/second_q/mappers/bravyi_kitaev_mapper.py b/qiskit_nature/second_q/mappers/bravyi_kitaev_mapper.py index e55741ab1..e75eea1c3 100644 --- a/qiskit_nature/second_q/mappers/bravyi_kitaev_mapper.py +++ b/qiskit_nature/second_q/mappers/bravyi_kitaev_mapper.py @@ -145,11 +145,11 @@ def flip_set(j, n): ) ) for k in range(register_length): - if np.in1d(k, update_sets[j]): + if np.isin(k, update_sets[j]): update_pauli[j].x[k] = True - if np.in1d(k, parity_sets[j]): + if np.isin(k, parity_sets[j]): parity_pauli[j].z[k] = True - if np.in1d(k, remainder_sets[j]): + if np.isin(k, remainder_sets[j]): remainder_pauli[j].z[k] = True x_j = Pauli( diff --git a/qiskit_nature/second_q/mappers/linear_mapper.py b/qiskit_nature/second_q/mappers/linear_mapper.py index c4466db0d..6913801ff 100644 --- a/qiskit_nature/second_q/mappers/linear_mapper.py +++ b/qiskit_nature/second_q/mappers/linear_mapper.py @@ -53,7 +53,8 @@ def _map_single( operatorlist = [mat[i] if i in mat else identity for i in range(register_length)] # Now, we can tensor all operators in this list - qubit_ops_list.append(coeff * reduce(operator.xor, reversed(operatorlist))) + qubit_ops_list.append( + coeff * reduce(operator.xor, reversed(operatorlist))) # type: ignore[operator] qubit_op = reduce(operator.add, qubit_ops_list) return qubit_op.simplify() diff --git a/qiskit_nature/second_q/mappers/logarithmic_mapper.py b/qiskit_nature/second_q/mappers/logarithmic_mapper.py index 4fd939248..61eb2cff9 100644 --- a/qiskit_nature/second_q/mappers/logarithmic_mapper.py +++ b/qiskit_nature/second_q/mappers/logarithmic_mapper.py @@ -102,7 +102,8 @@ def _map_single( operatorlist = [mat[i] if i in mat else identity for i in range(register_length)] # Now, we can tensor all operators in this list - qubit_ops_list.append(coeff * reduce(operator.xor, reversed(operatorlist))) + qubit_ops_list.append( + coeff * reduce(operator.xor, reversed(operatorlist))) # type: ignore[operator] qubit_op = reduce(operator.add, qubit_ops_list) diff --git a/qiskit_nature/second_q/operators/bosonic_op.py b/qiskit_nature/second_q/operators/bosonic_op.py index 56ce46bc5..5eb2b3f37 100644 --- a/qiskit_nature/second_q/operators/bosonic_op.py +++ b/qiskit_nature/second_q/operators/bosonic_op.py @@ -195,7 +195,7 @@ def _new_instance( return self.__class__(data, copy=False, num_modes=num_so) def _validate_keys(self, keys: Collection[str]) -> None: - super()._validate_keys(keys) + super()._validate_keys(keys) # type: ignore[safe-super] num_so = self.num_modes diff --git a/qiskit_nature/second_q/operators/fermionic_op.py b/qiskit_nature/second_q/operators/fermionic_op.py index 3c846b547..8aba98556 100644 --- a/qiskit_nature/second_q/operators/fermionic_op.py +++ b/qiskit_nature/second_q/operators/fermionic_op.py @@ -196,7 +196,7 @@ def _new_instance( return self.__class__(data, copy=False, num_spin_orbitals=num_so) def _validate_keys(self, keys: Collection[str]) -> None: - super()._validate_keys(keys) + super()._validate_keys(keys) # type: ignore[safe-super] num_so = self.num_spin_orbitals diff --git a/qiskit_nature/second_q/operators/majorana_op.py b/qiskit_nature/second_q/operators/majorana_op.py index b6c67f884..cbb83eb0b 100644 --- a/qiskit_nature/second_q/operators/majorana_op.py +++ b/qiskit_nature/second_q/operators/majorana_op.py @@ -250,7 +250,7 @@ def _new_instance( return self.__class__(data, copy=False, num_modes=num_modes) def _validate_keys(self, keys: Collection[str]) -> None: - super()._validate_keys(keys) + super()._validate_keys(keys) # type: ignore[safe-super] num_modes = self.num_modes diff --git a/qiskit_nature/second_q/operators/spin_op.py b/qiskit_nature/second_q/operators/spin_op.py index 5dd9eaebb..f667cf04d 100644 --- a/qiskit_nature/second_q/operators/spin_op.py +++ b/qiskit_nature/second_q/operators/spin_op.py @@ -254,7 +254,7 @@ def _new_instance(self, data: Mapping[str, _TCoeff], *, other: SpinOp | None = N return self.__class__(data, copy=False, num_spins=num_s) def _validate_keys(self, keys: Collection[str]) -> None: - super()._validate_keys(keys) + super()._validate_keys(keys) # type: ignore[safe-super] num_s = self.num_spins diff --git a/qiskit_nature/second_q/operators/symmetric_two_body.py b/qiskit_nature/second_q/operators/symmetric_two_body.py index b3d4c54e3..14bbbe63f 100644 --- a/qiskit_nature/second_q/operators/symmetric_two_body.py +++ b/qiskit_nature/second_q/operators/symmetric_two_body.py @@ -665,7 +665,7 @@ def fold_s1_to_s8(eri: Tensor | ARRAY_TYPE, *, validate: bool = True) -> S8Integ new_eri = np.zeros(npair * (npair + 1) // 2) ijkl = 0 for ij, (i, j) in enumerate(zip(*np.tril_indices(norb))): - for kl, (k, l) in enumerate(zip(*np.tril_indices(i + 1))): + for kl, (k, l) in enumerate(zip(*np.tril_indices(int(i + 1)))): if ij >= kl: new_eri[ijkl] = eri[i, j, k, l] ijkl += 1 @@ -857,9 +857,9 @@ def unfold_s8_to_s1(eri: Tensor | ARRAY_TYPE, *, validate: bool = True) -> S1Int row = np.zeros(npair) idx = ij * (ij + 1) // 2 row[:ij] = eri[idx : idx + ij] - for k in range(ij, npair): - idx += k - row[k] = eri[idx] + for a in range(ij, npair): + idx += a + row[a] = eri[idx] idx = ij * (ij + 1) // 2 for kl, (k, l) in enumerate(zip(*np.tril_indices(norb))): if ij <= kl: diff --git a/qiskit_nature/second_q/operators/tensor.py b/qiskit_nature/second_q/operators/tensor.py index d7f58d2bf..365fb6fd6 100644 --- a/qiskit_nature/second_q/operators/tensor.py +++ b/qiskit_nature/second_q/operators/tensor.py @@ -596,7 +596,7 @@ def expand(self, other: Tensor) -> Tensor: @classmethod def _tensor(cls, a: Tensor, b: Tensor) -> Tensor: # expand a-matrix into upper left sector - amat = cast(ARRAY_TYPE, a._array) + amat = a._array adim = len(a.shape) aones = np.zeros((2,) * adim) aones[(0,) * adim] = 1.0 @@ -604,7 +604,7 @@ def _tensor(cls, a: Tensor, b: Tensor) -> Tensor: aeinsum = string.ascii_lowercase[:adim] if adim > 0 else "" # expand b-matrix into lower right sector - bmat = cast(ARRAY_TYPE, b._array) + bmat = b._array bdim = len(b.shape) bones = np.zeros((2,) * bdim) bones[(1,) * bdim] = 1.0 diff --git a/qiskit_nature/second_q/operators/vibrational_op.py b/qiskit_nature/second_q/operators/vibrational_op.py index bd156ac11..3736295c5 100644 --- a/qiskit_nature/second_q/operators/vibrational_op.py +++ b/qiskit_nature/second_q/operators/vibrational_op.py @@ -249,7 +249,7 @@ def elementwise_max(a, b): return self.__class__(data, copy=False, num_modals=num_modals) def _validate_keys(self, keys: Collection[str]) -> None: - super()._validate_keys(keys) + super()._validate_keys(keys) # type: ignore[safe-super] num_modals = self._num_modals if self._num_modals is not None else [] for key in keys: diff --git a/qiskit_nature/second_q/problems/vibrational_basis.py b/qiskit_nature/second_q/problems/vibrational_basis.py index 7c485a59c..a6c2fc468 100644 --- a/qiskit_nature/second_q/problems/vibrational_basis.py +++ b/qiskit_nature/second_q/problems/vibrational_basis.py @@ -131,4 +131,4 @@ def map( else: # update the matrix in all permuted locations for i in product(*index_permutations): - yield (coeff, tuple(chain(*i))) + yield (coeff, tuple(chain(*i))) # type: ignore[arg-type] From f125fa44ef1fad2f90bb50e8f69c2f43a5c5f454 Mon Sep 17 00:00:00 2001 From: ftroisi Date: Wed, 15 Jan 2025 15:40:34 +0100 Subject: [PATCH 03/21] Fixed errors in tests due to old package networkx --- requirements-dev.txt | 24 ++++++++++++----------- test/second_q/mappers/test_bksf_mapper.py | 4 ++-- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index 7d6c0b8b1..4e4644605 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,19 +1,21 @@ +black[jupyter]~=24.1 coverage>=4.4.0 +ddt>=1.2.0,!=1.4.0,!=1.4.3 +discover +h5py +jupyter-sphinx matplotlib>=3.3 -black[jupyter]~=24.1 +mypy>=0.991 +mypy-extensions>=0.4.3 +nbsphinx +networkx>=3.0 pylint>=2.15.0 pylatexenc>=1.4 -stestr>=2.0.0 -ddt>=1.2.0,!=1.4.0,!=1.4.3 +qiskit-aer>=0.11.2 +qiskit-algorithms +qiskit_sphinx_theme~=1.16.0 reno>=3.4.0 Sphinx>=5.0 sphinx-design>=0.4.1 sphinxcontrib-spelling!=7.3.1 -jupyter-sphinx -discover -qiskit-aer>=0.11.2 -mypy>=0.991 -mypy-extensions>=0.4.3 -nbsphinx -qiskit_sphinx_theme~=1.16.0 -networkx>=2.2,<2.6 +stestr>=2.0.0 diff --git a/test/second_q/mappers/test_bksf_mapper.py b/test/second_q/mappers/test_bksf_mapper.py index 71aff36c4..a98355d80 100644 --- a/test/second_q/mappers/test_bksf_mapper.py +++ b/test/second_q/mappers/test_bksf_mapper.py @@ -100,7 +100,7 @@ def test_bksf_edge_op_aij(self): def test_h2(self): """Test H2 molecule""" with self.subTest("Excitation edges 1"): - assert np.alltrue( + assert np.all( _bksf_edge_list_fermionic_op( FermionicOp({"+_0 -_1 +_2 -_3": 1}, num_spin_orbitals=4), 4, @@ -109,7 +109,7 @@ def test_h2(self): ) with self.subTest("Excitation edges 2"): - assert np.alltrue( + assert np.all( _bksf_edge_list_fermionic_op( FermionicOp({"+_0 -_1 -_2 +_3": 1}, num_spin_orbitals=4), 4, From 5f14013caf3843b1a2c2f77426689b7639c60878 Mon Sep 17 00:00:00 2001 From: ftroisi Date: Wed, 15 Jan 2025 15:46:57 +0100 Subject: [PATCH 04/21] Copyright and style fixes --- .../algorithms/excited_states_solvers/qeom.py | 4 ++-- .../second_q/circuit/library/ansatzes/ucc.py | 11 +++++++---- .../second_q/circuit/library/ansatzes/uvcc.py | 2 +- .../circuit/library/initial_states/hartree_fock.py | 2 +- .../second_q/circuit/library/initial_states/vscf.py | 2 +- .../second_q/hamiltonians/electronic_energy.py | 2 +- .../second_q/hamiltonians/fermi_hubbard_model.py | 2 +- .../second_q/hamiltonians/lattices/kagome_lattice.py | 2 +- .../second_q/hamiltonians/lattices/square_lattice.py | 2 +- .../hamiltonians/lattices/triangular_lattice.py | 2 +- qiskit_nature/second_q/mappers/bksf.py | 3 ++- .../second_q/mappers/bosonic_logarithmic_mapper.py | 8 +++++--- .../second_q/mappers/bravyi_kitaev_mapper.py | 2 +- qiskit_nature/second_q/mappers/linear_mapper.py | 5 +++-- qiskit_nature/second_q/mappers/logarithmic_mapper.py | 5 +++-- qiskit_nature/second_q/operators/bosonic_op.py | 4 ++-- .../second_q/operators/electronic_integrals.py | 2 +- qiskit_nature/second_q/operators/fermionic_op.py | 4 ++-- qiskit_nature/second_q/operators/majorana_op.py | 4 ++-- qiskit_nature/second_q/operators/spin_op.py | 4 ++-- .../second_q/operators/symmetric_two_body.py | 2 +- qiskit_nature/second_q/operators/tensor.py | 2 +- qiskit_nature/second_q/operators/vibrational_op.py | 4 ++-- qiskit_nature/second_q/problems/harmonic_basis.py | 2 +- qiskit_nature/second_q/problems/vibrational_basis.py | 4 ++-- .../second_q/transformers/active_space_transformer.py | 2 +- .../utils/test_fermionic_excitation_generator.py | 2 +- .../drivers/gaussiand/test_driver_gaussian_forces.py | 2 +- test/second_q/drivers/test_driver.py | 2 +- test/second_q/formats/fcidump/test_fcidump.py | 2 +- test/second_q/formats/fcidump/test_fcidump_dumper.py | 2 +- test/second_q/hamiltonians/lattices/test_lattice.py | 2 +- test/second_q/mappers/test_bksf_mapper.py | 2 +- test/second_q/operators/test_commutators.py | 2 +- 34 files changed, 56 insertions(+), 48 deletions(-) diff --git a/qiskit_nature/second_q/algorithms/excited_states_solvers/qeom.py b/qiskit_nature/second_q/algorithms/excited_states_solvers/qeom.py index 2962605b7..e7147a736 100644 --- a/qiskit_nature/second_q/algorithms/excited_states_solvers/qeom.py +++ b/qiskit_nature/second_q/algorithms/excited_states_solvers/qeom.py @@ -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 @@ -930,7 +930,7 @@ def _evaluate_observables_excited_states( for indice in indices_diag_as_list: aux_operators_eigenvalues[indice] = {} # type: ignore[index] for aux_name in untap_aux_ops.keys(): - aux_operators_eigenvalues[indice][aux_name] = aux_measurements.get( # type: ignore + aux_operators_eigenvalues[indice][aux_name] = aux_measurements.get( # type: ignore (aux_name, indice[0], indice[1]), (0.0, {}) ) diff --git a/qiskit_nature/second_q/circuit/library/ansatzes/ucc.py b/qiskit_nature/second_q/circuit/library/ansatzes/ucc.py index e05a8d515..b64dff8c9 100644 --- a/qiskit_nature/second_q/circuit/library/ansatzes/ucc.py +++ b/qiskit_nature/second_q/circuit/library/ansatzes/ucc.py @@ -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 @@ -459,8 +459,9 @@ def _get_excitation_generators(self) -> list[Callable]: 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, + "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), } @@ -483,7 +484,9 @@ def _get_excitation_generators(self) -> list[Callable]: elif isinstance(self.excitations, list): for excitation in self.excitations: generators.append( - partial(generate_fermionic_excitations, num_excitations=excitation, **extra_kwargs) + partial( + generate_fermionic_excitations, num_excitations=excitation, **extra_kwargs + ) ) elif callable(self.excitations): generators = [self.excitations] diff --git a/qiskit_nature/second_q/circuit/library/ansatzes/uvcc.py b/qiskit_nature/second_q/circuit/library/ansatzes/uvcc.py index e6dd802ce..96d8d1a6e 100644 --- a/qiskit_nature/second_q/circuit/library/ansatzes/uvcc.py +++ b/qiskit_nature/second_q/circuit/library/ansatzes/uvcc.py @@ -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 diff --git a/qiskit_nature/second_q/circuit/library/initial_states/hartree_fock.py b/qiskit_nature/second_q/circuit/library/initial_states/hartree_fock.py index afc5bbde9..9bdf2ba11 100644 --- a/qiskit_nature/second_q/circuit/library/initial_states/hartree_fock.py +++ b/qiskit_nature/second_q/circuit/library/initial_states/hartree_fock.py @@ -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 diff --git a/qiskit_nature/second_q/circuit/library/initial_states/vscf.py b/qiskit_nature/second_q/circuit/library/initial_states/vscf.py index 30a6137f5..ea6d36544 100644 --- a/qiskit_nature/second_q/circuit/library/initial_states/vscf.py +++ b/qiskit_nature/second_q/circuit/library/initial_states/vscf.py @@ -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 diff --git a/qiskit_nature/second_q/hamiltonians/electronic_energy.py b/qiskit_nature/second_q/hamiltonians/electronic_energy.py index c28f9c3c5..814672cc6 100644 --- a/qiskit_nature/second_q/hamiltonians/electronic_energy.py +++ b/qiskit_nature/second_q/hamiltonians/electronic_energy.py @@ -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 diff --git a/qiskit_nature/second_q/hamiltonians/fermi_hubbard_model.py b/qiskit_nature/second_q/hamiltonians/fermi_hubbard_model.py index dbf74eaec..b997baca2 100644 --- a/qiskit_nature/second_q/hamiltonians/fermi_hubbard_model.py +++ b/qiskit_nature/second_q/hamiltonians/fermi_hubbard_model.py @@ -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 diff --git a/qiskit_nature/second_q/hamiltonians/lattices/kagome_lattice.py b/qiskit_nature/second_q/hamiltonians/lattices/kagome_lattice.py index a1ab2eb23..023d872c4 100644 --- a/qiskit_nature/second_q/hamiltonians/lattices/kagome_lattice.py +++ b/qiskit_nature/second_q/hamiltonians/lattices/kagome_lattice.py @@ -1,6 +1,6 @@ # This code is part of a Qiskit project. # -# (C) Copyright IBM 2023, 2024. +# (C) Copyright IBM 2023, 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 diff --git a/qiskit_nature/second_q/hamiltonians/lattices/square_lattice.py b/qiskit_nature/second_q/hamiltonians/lattices/square_lattice.py index ee54f7035..6ab08b956 100644 --- a/qiskit_nature/second_q/hamiltonians/lattices/square_lattice.py +++ b/qiskit_nature/second_q/hamiltonians/lattices/square_lattice.py @@ -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 diff --git a/qiskit_nature/second_q/hamiltonians/lattices/triangular_lattice.py b/qiskit_nature/second_q/hamiltonians/lattices/triangular_lattice.py index 5c5c8683a..de544ccc8 100644 --- a/qiskit_nature/second_q/hamiltonians/lattices/triangular_lattice.py +++ b/qiskit_nature/second_q/hamiltonians/lattices/triangular_lattice.py @@ -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 diff --git a/qiskit_nature/second_q/mappers/bksf.py b/qiskit_nature/second_q/mappers/bksf.py index 694a23d0c..e8df7f7a4 100644 --- a/qiskit_nature/second_q/mappers/bksf.py +++ b/qiskit_nature/second_q/mappers/bksf.py @@ -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 @@ -304,6 +304,7 @@ def _double_excitation( final_coeff = 0.125 return (final_coeff * h2_pqrs) * qubit_op + # pylint: disable=invalid-name, disable=too-many-positional-arguments def _number_excitation( edge_list: np.ndarray, p: int, q: int, r: int, s: int, h2_pqrs: float diff --git a/qiskit_nature/second_q/mappers/bosonic_logarithmic_mapper.py b/qiskit_nature/second_q/mappers/bosonic_logarithmic_mapper.py index 631a596a6..083e2d743 100644 --- a/qiskit_nature/second_q/mappers/bosonic_logarithmic_mapper.py +++ b/qiskit_nature/second_q/mappers/bosonic_logarithmic_mapper.py @@ -1,6 +1,6 @@ # This code is part of a Qiskit project. # -# (C) Copyright IBM 2024. +# (C) Copyright IBM 2024, 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 @@ -101,8 +101,10 @@ def __init__(self, max_occupation: int) -> None: max_calculated_occupation = 2**self.number_of_qubits_per_mode - 1 if max_occupation != max_calculated_occupation: # Use of a message variable to suppress pylint warning logging-not-lazy - warning_message = f"The user requested a max occupation of {max_occupation}, " +\ - f"but the actual max occupation is {max_calculated_occupation}." + warning_message = ( + f"The user requested a max occupation of {max_occupation}, " + + f"but the actual max occupation is {max_calculated_occupation}." + ) logger.warning(warning_message) super().__init__(max_calculated_occupation) diff --git a/qiskit_nature/second_q/mappers/bravyi_kitaev_mapper.py b/qiskit_nature/second_q/mappers/bravyi_kitaev_mapper.py index e75eea1c3..8bbc984db 100644 --- a/qiskit_nature/second_q/mappers/bravyi_kitaev_mapper.py +++ b/qiskit_nature/second_q/mappers/bravyi_kitaev_mapper.py @@ -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 diff --git a/qiskit_nature/second_q/mappers/linear_mapper.py b/qiskit_nature/second_q/mappers/linear_mapper.py index 6913801ff..2e6b36a71 100644 --- a/qiskit_nature/second_q/mappers/linear_mapper.py +++ b/qiskit_nature/second_q/mappers/linear_mapper.py @@ -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 @@ -54,7 +54,8 @@ def _map_single( operatorlist = [mat[i] if i in mat else identity for i in range(register_length)] # Now, we can tensor all operators in this list qubit_ops_list.append( - coeff * reduce(operator.xor, reversed(operatorlist))) # type: ignore[operator] + coeff * reduce(operator.xor, reversed(operatorlist)) # type: ignore[operator] + ) qubit_op = reduce(operator.add, qubit_ops_list) return qubit_op.simplify() diff --git a/qiskit_nature/second_q/mappers/logarithmic_mapper.py b/qiskit_nature/second_q/mappers/logarithmic_mapper.py index 61eb2cff9..3950e0e77 100644 --- a/qiskit_nature/second_q/mappers/logarithmic_mapper.py +++ b/qiskit_nature/second_q/mappers/logarithmic_mapper.py @@ -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 @@ -103,7 +103,8 @@ def _map_single( operatorlist = [mat[i] if i in mat else identity for i in range(register_length)] # Now, we can tensor all operators in this list qubit_ops_list.append( - coeff * reduce(operator.xor, reversed(operatorlist))) # type: ignore[operator] + coeff * reduce(operator.xor, reversed(operatorlist)) # type: ignore[operator] + ) qubit_op = reduce(operator.add, qubit_ops_list) diff --git a/qiskit_nature/second_q/operators/bosonic_op.py b/qiskit_nature/second_q/operators/bosonic_op.py index 5eb2b3f37..7391ffa2e 100644 --- a/qiskit_nature/second_q/operators/bosonic_op.py +++ b/qiskit_nature/second_q/operators/bosonic_op.py @@ -1,6 +1,6 @@ # This code is part of a Qiskit project. # -# (C) Copyright IBM 2023, 2024. +# (C) Copyright IBM 2023, 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 @@ -195,7 +195,7 @@ def _new_instance( return self.__class__(data, copy=False, num_modes=num_so) def _validate_keys(self, keys: Collection[str]) -> None: - super()._validate_keys(keys) # type: ignore[safe-super] + super()._validate_keys(keys) # type: ignore[safe-super] num_so = self.num_modes diff --git a/qiskit_nature/second_q/operators/electronic_integrals.py b/qiskit_nature/second_q/operators/electronic_integrals.py index c6ec573c4..3a77203ab 100644 --- a/qiskit_nature/second_q/operators/electronic_integrals.py +++ b/qiskit_nature/second_q/operators/electronic_integrals.py @@ -1,6 +1,6 @@ # This code is part of a Qiskit project. # -# (C) Copyright IBM 2022, 2023. +# (C) Copyright IBM 2022, 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 diff --git a/qiskit_nature/second_q/operators/fermionic_op.py b/qiskit_nature/second_q/operators/fermionic_op.py index 8aba98556..a49a8617e 100644 --- a/qiskit_nature/second_q/operators/fermionic_op.py +++ b/qiskit_nature/second_q/operators/fermionic_op.py @@ -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 @@ -196,7 +196,7 @@ def _new_instance( return self.__class__(data, copy=False, num_spin_orbitals=num_so) def _validate_keys(self, keys: Collection[str]) -> None: - super()._validate_keys(keys) # type: ignore[safe-super] + super()._validate_keys(keys) # type: ignore[safe-super] num_so = self.num_spin_orbitals diff --git a/qiskit_nature/second_q/operators/majorana_op.py b/qiskit_nature/second_q/operators/majorana_op.py index cbb83eb0b..398b30ed0 100644 --- a/qiskit_nature/second_q/operators/majorana_op.py +++ b/qiskit_nature/second_q/operators/majorana_op.py @@ -1,6 +1,6 @@ # This code is part of a Qiskit project. # -# (C) Copyright IBM 2023, 2024. +# (C) Copyright IBM 2023, 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 @@ -250,7 +250,7 @@ def _new_instance( return self.__class__(data, copy=False, num_modes=num_modes) def _validate_keys(self, keys: Collection[str]) -> None: - super()._validate_keys(keys) # type: ignore[safe-super] + super()._validate_keys(keys) # type: ignore[safe-super] num_modes = self.num_modes diff --git a/qiskit_nature/second_q/operators/spin_op.py b/qiskit_nature/second_q/operators/spin_op.py index f667cf04d..b6c4251cf 100644 --- a/qiskit_nature/second_q/operators/spin_op.py +++ b/qiskit_nature/second_q/operators/spin_op.py @@ -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 @@ -254,7 +254,7 @@ def _new_instance(self, data: Mapping[str, _TCoeff], *, other: SpinOp | None = N return self.__class__(data, copy=False, num_spins=num_s) def _validate_keys(self, keys: Collection[str]) -> None: - super()._validate_keys(keys) # type: ignore[safe-super] + super()._validate_keys(keys) # type: ignore[safe-super] num_s = self.num_spins diff --git a/qiskit_nature/second_q/operators/symmetric_two_body.py b/qiskit_nature/second_q/operators/symmetric_two_body.py index 14bbbe63f..1f1675f4e 100644 --- a/qiskit_nature/second_q/operators/symmetric_two_body.py +++ b/qiskit_nature/second_q/operators/symmetric_two_body.py @@ -1,6 +1,6 @@ # This code is part of a Qiskit project. # -# (C) Copyright IBM 2022, 2023. +# (C) Copyright IBM 2022, 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 diff --git a/qiskit_nature/second_q/operators/tensor.py b/qiskit_nature/second_q/operators/tensor.py index 365fb6fd6..d1b5309ba 100644 --- a/qiskit_nature/second_q/operators/tensor.py +++ b/qiskit_nature/second_q/operators/tensor.py @@ -1,6 +1,6 @@ # This code is part of a Qiskit project. # -# (C) Copyright IBM 2022, 2023. +# (C) Copyright IBM 2022, 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 diff --git a/qiskit_nature/second_q/operators/vibrational_op.py b/qiskit_nature/second_q/operators/vibrational_op.py index 3736295c5..11385df84 100644 --- a/qiskit_nature/second_q/operators/vibrational_op.py +++ b/qiskit_nature/second_q/operators/vibrational_op.py @@ -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 @@ -249,7 +249,7 @@ def elementwise_max(a, b): return self.__class__(data, copy=False, num_modals=num_modals) def _validate_keys(self, keys: Collection[str]) -> None: - super()._validate_keys(keys) # type: ignore[safe-super] + super()._validate_keys(keys) # type: ignore[safe-super] num_modals = self._num_modals if self._num_modals is not None else [] for key in keys: diff --git a/qiskit_nature/second_q/problems/harmonic_basis.py b/qiskit_nature/second_q/problems/harmonic_basis.py index 081a4b753..fc62a790e 100644 --- a/qiskit_nature/second_q/problems/harmonic_basis.py +++ b/qiskit_nature/second_q/problems/harmonic_basis.py @@ -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 diff --git a/qiskit_nature/second_q/problems/vibrational_basis.py b/qiskit_nature/second_q/problems/vibrational_basis.py index a6c2fc468..3cce7b53c 100644 --- a/qiskit_nature/second_q/problems/vibrational_basis.py +++ b/qiskit_nature/second_q/problems/vibrational_basis.py @@ -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 @@ -131,4 +131,4 @@ def map( else: # update the matrix in all permuted locations for i in product(*index_permutations): - yield (coeff, tuple(chain(*i))) # type: ignore[arg-type] + yield (coeff, tuple(chain(*i))) # type: ignore[arg-type] diff --git a/qiskit_nature/second_q/transformers/active_space_transformer.py b/qiskit_nature/second_q/transformers/active_space_transformer.py index 90458a636..1c7ca63e3 100644 --- a/qiskit_nature/second_q/transformers/active_space_transformer.py +++ b/qiskit_nature/second_q/transformers/active_space_transformer.py @@ -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 diff --git a/test/second_q/circuit/library/ansatzes/utils/test_fermionic_excitation_generator.py b/test/second_q/circuit/library/ansatzes/utils/test_fermionic_excitation_generator.py index f6df0985c..cfedc4fb7 100644 --- a/test/second_q/circuit/library/ansatzes/utils/test_fermionic_excitation_generator.py +++ b/test/second_q/circuit/library/ansatzes/utils/test_fermionic_excitation_generator.py @@ -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 diff --git a/test/second_q/drivers/gaussiand/test_driver_gaussian_forces.py b/test/second_q/drivers/gaussiand/test_driver_gaussian_forces.py index 3c27ecde6..7160d6952 100644 --- a/test/second_q/drivers/gaussiand/test_driver_gaussian_forces.py +++ b/test/second_q/drivers/gaussiand/test_driver_gaussian_forces.py @@ -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 diff --git a/test/second_q/drivers/test_driver.py b/test/second_q/drivers/test_driver.py index fb1151fcc..74b6a2dac 100644 --- a/test/second_q/drivers/test_driver.py +++ b/test/second_q/drivers/test_driver.py @@ -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 diff --git a/test/second_q/formats/fcidump/test_fcidump.py b/test/second_q/formats/fcidump/test_fcidump.py index 24e8877fd..f627f2b2b 100644 --- a/test/second_q/formats/fcidump/test_fcidump.py +++ b/test/second_q/formats/fcidump/test_fcidump.py @@ -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 diff --git a/test/second_q/formats/fcidump/test_fcidump_dumper.py b/test/second_q/formats/fcidump/test_fcidump_dumper.py index 05e199769..49433683b 100644 --- a/test/second_q/formats/fcidump/test_fcidump_dumper.py +++ b/test/second_q/formats/fcidump/test_fcidump_dumper.py @@ -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 diff --git a/test/second_q/hamiltonians/lattices/test_lattice.py b/test/second_q/hamiltonians/lattices/test_lattice.py index 0947f505e..d47d8c121 100644 --- a/test/second_q/hamiltonians/lattices/test_lattice.py +++ b/test/second_q/hamiltonians/lattices/test_lattice.py @@ -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 diff --git a/test/second_q/mappers/test_bksf_mapper.py b/test/second_q/mappers/test_bksf_mapper.py index a98355d80..eb9dafa60 100644 --- a/test/second_q/mappers/test_bksf_mapper.py +++ b/test/second_q/mappers/test_bksf_mapper.py @@ -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 diff --git a/test/second_q/operators/test_commutators.py b/test/second_q/operators/test_commutators.py index c45b51710..b890781d1 100644 --- a/test/second_q/operators/test_commutators.py +++ b/test/second_q/operators/test_commutators.py @@ -1,6 +1,6 @@ # This code is part of a Qiskit project. # -# (C) Copyright IBM 2022, 2023. +# (C) Copyright IBM 2022, 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 From 588a0ed849e4939921670459cee7ad9e28ce519d Mon Sep 17 00:00:00 2001 From: ftroisi Date: Wed, 15 Jan 2025 15:49:26 +0100 Subject: [PATCH 05/21] Updated contribution guidelines --- CONTRIBUTING.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 178569e67..b97987299 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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. From 4fb62e5c5c178cc5cd9516b1212dfc54a4e3c055 Mon Sep 17 00:00:00 2001 From: ftroisi Date: Wed, 15 Jan 2025 16:11:00 +0100 Subject: [PATCH 06/21] Removed unused type ignore comment --- .../second_q/algorithms/excited_states_solvers/qeom.py | 8 ++++---- qiskit_nature/second_q/problems/vibrational_basis.py | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/qiskit_nature/second_q/algorithms/excited_states_solvers/qeom.py b/qiskit_nature/second_q/algorithms/excited_states_solvers/qeom.py index e7147a736..4a166de24 100644 --- a/qiskit_nature/second_q/algorithms/excited_states_solvers/qeom.py +++ b/qiskit_nature/second_q/algorithms/excited_states_solvers/qeom.py @@ -928,9 +928,9 @@ def _evaluate_observables_excited_states( indices_diag = np.diag_indices(size + 1) indices_diag_as_list = list(zip(indices_diag[0], indices_diag[1])) for indice in indices_diag_as_list: - aux_operators_eigenvalues[indice] = {} # type: ignore[index] + aux_operators_eigenvalues[indice] = {} for aux_name in untap_aux_ops.keys(): - aux_operators_eigenvalues[indice][aux_name] = aux_measurements.get( # type: ignore + aux_operators_eigenvalues[indice][aux_name] = aux_measurements.get( (aux_name, indice[0], indice[1]), (0.0, {}) ) @@ -938,9 +938,9 @@ def _evaluate_observables_excited_states( indices_offdiag = np.triu_indices(size + 1, k=1) indices_offdiag_as_list = list(zip(indices_offdiag[0], indices_offdiag[1])) for indice in indices_offdiag_as_list: - transition_amplitudes[indice] = {} # type: ignore[index] + transition_amplitudes[indice] = {} for aux_name in untap_aux_ops.keys(): - transition_amplitudes[indice][aux_name] = aux_measurements.get( # type: ignore + transition_amplitudes[indice][aux_name] = aux_measurements.get( (aux_name, indice[0], indice[1]), (0.0, {}) ) diff --git a/qiskit_nature/second_q/problems/vibrational_basis.py b/qiskit_nature/second_q/problems/vibrational_basis.py index 3cce7b53c..fea57cfbe 100644 --- a/qiskit_nature/second_q/problems/vibrational_basis.py +++ b/qiskit_nature/second_q/problems/vibrational_basis.py @@ -131,4 +131,4 @@ def map( else: # update the matrix in all permuted locations for i in product(*index_permutations): - yield (coeff, tuple(chain(*i))) # type: ignore[arg-type] + yield (coeff, tuple(chain(*i))) From 76ea0163cc76648bd736ad9710dc8fce53c086d8 Mon Sep 17 00:00:00 2001 From: ftroisi Date: Wed, 15 Jan 2025 22:40:01 +0100 Subject: [PATCH 07/21] Added transpiler to pylintdict --- .pylintdict | 1 + 1 file changed, 1 insertion(+) diff --git a/.pylintdict b/.pylintdict index 608370663..57370b46a 100644 --- a/.pylintdict +++ b/.pylintdict @@ -598,6 +598,7 @@ tran translational transpilation transpile +transpiler trotterization tryptophan tuple From af05d3ad82691f6e547c7d12f674f23a14e70da1 Mon Sep 17 00:00:00 2001 From: ftroisi Date: Mon, 20 Jan 2025 16:58:54 +0100 Subject: [PATCH 08/21] debug macos pipeline --- .github/workflows/main.yml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 0954f9e3e..c36ffdd7b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -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 @@ -149,7 +149,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest] - python-version: [3.8, 3.9, '3.10', 3.11, 3.12] + python-version: [3.8, 3.9, 3.10, 3.11, 3.12] include: - os: macos-latest python-version: 3.8 @@ -171,11 +171,14 @@ jobs: requirements-dev.txt - name: Create conda environment run: | + echo user $USER + echo conda_dir $CONDA + which conda if [ "${{ matrix.os }}" == "macos-latest" ]; then sudo chown -R $USER: "$CONDA" fi source "$CONDA/etc/profile.d/conda.sh" - if [ "${{ matrix.python-version }}" >= "3.11" ]; then + if [ "${{ matrix.python-version }}" >= "3.9" ]; then conda create -y -n psi4env python=${{ matrix.python-version }} -c conda-forge else conda create -y -n psi4env python=${{ matrix.python-version }} From e920b5b277d0419cfbcc13c48cc01653586fd56b Mon Sep 17 00:00:00 2001 From: ftroisi Date: Tue, 21 Jan 2025 22:18:54 +0100 Subject: [PATCH 09/21] Test using macos 13 --- .github/workflows/main.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index c36ffdd7b..ff97c3de6 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -149,11 +149,11 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest] - python-version: [3.8, 3.9, 3.10, 3.11, 3.12] + python-version: [3.8, 3.9, '3.10', 3.11, 3.12] include: - - os: macos-latest + - os: macos-13 python-version: 3.8 - - os: macos-latest + - os: macos-13 python-version: 3.12 - os: windows-latest python-version: 3.8 @@ -172,9 +172,9 @@ jobs: - name: Create conda environment run: | echo user $USER - echo conda_dir $CONDA + echo conda_dir $CONDA output_complete which conda - if [ "${{ matrix.os }}" == "macos-latest" ]; then + if [ "${{ matrix.os }}" == "macos-13" ]; then sudo chown -R $USER: "$CONDA" fi source "$CONDA/etc/profile.d/conda.sh" @@ -386,11 +386,11 @@ jobs: path: /tmp/u312 - uses: actions/download-artifact@v4 with: - name: macos-latest-3.8 + name: macos-13-3.8 path: /tmp/m38 - uses: actions/download-artifact@v4 with: - name: macos-latest-3.12 + name: macos-13-3.12 path: /tmp/m312 - uses: actions/download-artifact@v4 with: From f9d86fc65af7f1e05c8a0ef95e2e4ae485321fb2 Mon Sep 17 00:00:00 2001 From: ftroisi Date: Tue, 21 Jan 2025 22:20:54 +0100 Subject: [PATCH 10/21] Test with macos12 --- .github/workflows/main.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index ff97c3de6..b13226a64 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -151,9 +151,9 @@ jobs: os: [ubuntu-latest] python-version: [3.8, 3.9, '3.10', 3.11, 3.12] include: - - os: macos-13 + - os: macos-12 python-version: 3.8 - - os: macos-13 + - os: macos-12 python-version: 3.12 - os: windows-latest python-version: 3.8 @@ -174,7 +174,7 @@ jobs: echo user $USER echo conda_dir $CONDA output_complete which conda - if [ "${{ matrix.os }}" == "macos-13" ]; then + if [ "${{ matrix.os }}" == "macos-12" ]; then sudo chown -R $USER: "$CONDA" fi source "$CONDA/etc/profile.d/conda.sh" @@ -386,11 +386,11 @@ jobs: path: /tmp/u312 - uses: actions/download-artifact@v4 with: - name: macos-13-3.8 + name: macos-12-3.8 path: /tmp/m38 - uses: actions/download-artifact@v4 with: - name: macos-13-3.12 + name: macos-12-3.12 path: /tmp/m312 - uses: actions/download-artifact@v4 with: From 1be947dd4b856fed1217df70be188f8239f4cb95 Mon Sep 17 00:00:00 2001 From: ftroisi Date: Tue, 21 Jan 2025 22:26:58 +0100 Subject: [PATCH 11/21] Test setup conda --- .github/workflows/main.yml | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index b13226a64..e8687ab24 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -151,9 +151,9 @@ jobs: os: [ubuntu-latest] python-version: [3.8, 3.9, '3.10', 3.11, 3.12] include: - - os: macos-12 + - os: macos-latest python-version: 3.8 - - os: macos-12 + - os: macos-latest python-version: 3.12 - os: windows-latest python-version: 3.8 @@ -169,12 +169,18 @@ 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: | echo user $USER echo conda_dir $CONDA output_complete which conda - if [ "${{ matrix.os }}" == "macos-12" ]; then + if [ "${{ matrix.os }}" == "macos-latest" ]; then sudo chown -R $USER: "$CONDA" fi source "$CONDA/etc/profile.d/conda.sh" @@ -386,11 +392,11 @@ jobs: path: /tmp/u312 - uses: actions/download-artifact@v4 with: - name: macos-12-3.8 + name: macos-latest-3.8 path: /tmp/m38 - uses: actions/download-artifact@v4 with: - name: macos-12-3.12 + name: macos-latest-3.12 path: /tmp/m312 - uses: actions/download-artifact@v4 with: From cd1f41e865fe285856c4e3ef04f759c1de374cef Mon Sep 17 00:00:00 2001 From: ftroisi Date: Tue, 21 Jan 2025 22:43:12 +0100 Subject: [PATCH 12/21] Dropped python 3.9 support --- .github/actions/run-tests/action.yml | 2 +- .github/workflows/deploy-code.yml | 2 +- .github/workflows/deploy-docs.yml | 2 +- .github/workflows/main.yml | 40 ++++++++++------------------ .mergify.yml | 4 +-- setup.py | 3 +-- 6 files changed, 20 insertions(+), 33 deletions(-) diff --git a/.github/actions/run-tests/action.yml b/.github/actions/run-tests/action.yml index 27c0ab967..024881103 100644 --- a/.github/actions/run-tests/action.yml +++ b/.github/actions/run-tests/action.yml @@ -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) diff --git a/.github/workflows/deploy-code.yml b/.github/workflows/deploy-code.yml index ad80409ba..8ad17587e 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 14e64ba62..cc8a537c5 100644 --- a/.github/workflows/deploy-docs.yml +++ b/.github/workflows/deploy-docs.yml @@ -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: diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index e8687ab24..48cc03dcb 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: @@ -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: @@ -177,14 +177,11 @@ jobs: if: ${{ matrix.os == 'macos-latest' }} - name: Create conda environment run: | - echo user $USER - echo conda_dir $CONDA output_complete - which conda if [ "${{ matrix.os }}" == "macos-latest" ]; then sudo chown -R $USER: "$CONDA" fi source "$CONDA/etc/profile.d/conda.sh" - if [ "${{ matrix.python-version }}" >= "3.9" ]; then + if [ "${{ matrix.python-version }}" >= "3.11" ]; then conda create -y -n psi4env python=${{ matrix.python-version }} -c conda-forge else conda create -y -n psi4env python=${{ matrix.python-version }} @@ -204,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" @@ -254,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: @@ -283,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: @@ -350,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 @@ -392,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 diff --git a/.mergify.yml b/.mergify.yml index d9a318886..ca27e5964 100644 --- a/.mergify.yml +++ b/.mergify.yml @@ -1,12 +1,12 @@ queue_rules: - name: automerge conditions: - - check-success=Deprecation_Messages_and_Coverage (3.8) + - check-success=Deprecation_Messages_and_Coverage (3.9) 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 diff --git a/setup.py b/setup.py index 33f36a9eb..8a9e469cd 100644 --- a/setup.py +++ b/setup.py @@ -62,7 +62,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", @@ -73,7 +72,7 @@ packages=setuptools.find_packages(include=["qiskit_nature", "qiskit_nature.*"]), install_requires=REQUIREMENTS, include_package_data=True, - python_requires=">=3.8", + python_requires=">=3.9", extras_require={ "pyscf": ["pyscf; sys_platform != 'win32'"], "mpl": ["matplotlib>=3.3"], From 87d1dd670b977d1c004f610e5c508723b963e12d Mon Sep 17 00:00:00 2001 From: ftroisi Date: Tue, 21 Jan 2025 22:50:04 +0100 Subject: [PATCH 13/21] Copyright fix --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 8a9e469cd..22df4999f 100644 --- a/setup.py +++ b/setup.py @@ -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 From b26599ca827c6398034c52df894348b3962598b3 Mon Sep 17 00:00:00 2001 From: ftroisi Date: Wed, 22 Jan 2025 14:31:39 +0100 Subject: [PATCH 14/21] Added debug for psi4 --- qiskit_nature/second_q/drivers/psi4d/psi4driver.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/qiskit_nature/second_q/drivers/psi4d/psi4driver.py b/qiskit_nature/second_q/drivers/psi4d/psi4driver.py index 9971ea342..b8d2c28b1 100644 --- a/qiskit_nature/second_q/drivers/psi4d/psi4driver.py +++ b/qiskit_nature/second_q/drivers/psi4d/psi4driver.py @@ -239,11 +239,14 @@ def _run_psi4(input_file, output_file): if process.returncode != 0: errmsg = "" + print("stdout", stdout) + print("stderr", process.stderr) if stdout is not None: lines = stdout.splitlines() for line in lines: logger.error(line) errmsg += line + "\n" + print(lines) raise QiskitNatureError( - f"{_optionals.PSI4} process return code {process.returncode}\n{errmsg}" + f"{_optionals.PSI4} process return code {process.returncode}: {errmsg}" ) From c6e8aae03d1cdda1f3b5aa4929bee721969ab5ac Mon Sep 17 00:00:00 2001 From: ftroisi Date: Wed, 22 Jan 2025 14:49:12 +0100 Subject: [PATCH 15/21] install libecpint for psi4 on ubuntu for python 3.9 and 3.10 --- .github/actions/install-psi4/action.yml | 6 +++++- qiskit_nature/second_q/drivers/psi4d/psi4driver.py | 5 +---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/.github/actions/install-psi4/action.yml b/.github/actions/install-psi4/action.yml index 795e77413..1d40ab450 100644 --- a/.github/actions/install-psi4/action.yml +++ b/.github/actions/install-psi4/action.yml @@ -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 @@ -25,6 +25,10 @@ runs: - run : | source "$CONDA/etc/profile.d/conda.sh" conda activate psi4env + if [ "${{ inputs.os }}" == "ubuntu-latest" && "${{ inputs.python-version }}" < "3.11" ]; 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 diff --git a/qiskit_nature/second_q/drivers/psi4d/psi4driver.py b/qiskit_nature/second_q/drivers/psi4d/psi4driver.py index b8d2c28b1..54b6af4f2 100644 --- a/qiskit_nature/second_q/drivers/psi4d/psi4driver.py +++ b/qiskit_nature/second_q/drivers/psi4d/psi4driver.py @@ -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 @@ -239,14 +239,11 @@ def _run_psi4(input_file, output_file): if process.returncode != 0: errmsg = "" - print("stdout", stdout) - print("stderr", process.stderr) if stdout is not None: lines = stdout.splitlines() for line in lines: logger.error(line) errmsg += line + "\n" - print(lines) raise QiskitNatureError( f"{_optionals.PSI4} process return code {process.returncode}: {errmsg}" ) From 1918734a5ee0fe38e75edf1c0bea9a1f65a50fde Mon Sep 17 00:00:00 2001 From: ftroisi Date: Wed, 22 Jan 2025 15:02:42 +0100 Subject: [PATCH 16/21] Sintax error fix --- .github/actions/install-psi4/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/install-psi4/action.yml b/.github/actions/install-psi4/action.yml index 1d40ab450..091e17291 100644 --- a/.github/actions/install-psi4/action.yml +++ b/.github/actions/install-psi4/action.yml @@ -25,7 +25,7 @@ runs: - run : | source "$CONDA/etc/profile.d/conda.sh" conda activate psi4env - if [ "${{ inputs.os }}" == "ubuntu-latest" && "${{ inputs.python-version }}" < "3.11" ]; then + if [[ "${{ inputs.os }}" == "ubuntu-latest" && "${{ inputs.python-version }}" < "3.11" ]]; then echo "installs libecpint" conda install -c conda-forge libecpint fi From 61b46e1caa5703b82a787f44f43001d1b9bfe0d5 Mon Sep 17 00:00:00 2001 From: ftroisi Date: Wed, 22 Jan 2025 15:49:30 +0100 Subject: [PATCH 17/21] Fixed logic for libecpint installation --- .github/actions/install-psi4/action.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/actions/install-psi4/action.yml b/.github/actions/install-psi4/action.yml index 091e17291..837355758 100644 --- a/.github/actions/install-psi4/action.yml +++ b/.github/actions/install-psi4/action.yml @@ -25,7 +25,8 @@ runs: - run : | source "$CONDA/etc/profile.d/conda.sh" conda activate psi4env - if [[ "${{ inputs.os }}" == "ubuntu-latest" && "${{ inputs.python-version }}" < "3.11" ]]; then + 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 From 9fd0d5c907b36e24d789e3d6b7eeeeb2bde18c10 Mon Sep 17 00:00:00 2001 From: ftroisi Date: Wed, 22 Jan 2025 17:18:56 +0100 Subject: [PATCH 18/21] Removed python 3.8 folders --- .github/workflows/main.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 48cc03dcb..91d6e4110 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -399,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: From 2916c360b10d777241eec5887e1e50842b22178b Mon Sep 17 00:00:00 2001 From: ftroisi Date: Wed, 22 Jan 2025 17:19:10 +0100 Subject: [PATCH 19/21] Fixed mergify yml --- .mergify.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.mergify.yml b/.mergify.yml index ca27e5964..cf2784be7 100644 --- a/.mergify.yml +++ b/.mergify.yml @@ -1,7 +1,8 @@ queue_rules: - name: automerge - conditions: + queue_conditions: - check-success=Deprecation_Messages_and_Coverage (3.9) + merge_method: squash pull_request_rules: - name: automatic merge on CI success and review @@ -13,7 +14,6 @@ pull_request_rules: actions: queue: name: automerge - method: squash - name: backport conditions: - label=stable backport potential From 938887c77773636f55ec826091e2be0b09b0ca0c Mon Sep 17 00:00:00 2001 From: ftroisi Date: Thu, 23 Jan 2025 15:47:41 +0100 Subject: [PATCH 20/21] Added release note for python 3.8 drop --- releasenotes/notes/drop_python_3_8-fd6fe0e7f9fbff49.yaml | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 releasenotes/notes/drop_python_3_8-fd6fe0e7f9fbff49.yaml diff --git a/releasenotes/notes/drop_python_3_8-fd6fe0e7f9fbff49.yaml b/releasenotes/notes/drop_python_3_8-fd6fe0e7f9fbff49.yaml new file mode 100644 index 000000000..edf6ae1fb --- /dev/null +++ b/releasenotes/notes/drop_python_3_8-fd6fe0e7f9fbff49.yaml @@ -0,0 +1,5 @@ +--- +upgrade: + - | + Support for running with Python 3.8 has been removed. To run Nature you need + a minimum Python version of 3.9. From 9d69f988c33118ad94f8fec7c9fb2c327ddcdafb Mon Sep 17 00:00:00 2001 From: ftroisi Date: Thu, 23 Jan 2025 15:48:14 +0100 Subject: [PATCH 21/21] Removed unnecessary package from requirements-decv --- requirements-dev.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index 4e4644605..af6dba1fb 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -8,7 +8,6 @@ matplotlib>=3.3 mypy>=0.991 mypy-extensions>=0.4.3 nbsphinx -networkx>=3.0 pylint>=2.15.0 pylatexenc>=1.4 qiskit-aer>=0.11.2