-
Notifications
You must be signed in to change notification settings - Fork 310
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 entry point to tell NetworkX about nx-cugraph without importing it. #3848
Merged
rapids-bot
merged 10 commits into
rapidsai:branch-23.10
from
eriknw:nx_plugin_info_entrypoint
Sep 28, 2023
Merged
Changes from 5 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
5936023
Add entry point to tell NetworkX about nx-cugraph without importing it.
eriknw a9eaba7
Include type info in extra parameter
eriknw f32831b
Fix; add "url" and "short_summary"
eriknw 3eeec69
Merge branch 'branch-23.10' into nx_plugin_info_entrypoint
eriknw f045d6e
Support networkx 3.0 and 3.1
eriknw 67e3cc6
Merge branch 'branch-23.10' into nx_plugin_info_entrypoint
eriknw 7950c4e
Change format of function info in dict
eriknw d2ab5cf
Bump lint versions
eriknw 465bf69
Update `_nx_cugraph.__version__`; support threshold in louvain
eriknw 3c81a1c
Merge branch 'branch-23.10' into nx_plugin_info_entrypoint
eriknw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,17 @@ | ||
# Copyright (c) 2023, NVIDIA CORPORATION. | ||
SHELL= /bin/bash | ||
|
||
.PHONY: all | ||
all: plugin-info lint | ||
|
||
.PHONY: lint | ||
lint: | ||
git ls-files | xargs pre-commit run --config lint.yaml --files | ||
|
||
.PHONY: lint-update | ||
lint-update: | ||
pre-commit autoupdate --config lint.yaml | ||
|
||
.PHONY: plugin-info | ||
plugin-info: | ||
python _nx_cugraph/__init__.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# Copyright (c) 2023, NVIDIA CORPORATION. | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
"""Tell NetworkX about the cugraph backend. This file can update itself: | ||
|
||
$ make plugin-info # Recommended method for development | ||
|
||
or | ||
|
||
$ python _nx_cugraph/__init__.py | ||
""" | ||
|
||
|
||
def get_info(): | ||
"""Target of ``networkx.plugin_info`` entry point. | ||
|
||
This tells NetworkX about the cugraph backend without importing nx_cugraph. | ||
""" | ||
# Entries between BEGIN and END are automatically generated | ||
return { | ||
"backend_name": "cugraph", | ||
"project": "nx-cugraph", | ||
"package": "nx_cugraph", | ||
"url": "https://github.com/rapidsai/cugraph/tree/branch-23.10/python/nx-cugraph", | ||
"short_summary": "GPU-accelerated backend.", | ||
# "description": "TODO", | ||
"functions": { | ||
# BEGIN: functions | ||
"betweenness_centrality", | ||
"edge_betweenness_centrality", | ||
"louvain_communities", | ||
# END: functions | ||
}, | ||
"extra_docstrings": { | ||
# BEGIN: extra_docstrings | ||
"betweenness_centrality": "`weight` parameter is not yet supported.", | ||
"edge_betweenness_centrality": "`weight` parameter is not yet supported.", | ||
"louvain_communities": "`threshold` and `seed` parameters are currently ignored.", | ||
# END: extra_docstrings | ||
}, | ||
"extra_parameters": { | ||
# BEGIN: extra_parameters | ||
"louvain_communities": { | ||
"max_level : int, optional": "Upper limit of the number of macro-iterations.", | ||
}, | ||
# END: extra_parameters | ||
}, | ||
} | ||
|
||
|
||
__version__ = "23.10.00" | ||
eriknw marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
if __name__ == "__main__": | ||
from pathlib import Path | ||
|
||
from _nx_cugraph.core import main | ||
|
||
filepath = Path(__file__) | ||
text = main(filepath) | ||
with filepath.open("w") as f: | ||
f.write(text) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
# Copyright (c) 2023, NVIDIA CORPORATION. | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
"""Utilities to help keep _nx_cugraph up to date.""" | ||
|
||
|
||
def get_functions(): | ||
from nx_cugraph.interface import BackendInterface | ||
from nx_cugraph.utils import networkx_algorithm | ||
|
||
return { | ||
key: val | ||
for key, val in vars(BackendInterface).items() | ||
if isinstance(val, networkx_algorithm) | ||
} | ||
|
||
|
||
def get_extra_docstrings(functions=None): | ||
if functions is None: | ||
functions = get_functions() | ||
return {key: val.extra_doc for key, val in functions.items() if val.extra_doc} | ||
|
||
|
||
def get_extra_parameters(functions=None): | ||
if functions is None: | ||
functions = get_functions() | ||
return {key: val.extra_params for key, val in functions.items() if val.extra_params} | ||
|
||
|
||
def update_text(text, lines_to_add, target, indent=" " * 12): | ||
begin = f"# BEGIN: {target}\n" | ||
end = f"# END: {target}\n" | ||
start = text.index(begin) | ||
stop = text.index(end) | ||
to_add = "\n".join([f"{indent}{line}" for line in lines_to_add]) | ||
return f"{text[:start]}{begin}{to_add}\n{indent}{text[stop:]}" | ||
|
||
|
||
def dict_to_lines(d, *, indent=""): | ||
for key in sorted(d): | ||
val = d[key] | ||
if "\n" not in val: | ||
yield f"{indent}{key!r}: {val!r}," | ||
else: | ||
yield f"{indent}{key!r}: (" | ||
*lines, last_line = val.split("\n") | ||
for line in lines: | ||
line += "\n" | ||
yield f" {indent}{line!r}" | ||
yield f" {indent}{last_line!r}" | ||
yield f"{indent})," | ||
|
||
|
||
def main(filepath): | ||
from pathlib import Path | ||
|
||
filepath = Path(filepath) | ||
with filepath.open() as f: | ||
orig_text = f.read() | ||
text = orig_text | ||
|
||
# Update functions | ||
functions = get_functions() | ||
to_add = [f'"{name}",' for name in sorted(functions)] | ||
text = update_text(text, to_add, "functions") | ||
|
||
# Update extra_docstrings | ||
extra_docstrings = get_extra_docstrings(functions) | ||
to_add = list(dict_to_lines(extra_docstrings)) | ||
text = update_text(text, to_add, "extra_docstrings") | ||
|
||
# Update extra_parameters | ||
extra_parameters = get_extra_parameters(functions) | ||
to_add = [] | ||
for name in sorted(extra_parameters): | ||
params = extra_parameters[name] | ||
to_add.append(f"{name!r}: {{") | ||
to_add.extend(dict_to_lines(params, indent=" " * 4)) | ||
to_add.append("},") | ||
text = update_text(text, to_add, "extra_parameters") | ||
return text |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,9 +12,21 @@ | |
# limitations under the License. | ||
from networkx.exception import * | ||
|
||
from . import algorithms, classes, convert, utils | ||
from .algorithms import * | ||
from . import utils | ||
|
||
from . import classes | ||
from .classes import * | ||
|
||
from . import convert | ||
from .convert import * | ||
|
||
# from . import convert_matrix | ||
# from .convert_matrix import * | ||
|
||
# from . import generators | ||
# from .generators import * | ||
Comment on lines
+23
to
+27
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this dead code we can remove? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is future code, yet to be born |
||
|
||
from . import algorithms | ||
from .algorithms import * | ||
|
||
__version__ = "23.10.00" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alternatively, we could organize info like: