Skip to content

Commit

Permalink
[GA-165] Phenolrs: Support Edge Values in COO Loading for `NetworkXGr…
Browse files Browse the repository at this point in the history
…aph` (#29)

* support to write edge values when using data structure coo

* u64 instead of vec<u64>

* fixed insert edge in networkx graph when "@collection_name" is being set

* black fmt

* cargo fmt

* add EdgeValuesDict and use it

* black fmt

* add a test for edge values

* added failure test

* removed comment, added todo

* use latest lib vers 0.0.7, code cleanup

* fmt

* Update python/tests/test_all.py

* put coo relevant logic in coo relevant code block, f64 instead of u64

* Update python/phenolrs/networkx/typings.py

Co-authored-by: Anthony Mahanna <[email protected]>

* applied proper error testing code review request

* remove not required res

* more tests

* black fmt

* remove `bool` as possible `EdgeValue` type

(my mistake)

---------

Co-authored-by: Anthony Mahanna <[email protected]>
Co-authored-by: Anthony Mahanna <[email protected]>
  • Loading branch information
3 people authored Aug 9, 2024
1 parent 5e0b8fe commit 156b860
Show file tree
Hide file tree
Showing 10 changed files with 292 additions and 32 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ lto = "fat"
# TODO: add rustflags for target features/cpus

[dependencies]
arangors-graph-exporter = "0.0.6"
arangors-graph-exporter = "0.0.7"
numpy = "0.20.0"
tokio = { version = "1", features = ["full"] }
bytes = "1.5.0"
Expand Down
29 changes: 19 additions & 10 deletions python/phenolrs/networkx/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
MultiGraphAdjDict,
NodeDict,
SrcIndices,
EdgeValuesDict,
)


Expand Down Expand Up @@ -41,6 +42,7 @@ def load_into_networkx(
DstIndices,
EdgeIndices,
ArangoIDtoIndex,
EdgeValuesDict,
]:
if "vertexCollections" not in metagraph:
raise PhenolError("vertexCollections not found in metagraph")
Expand Down Expand Up @@ -113,16 +115,22 @@ def load_into_networkx(
for e_col_name, entries in metagraph["edgeCollections"].items()
]

node_dict, adj_dict, src_indices, dst_indices, edge_indices, id_to_index_map = (
graph_to_networkx_format(
request={
"vertex_collections": vertex_collections,
"edge_collections": edge_collections,
"database_config": db_config_options,
"load_config": load_config_options,
},
graph_config=graph_config, # TODO Anthony: Move into request
)
(
node_dict,
adj_dict,
src_indices,
dst_indices,
edge_indices,
id_to_index_map,
edge_values,
) = graph_to_networkx_format(
request={
"vertex_collections": vertex_collections,
"edge_collections": edge_collections,
"database_config": db_config_options,
"load_config": load_config_options,
},
graph_config=graph_config, # TODO Anthony: Move into request
)

return (
Expand All @@ -132,4 +140,5 @@ def load_into_networkx(
dst_indices,
edge_indices,
id_to_index_map,
edge_values,
)
1 change: 1 addition & 0 deletions python/phenolrs/networkx/typings.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
DiGraphAdjDict = dict[str, GraphAdjDict]
MultiGraphAdjDict = dict[str, dict[str, dict[int, Json]]]
MultiDiGraphAdjDict = dict[str, MultiGraphAdjDict]
EdgeValuesDict = dict[str, list[int | float]]

SrcIndices = npt.NDArray[np.int64]
DstIndices = npt.NDArray[np.int64]
Expand Down
2 changes: 2 additions & 0 deletions python/phenolrs/phenolrs.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ from .networkx.typings import (
MultiGraphAdjDict,
NodeDict,
SrcIndices,
EdgeValuesDict,
)
from .numpy.typings import (
ArangoCollectionToArangoKeyToIndex,
Expand All @@ -36,6 +37,7 @@ def graph_to_networkx_format(
DstIndices,
EdgeIndices,
ArangoIDtoIndex,
EdgeValuesDict,
]: ...

class PhenolError(Exception): ...
44 changes: 44 additions & 0 deletions python/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,50 @@ def abide_db_name() -> str:
return "abide"


@pytest.fixture(scope="module")
def custom_graph_db_name() -> str:
return "custom_graph"


@pytest.fixture(scope="module")
def load_line_graph(
custom_graph_db_name: str, connection_information: Dict[str, Any]
) -> None:
client = arango.ArangoClient(connection_information["url"])
sys_db = client.db(
"_system",
username=connection_information["username"],
password=connection_information["password"],
)

if not sys_db.has_database(custom_graph_db_name):
sys_db.delete_database(custom_graph_db_name, ignore_missing=True)
sys_db.create_database(custom_graph_db_name)
custom_graph_db = client.db(
custom_graph_db_name,
username=connection_information["username"],
password=connection_information["password"],
)

edge_def = [
{
"edge_collection": "line_graph_edges",
"from_vertex_collections": ["line_graph_vertices"],
"to_vertex_collections": ["line_graph_vertices"],
}
]

G = nx.Graph()
G.add_edge(0, 1, boolean_weight=True, int_value=1, float_value=1.1)
G.add_edge(1, 2, boolean_weight=False, int_value=2, float_value=2.2)
G.add_edge(2, 3, boolean_weight=True, int_value=3, float_value=3.3)
G.add_edge(3, 4, boolean_weight=False, int_value=4, float_value=4.4)

ADBNX_Adapter(custom_graph_db).networkx_to_arangodb(
custom_graph_db_name, G, edge_def
)


@pytest.fixture(scope="module")
def load_karate(karate_db_name: str, connection_information: Dict[str, Any]) -> None:
client = arango.ArangoClient(connection_information["url"])
Expand Down
Loading

0 comments on commit 156b860

Please sign in to comment.