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

Add missing methods in PyGraph and PyDiGraph stubs #967

Merged
merged 15 commits into from
Jan 13, 2024

Conversation

IvanIsCoding
Copy link
Collaborator

@IvanIsCoding IvanIsCoding commented Aug 16, 2023

Closes #1036

Related to #352

Adds methods that were added after #401 was merged. All of them were checked with mypy.stubtest

@IvanIsCoding IvanIsCoding marked this pull request as ready for review August 16, 2023 03:39
Comment on lines +30 to +32
if TYPE_CHECKING:
from .digraph import PyDiGraph

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

PyGraph and PyDiGraph have a "cyclic" dependency due to the to_directed and to_undirected method. This is a hack to make Python agree with the Rust code

@coveralls
Copy link

coveralls commented Aug 16, 2023

Pull Request Test Coverage Report for Build 7513006606

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 95.915%

Totals Coverage Status
Change from base Build 7479261092: 0.0%
Covered Lines: 15990
Relevant Lines: 16671

💛 - Coveralls

@IvanIsCoding IvanIsCoding added this to the 0.14.0 milestone Aug 22, 2023
Copy link
Member

@mtreinish mtreinish left a comment

Choose a reason for hiding this comment

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

Overall this LGTM, just inline comments about the mapping of Vec<usize> to list[int] as Vec<usize> will take more than just a list.

Also is there a point where we can catch these missing functions in CI? I assume we're not yet because we're still marked as only partially typed. But can we enforce this for new methods on the graph classes while working on the rest of the functions?

@@ -52,11 +57,20 @@ class PyDiGraph(Generic[S, T]):
node_map_func: Callable[[S], int] | None = ...,
edge_map_func: Callable[[T], int] | None = ...,
) -> dict[int, int]: ...
def contract_nodes(
self,
nodes: list[int],
Copy link
Member

Choose a reason for hiding this comment

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

Technically I think this is

Suggested change
nodes: list[int],
nodes: Sequence[int],

although it also will except a numpy.ndarray, which isn't a sequence, for all int dtypes I think.

def copy(self) -> PyDiGraph[S, T]: ...
def edge_index_map(self) -> EdgeIndexMap[T]: ...
def edge_indices(self) -> EdgeIndices: ...
def edge_list(self) -> EdgeList: ...
def edges(self) -> list[T]: ...
def edge_subgraph(self, edge_list: list[tuple[int, int]], /) -> PyDiGraph[S, T]: ...
Copy link
Member

Choose a reason for hiding this comment

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

Same comment as above with contract_nodes.

Suggested change
def edge_subgraph(self, edge_list: list[tuple[int, int]], /) -> PyDiGraph[S, T]: ...
def edge_subgraph(self, edge_list: Sequence[tuple[int, int]], /) -> PyDiGraph[S, T]: ...

@@ -48,12 +55,20 @@ class PyGraph(Generic[S, T]):
node_map_func: Callable[[S], int] | None = ...,
edge_map_func: Callable[[T], int] | None = ...,
) -> dict[int, int]: ...
def contract_nodes(
self,
nodes: list[int],
Copy link
Member

Choose a reason for hiding this comment

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

Same comment as on digraph here.

@IvanIsCoding
Copy link
Collaborator Author

Overall this LGTM, just inline comments about the mapping of Vec<usize> to list[int] as Vec<usize> will take more than just a list.

Also is there a point where we can catch these missing functions in CI? I assume we're not yet because we're still marked as only partially typed. But can we enforce this for new methods on the graph classes while working on the rest of the functions?

We need to remove the —ignore from

commands = python -m mypy.stubtest --concise --ignore-missing-stub rustworkx.rustworkx
but I think it needs to be for our whole codebase

Copy link
Member

@mtreinish mtreinish left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for the quick update.

@mtreinish mtreinish added the automerge Queue a approved PR for merging label Jan 13, 2024
@mergify mergify bot merged commit f75291d into Qiskit:main Jan 13, 2024
27 checks passed
@IvanIsCoding IvanIsCoding deleted the new_graph_digraph_methods branch January 28, 2024 01:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge Queue a approved PR for merging
Projects
None yet
Development

Successfully merging this pull request may close these issues.

missing node_indices method
3 participants