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

[FEA]: Support creating a subgraph as a Property graph from an existing Property Graph #3158

Closed
2 tasks done
Tracked by #12 ...
acostadon opened this issue Jan 18, 2023 · 2 comments · Fixed by #3349
Closed
2 tasks done
Tracked by #12 ...
Assignees
Labels
feature request New feature or request
Milestone

Comments

@acostadon
Copy link
Contributor

Is this a new feature, an improvement, or a change to existing functionality?

New Feature

How would you describe the priority of this feature request

High

Please provide a clear description of problem this feature solves

a way to extract a subgraph or sample of a PropertyGraph object without converting it to a cugraph object.

Describe your ideal solution

the PropertySelection objects returned from e.g. select_vertices can be used to extract a new PropertyGraph

Describe any alternatives you have considered

No response

Additional context

No response

Code of Conduct

  • I agree to follow cuGraph's Code of Conduct
  • I have searched the open feature requests and have found no duplicates for this feature request
@acostadon acostadon added the feature request New feature or request label Jan 18, 2023
@acostadon
Copy link
Contributor Author

Please notify Christian Conroy in the Rapids-goAi Slack when this is complete.

@rlratzel
Copy link
Contributor

We may want to do this by allowing extract_subgraph to take a PropertyGraph for the create_using arg.

Here's a workaround I posted:

>>> from cugraph import Graph
>>> from cugraph.experimental import PropertyGraph
>>> import cudf

>>> df = cudf.DataFrame(columns=["src", "dst", "some_property"],
...                     data=[(99, 22, "a"),
...                           (98, 34, "b"),
...                           (97, 56, "c"),
...                           (96, 88, "d"),
...                     ])
>>> pG = PropertyGraph()
>>> pG.add_edge_data(df, vertex_col_names=("src", "dst"))
>>> pG.get_edge_data()
   _EDGE_ID_ some_property  _SRC_  _DST_ _TYPE_
0          0             a     99     22
1          1             b     98     34
2          2             c     97     56
3          3             d     96     88

>>> # Select edges 'a' and 'b'
>>> selection = pG.select_edges("(some_property=='a')|(some_property=='b')")

>>> # Extract a subgraph as a cugraph directed Graph, include the edge property
>>> # meta-data for use in future calls to annotate_dataframe()
>>> G2 = pG.extract_subgraph(selection=selection,
...                          create_using=Graph(directed=True),
...                          add_edge_data=True)

>>> # Create a DataFrame containing the property data for the extracted edges
>>> # referencing the original PropertyGraph from which it was extracted
>>> subgraph_edge_data = pG.annotate_dataframe(G2.edges(), G2, edge_vertex_col_names=["src", "dst"])

>>> # Create a new PropertyGraph using the extracted data
>>> subPG = PropertyGraph()
>>> subPG.add_edge_data(subgraph_edge_data,
...                     vertex_col_names=["src", "dst"],
...                     property_columns=["some_property"])
>>> subPG.get_edge_data()
   _EDGE_ID_ some_property _TYPE_  _SRC_  _DST_
0          0             b            98     34
1          1             a            99     22

@rlratzel rlratzel added this to the 23.04 milestone Jan 18, 2023
rapids-bot bot pushed a commit that referenced this issue Mar 24, 2023
Closes #3158 

This also fixes a deprecation in `cudf` when using `inplace` with adding categories.

Authors:
  - Erik Welch (https://github.com/eriknw)

Approvers:
  - Alex Barghi (https://github.com/alexbarghi-nv)
  - Rick Ratzel (https://github.com/rlratzel)

URL: #3349
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants