Skip to content

Instantly share code, notes, and snippets.

@colllin
Last active February 12, 2024 18:36

Revisions

  1. colllin revised this gist Feb 12, 2024. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions rustworkx-suggestions.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,7 @@
    - serialization/deserialization symmetry
    - in general need more formatting options OR go to/from a major interchange format and recommend a separate library for every other kind of format in/out.
    - But need to support at least one text-based in/out so that we can easily print to inspect a graph
    - Why does `rx.node_link_json` require `str` values in the node and edge payloads, when JSON supports several other data types? This makes deserialization awkward and error-prone, so for now I'm just converting the nodes to `{'json': json.dumps(node_payload)}`.
    - no `node_index_map()`? So you have this clunky interface where you can get either the indices or the data but not both
    - `subgraph()` resets node indices 😱🤯
    - `add_nodes_from()` should just be called `add_nodes()`, same for `add_edges_from()`
  2. colllin revised this gist Feb 6, 2024. 1 changed file with 1 addition and 13 deletions.
    14 changes: 1 addition & 13 deletions rustworkx-suggestions.md
    Original file line number Diff line number Diff line change
    @@ -8,21 +8,9 @@
    - `rx.union()` should accept a merge predicate function to determine which nodes to merge, and/or the attrs of the merged node
    - `PyGraph.contract_nodes()` equivalent to `merge_nodes()` in DiGraph and DAG? (Should be same name...)
    - `rx.is_subgraph_isomorphic(graph1, graph2)` returns `True` when `graph1` is empty (has `0` nodes) and `graph2` is not empty (has >0 nodes), but I believe it should return False, since an empty graph shouldn't have any subgraphs that are isomorphic with graph2... right?
    - Also rx.vf2_mapping will return empty mappings (`{}`) in this situation.
    - workaround? instead of use `next(rx.vf2_mapping(..., subgraph=True), None) is not None`
    - workaround? instead of `rx.is_subgraph_isomorphic`, use `next(rx.vf2_mapping(..., subgraph=True), None) is not None`

    ```
    # First wrap vf2 mapping to remove empty mappings.
    def vf2_mapping(*args, **kwargs):
    for mapping in rx.vf2_mapping(*args, **kwargs):
    # This skips "empty" mappings, i.e. `{}`, which happens when one of the graphs is empty.
    if mapping:
    yield mapping
    # Then rewrite is_subgraph_isomorphic to check for any non-empty mappings.
    # This solves two problems:
    # - one where is_subgraph_isomorphic returns True but vf2_mapping returns an empty list
    # - ther other where vf2_mapping returns empty mappings
    def is_subgraph_isomorphic(*args, **kwargs):
    return next(vf2_mapping(*args, subgraph=True, **kwargs), None) is not None
    ```
  3. colllin revised this gist Feb 6, 2024. 1 changed file with 19 additions and 1 deletion.
    20 changes: 19 additions & 1 deletion rustworkx-suggestions.md
    Original file line number Diff line number Diff line change
    @@ -8,5 +8,23 @@
    - `rx.union()` should accept a merge predicate function to determine which nodes to merge, and/or the attrs of the merged node
    - `PyGraph.contract_nodes()` equivalent to `merge_nodes()` in DiGraph and DAG? (Should be same name...)
    - `rx.is_subgraph_isomorphic(graph1, graph2)` returns `True` when `graph1` is empty (has `0` nodes) and `graph2` is not empty (has >0 nodes), but I believe it should return False, since an empty graph shouldn't have any subgraphs that are isomorphic with graph2... right?
    - workaround? instead use `next(rx.vf2_mapping(..., subgraph=True), None) is not None`
    - Also rx.vf2_mapping will return empty mappings (`{}`) in this situation.
    - workaround? instead of use `next(rx.vf2_mapping(..., subgraph=True), None) is not None`

    ```
    # First wrap vf2 mapping to remove empty mappings.
    def vf2_mapping(*args, **kwargs):
    for mapping in rx.vf2_mapping(*args, **kwargs):
    # This skips "empty" mappings, i.e. `{}`, which happens when one of the graphs is empty.
    if mapping:
    yield mapping
    # Then rewrite is_subgraph_isomorphic to check for any non-empty mappings.
    # This solves two problems:
    # - one where is_subgraph_isomorphic returns True but vf2_mapping returns an empty list
    # - ther other where vf2_mapping returns empty mappings
    def is_subgraph_isomorphic(*args, **kwargs):
    return next(vf2_mapping(*args, subgraph=True, **kwargs), None) is not None
    ```
    -
  4. colllin revised this gist Feb 6, 2024. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions rustworkx-suggestions.md
    Original file line number Diff line number Diff line change
    @@ -8,4 +8,5 @@
    - `rx.union()` should accept a merge predicate function to determine which nodes to merge, and/or the attrs of the merged node
    - `PyGraph.contract_nodes()` equivalent to `merge_nodes()` in DiGraph and DAG? (Should be same name...)
    - `rx.is_subgraph_isomorphic(graph1, graph2)` returns `True` when `graph1` is empty (has `0` nodes) and `graph2` is not empty (has >0 nodes), but I believe it should return False, since an empty graph shouldn't have any subgraphs that are isomorphic with graph2... right?
    - workaround? instead use `next(rx.vf2_mapping(..., subgraph=True), None) is not None`
    -
  5. colllin renamed this gist Feb 6, 2024. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions rustworkx-issues.md → rustworkx-suggestions.md
    Original file line number Diff line number Diff line change
    @@ -7,4 +7,5 @@
    - `compose()` accepts an edge map which prevents having multiple edges from one node in the main graph to multiple nodes in the added fragment. Instead, it should accept an edge list in the same format used by `add_edges_from()`
    - `rx.union()` should accept a merge predicate function to determine which nodes to merge, and/or the attrs of the merged node
    - `PyGraph.contract_nodes()` equivalent to `merge_nodes()` in DiGraph and DAG? (Should be same name...)
    - `rx.is_subgraph_isomorphic(graph1, graph2)` returns `True` when `graph1` is empty (has `0` nodes) and `graph2` is not empty (has >0 nodes), but I believe it should return False, since an empty graph shouldn't have any subgraphs that are isomorphic with graph2... right?
    -
  6. colllin revised this gist Jan 5, 2024. No changes.
  7. colllin revised this gist Jan 5, 2024. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions rustworkx-issues.md
    Original file line number Diff line number Diff line change
    @@ -6,4 +6,5 @@
    - `add_nodes_from()` should just be called `add_nodes()`, same for `add_edges_from()`
    - `compose()` accepts an edge map which prevents having multiple edges from one node in the main graph to multiple nodes in the added fragment. Instead, it should accept an edge list in the same format used by `add_edges_from()`
    - `rx.union()` should accept a merge predicate function to determine which nodes to merge, and/or the attrs of the merged node
    - `PyGraph.contract_nodes()` equivalent to `merge_nodes()` in DiGraph and DAG? (Should be same name...)
    -
  8. colllin revised this gist Jan 4, 2024. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion rustworkx-issues.md
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,7 @@
    - in general need more formatting options OR go to/from a major interchange format and recommend a separate library for every other kind of format in/out.
    - But need to support at least one text-based in/out so that we can easily print to inspect a graph
    - no `node_index_map()`? So you have this clunky interface where you can get either the indices or the data but not both
    - `subgraph()` resets node indices
    - `subgraph()` resets node indices 😱🤯
    - `add_nodes_from()` should just be called `add_nodes()`, same for `add_edges_from()`
    - `compose()` accepts an edge map which prevents having multiple edges from one node in the main graph to multiple nodes in the added fragment. Instead, it should accept an edge list in the same format used by `add_edges_from()`
    - `rx.union()` should accept a merge predicate function to determine which nodes to merge, and/or the attrs of the merged node
  9. colllin renamed this gist Jan 4, 2024. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  10. colllin revised this gist Jan 4, 2024. 1 changed file with 8 additions and 6 deletions.
    14 changes: 8 additions & 6 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,9 @@
    - serialization/deserialization
    - no node_index_map?
    - subgraph resets node indices
    - "add_nodes_from" should just be "add_nodes", same for add_edges_from
    - compose accepts an edge map which prevents having multiple edges from one node in the main graph to multiple nodes in the added fragment.
    - union should accept a merge predicate function to determine which nodes to merge, and/or the attrs of the merged node
    - serialization/deserialization symmetry
    - in general need more formatting options OR go to/from a major interchange format and recommend a separate library for every other kind of format in/out.
    - But need to support at least one text-based in/out so that we can easily print to inspect a graph
    - no `node_index_map()`? So you have this clunky interface where you can get either the indices or the data but not both
    - `subgraph()` resets node indices
    - `add_nodes_from()` should just be called `add_nodes()`, same for `add_edges_from()`
    - `compose()` accepts an edge map which prevents having multiple edges from one node in the main graph to multiple nodes in the added fragment. Instead, it should accept an edge list in the same format used by `add_edges_from()`
    - `rx.union()` should accept a merge predicate function to determine which nodes to merge, and/or the attrs of the merged node
    -
  11. colllin created this gist Jan 4, 2024.
    7 changes: 7 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    - serialization/deserialization
    - no node_index_map?
    - subgraph resets node indices
    - "add_nodes_from" should just be "add_nodes", same for add_edges_from
    - compose accepts an edge map which prevents having multiple edges from one node in the main graph to multiple nodes in the added fragment.
    - union should accept a merge predicate function to determine which nodes to merge, and/or the attrs of the merged node
    -