Skip to content

Commit

Permalink
fix: typing compatibility with rustworkx 0.13.0 (#1202)
Browse files Browse the repository at this point in the history
* fix: typing compatibility with rustworkx 0.13.0

* fix: update copyright

* hotfix: avoid mypy warning about unused ignores

This change should be reverted once rustworkx 0.13.1 has fixed this
typing incompatibility.
  • Loading branch information
mrossinek authored Jun 8, 2023
1 parent bf3ce82 commit 08df681
Show file tree
Hide file tree
Showing 13 changed files with 32 additions and 24 deletions.
9 changes: 8 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,14 @@ jobs:
source "$CONDA/etc/profile.d/conda.sh"
conda activate psi4env
make mypy
if: ${{ !cancelled() }}
if: ${{ !cancelled() && matrix.python-version != 3.7 }}
shell: bash
- name: Run mypy on Python 3.7
run: |
source "$CONDA/etc/profile.d/conda.sh"
conda activate psi4env
python -m mypy --no-warn-unused-ignores qiskit_nature test tools
if: ${{ !cancelled() && matrix.python-version == 3.7 }}
shell: bash
- name: Stestr Cache
uses: actions/cache@v3
Expand Down
1 change: 1 addition & 0 deletions constraints.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
numpy>=1.20.0
ipython<8.13;python_version<'3.9'
rustworkx!=0.13.0;python_version<'3.8'
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def __init__(

self._boundary_condition = boundary_condition

graph = PyGraph(multigraph=False)
graph: PyGraph = PyGraph(multigraph=False)
graph.add_nodes_from(range(np.prod(size)))

# add edges excluding the boundary edges
Expand Down
8 changes: 4 additions & 4 deletions qiskit_nature/second_q/hamiltonians/lattices/lattice.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This code is part of Qiskit.
#
# (C) Copyright IBM 2021, 2022.
# (C) Copyright IBM 2021, 2023.
#
# 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 @@ -22,7 +22,7 @@
import numpy as np

from rustworkx import NodeIndices, PyGraph, WeightedEdgeList
from rustworkx import adjacency_matrix, networkx_converter
from rustworkx import adjacency_matrix, networkx_converter # type: ignore[attr-defined]
from rustworkx.visualization import mpl_draw

from qiskit.utils import optionals as _optionals
Expand Down Expand Up @@ -186,7 +186,7 @@ def from_nodes_and_edges(
Returns:
Lattice generated from lists of nodes and edges.
"""
graph = PyGraph(multigraph=False)
graph: PyGraph = PyGraph(multigraph=False)
graph.add_nodes_from(range(num_nodes))
graph.add_edges_from(weighted_edges)
return cls(graph)
Expand Down Expand Up @@ -243,7 +243,7 @@ def from_adjacency_matrix(cls, interaction_matrix: np.ndarray) -> Lattice:
"It must be a square matrix."
)

graph = PyGraph(multigraph=False)
graph: PyGraph = PyGraph(multigraph=False)
graph.add_nodes_from(range(shape[0]))
for source_index in range(shape[0]):
for target_index in range(source_index, shape[0]):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This code is part of Qiskit.
#
# (C) Copyright IBM 2021, 2022.
# (C) Copyright IBM 2021, 2023.
#
# 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 @@ -209,7 +209,7 @@ def __init__(
self.edge_parameter = edge_parameter
self.onsite_parameter = onsite_parameter

graph = PyGraph(multigraph=False)
graph: PyGraph = PyGraph(multigraph=False)
graph.add_nodes_from(range(np.prod(self.size)))

# add edges excluding the boundary edges
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This code is part of Qiskit.
#
# (C) Copyright IBM 2021, 2022.
# (C) Copyright IBM 2021, 2023.
#
# 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 @@ -14,7 +14,7 @@
from test import QiskitNatureTestCase
import numpy as np
from numpy.testing import assert_array_equal
from rustworkx import PyGraph, is_isomorphic
from rustworkx import PyGraph, is_isomorphic # type: ignore[attr-defined]
from qiskit_nature.second_q.hamiltonians.lattices import (
BoundaryCondition,
HyperCubicLattice,
Expand Down
4 changes: 2 additions & 2 deletions test/second_q/hamiltonians/lattices/test_lattice.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This code is part of Qiskit.
#
# (C) Copyright IBM 2021, 2022.
# (C) Copyright IBM 2021, 2023.
#
# 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 @@ -17,7 +17,7 @@
import numpy as np
from numpy.testing import assert_array_equal

from rustworkx import PyGraph, is_isomorphic
from rustworkx import PyGraph, is_isomorphic # type: ignore[attr-defined]

from qiskit.utils import optionals as _optionals

Expand Down
4 changes: 2 additions & 2 deletions test/second_q/hamiltonians/lattices/test_line_lattice.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This code is part of Qiskit.
#
# (C) Copyright IBM 2021, 2022.
# (C) Copyright IBM 2021, 2023.
#
# 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 @@ -14,7 +14,7 @@
from test import QiskitNatureTestCase
from numpy.testing import assert_array_equal
import numpy as np
from rustworkx import PyGraph, is_isomorphic
from rustworkx import PyGraph, is_isomorphic # type: ignore[attr-defined]
from qiskit_nature.second_q.hamiltonians.lattices import (
BoundaryCondition,
LineLattice,
Expand Down
4 changes: 2 additions & 2 deletions test/second_q/hamiltonians/lattices/test_square_lattice.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This code is part of Qiskit.
#
# (C) Copyright IBM 2021, 2022.
# (C) Copyright IBM 2021, 2023.
#
# 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 @@ -14,7 +14,7 @@
from test import QiskitNatureTestCase
from numpy.testing import assert_array_equal
import numpy as np
from rustworkx import PyGraph, is_isomorphic
from rustworkx import PyGraph, is_isomorphic # type: ignore[attr-defined]
from qiskit_nature.second_q.hamiltonians.lattices import (
BoundaryCondition,
SquareLattice,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This code is part of Qiskit.
#
# (C) Copyright IBM 2021, 2022.
# (C) Copyright IBM 2021, 2023.
#
# 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 @@ -14,7 +14,7 @@
from test import QiskitNatureTestCase
from numpy.testing import assert_array_equal
import numpy as np
from rustworkx import PyGraph, is_isomorphic
from rustworkx import PyGraph, is_isomorphic # type: ignore[attr-defined]
from qiskit_nature.second_q.hamiltonians.lattices import (
BoundaryCondition,
TriangularLattice,
Expand Down
4 changes: 2 additions & 2 deletions test/second_q/hamiltonians/test_fermi_hubbard_model.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This code is part of Qiskit.
#
# (C) Copyright IBM 2021, 2022.
# (C) Copyright IBM 2021, 2023.
#
# 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 @@ -15,7 +15,7 @@

import numpy as np
from numpy.testing import assert_array_equal
from rustworkx import PyGraph, is_isomorphic
from rustworkx import PyGraph, is_isomorphic # type: ignore[attr-defined]

from qiskit_nature.second_q.hamiltonians import FermiHubbardModel
from qiskit_nature.second_q.hamiltonians.lattices import Lattice
Expand Down
4 changes: 2 additions & 2 deletions test/second_q/hamiltonians/test_heisenberg_model.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This code is part of Qiskit.
#
# (C) Copyright IBM 2022.
# (C) Copyright IBM 2022, 2023.
#
# 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 @@ -13,7 +13,7 @@
"""Test HeisenbergModel."""

from test import QiskitNatureTestCase
from rustworkx import PyGraph, is_isomorphic
from rustworkx import PyGraph, is_isomorphic # type: ignore[attr-defined]
from qiskit_nature.second_q.hamiltonians.lattices import Lattice, LineLattice
from qiskit_nature.second_q.hamiltonians import HeisenbergModel, IsingModel

Expand Down
4 changes: 2 additions & 2 deletions test/second_q/hamiltonians/test_ising_model.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This code is part of Qiskit.
#
# (C) Copyright IBM 2021, 2022.
# (C) Copyright IBM 2021, 2023.
#
# 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,7 +16,7 @@

import numpy as np
from numpy.testing import assert_array_equal
from rustworkx import PyGraph, is_isomorphic
from rustworkx import PyGraph, is_isomorphic # type: ignore[attr-defined]

from qiskit_nature.second_q.hamiltonians.lattices import Lattice
from qiskit_nature.second_q.hamiltonians import IsingModel
Expand Down

0 comments on commit 08df681

Please sign in to comment.