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

Subgraph isomorphism fails with parallel edges #429

Closed
georgios-ts opened this issue Aug 30, 2021 · 2 comments · Fixed by #430
Closed

Subgraph isomorphism fails with parallel edges #429

georgios-ts opened this issue Aug 30, 2021 · 2 comments · Fixed by #430
Assignees
Labels
bug Something isn't working

Comments

@georgios-ts
Copy link
Collaborator

Information

  • retworkx version: main
  • Python version: Any
  • Rust version: Any
  • Operating system: Any

What is the current behavior?

is_subgraph_isomorphic returns True even in cases it shouldn't. This happens if the input "small" graph have parallel edges.

What is the expected behavior?

Handle correctly graphs with parallel edges.

Steps to reproduce the problem

import retworkx as rx

first = rx.PyGraph()
first.extend_from_edge_list([
    (0, 1), (1, 2), (2, 3)
])
second = rx.PyGraph()
second.extend_from_edge_list([
    (0, 1), (0, 1)
])
rx.is_subgraph_isomorphic(first, second)
---
True
@georgios-ts georgios-ts added the bug Something isn't working label Aug 30, 2021
@georgios-ts georgios-ts self-assigned this Aug 30, 2021
@mtreinish
Copy link
Member

Fixing this definitely seems worth including in a 0.10.2 release.

georgios-ts added a commit to georgios-ts/retworkx that referenced this issue Aug 30, 2021
Closes Qiskit#429.
The solution is build an adjacency matrix with entries equal
to the number of edges connecting a pair of nodes instead of
0/1 values
@georgios-ts
Copy link
Collaborator Author

georgios-ts commented Sep 1, 2021

UPDATE:
Even retworkx.is_isomorphic fails with parallel edges if an edge_matcher is specified.
An example:

import retworkx as rx

graph = rx.PyGraph()
graph.extend_from_weighted_edge_list([
    (0, 1, 'a'), (0, 1, 'b'), (1, 2, 'c')
])

rx.is_isomorphic(graph, graph,
                 edge_matcher=lambda x, y: x == y)
----
False

UPDATE 2:
retworkx.is_subgraph_isomorphic may panic if induced=False and an edge_matcher is specified.

first = rx.PyGraph()
first.extend_from_weighted_edge_list([
    (0, 1, 'a'), (1, 2, 'b'), (2, 0, 'c')
])

second = rx.PyGraph()
second.extend_from_weighted_edge_list([
    (0, 1, 'a'), (1, 2, 'b')
])

rx.is_subgraph_isomorphic(first, second, induced=False,
                          edge_matcher=lambda x, y: x == y
)
---
PanicException: internal error: entered unreachable code

mtreinish pushed a commit that referenced this issue Sep 3, 2021
* Fix `is_subgraph_isomorphic` with parallel edges.
Closes #429.
The solution is build an adjacency matrix with entries equal
to the number of edges connecting a pair of nodes instead of
0/1 values

* run black

* use HashMap for adjacency matrix

* Fixes Vf2 algorithm if an `edge_matcher` is specified

* avoid clone

* call `edge_multiplicity` directly

Co-authored-by: Ivan Carvalho <ivan.ivancps.cn@gmail.com>

* a note about the decrease of memory usage

* drop extra referenece
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants