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

fix: typing compatibility with rustworkx 0.13.0 #1202

Merged
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
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I imagine you could have done a simple if else around the make mypy to do it one way or another depending on whether python version was 3.7 or not - akin to what is done in line 176 above. But this does the job too.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ha I failed to see that other example and simply zoomed in on the local part here and this seemed good enough 👍

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