-
Notifications
You must be signed in to change notification settings - Fork 4
nxadb_to_nx cleanup #32
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
Merged
Merged
Changes from 9 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
2636027
attempt: nxadb_to_nx cleanup
aMahanna 614bea6
Merge branch 'main' into cleanup-nxadb-to-nx
aMahanna fda2dc3
checkpoint
aMahanna d9b5c30
bring back other algorithms
aMahanna eb2772d
passing, but certain assertions are commented out
aMahanna e442c9b
attempt cleanup: nx overrides
aMahanna 6870108
cleanup: symmetrize_edges_if_directed
aMahanna b8e86c2
cleanup: `test_algorithm` assertions
aMahanna 26b0f53
Merge branch 'main' into cleanup-nxadb-to-nx
aMahanna 7c46d28
Merge branch 'main' into cleanup-nxadb-to-nx
aMahanna 194a0fe
fix: symmetrize edges
aMahanna 7fe5503
fix: symmetrize edges
aMahanna 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -6,6 +6,8 @@ | |
import networkx as nx | ||
|
||
import nx_arangodb as nxadb | ||
from nx_arangodb.classes.dict.adj import AdjListOuterDict | ||
from nx_arangodb.classes.dict.node import NodeDict | ||
from nx_arangodb.classes.function import do_load_all_edge_attributes | ||
from nx_arangodb.logger import logger | ||
|
||
|
@@ -30,7 +32,7 @@ | |
def _to_nx_graph(G: Any, *args: Any, **kwargs: Any) -> nx.Graph: | ||
logger.debug(f"_to_nx_graph for {G.__class__.__name__}") | ||
|
||
if isinstance(G, nxadb.Graph | nxadb.DiGraph): | ||
if isinstance(G, nxadb.Graph): | ||
return nxadb_to_nx(G) | ||
|
||
if isinstance(G, nx.Graph): | ||
|
@@ -109,16 +111,14 @@ def nx_to_nxadb( | |
|
||
def nxadb_to_nx(G: nxadb.Graph) -> nx.Graph: | ||
if not G.graph_exists_in_db: | ||
logger.debug("graph does not exist, nothing to pull") | ||
# TODO: Consider just returning G here? | ||
# Avoids the need to re-create the graph from scratch | ||
return G.to_networkx_class()(incoming_graph_data=G) | ||
# Since nxadb.Graph is a subclass of nx.Graph, we can return it as is. | ||
# This only applies if the graph does not exist in the database. | ||
return G | ||
|
||
# TODO: Re-enable this | ||
# if G.use_nx_cache and G._node and G._adj: | ||
# m = "**use_nx_cache** is enabled. using cached data. no pull required." | ||
# logger.debug(m) | ||
# return G | ||
assert isinstance(G._node, NodeDict) | ||
assert isinstance(G._adj, AdjListOuterDict) | ||
if G._node.FETCHED_ALL_DATA and G._adj.FETCHED_ALL_DATA: | ||
return G | ||
|
||
start_time = time.time() | ||
|
||
|
@@ -137,11 +137,22 @@ def nxadb_to_nx(G: nxadb.Graph) -> nx.Graph: | |
|
||
print(f"Graph '{G.adb_graph.name}' load took {time.time() - start_time}s") | ||
|
||
G_NX: nx.Graph | nx.DiGraph = G.to_networkx_class()() | ||
# NOTE: At this point, we _could_ choose to implement something similar to | ||
# NodeDict._fetch_all() and AdjListOuterDict._fetch_all() to iterate through | ||
# **node_dict** and **adj_dict**, and establish the "custom" Dictionary classes | ||
# that we've implemented in nx_arangodb.classes.dict. | ||
# However, this would involve adding additional for-loops and would likely be | ||
# slower than the current implementation. | ||
# Perhaps we should consider adding a feature flag to allow users to choose | ||
# between the two methods? e.g `build_remote_dicts=True/False` | ||
# If True, then we would return the (updated) nxadb.Graph that was passed in. | ||
# If False, then we would return the nx.Graph that is built below: | ||
|
||
G_NX: nx.Graph = G.to_networkx_class()() | ||
G_NX._node = node_dict | ||
|
||
if isinstance(G_NX, nx.DiGraph): | ||
G_NX._succ = G._adj = adj_dict["succ"] | ||
G_NX._succ = G_NX._adj = adj_dict["succ"] | ||
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. this was the bug culprit. I mistakenly overwrote the |
||
G_NX._pred = adj_dict["pred"] | ||
|
||
else: | ||
|
This file contains hidden or 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 hidden or 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
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.
this would be an interesting point of discussion to address in a separate PR as an improvement