-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
VF2 Layout : The layout allocation as a subgraph isomorphism problem #6620
Conversation
If you update the retworkx line in the requirements.txt file to:
Then you can run the tests in CI. See: https://github.com/Qiskit/qiskit-terra/pull/6302/files#diff-4d7c51b1efe9043e44439a949dfd92e5827321b34082903477fd04876edb7552 for where I'm doing that on another PR that depends on an in progress retworkx commit. |
Co-authored-by: Matthew Treinish <[email protected]>
Hi @1ucian0, i'm afraid we need to tweak a bit import retworkx as rx
ga = rx.PyGraph()
ga.add_nodes_from([0, 1, 2])
ga.add_edges_from_no_data([
(0, 1), (1, 2), (2, 0)
])
gb = rx.PyGraph()
gb.add_nodes_from([0, 1, 2])
gb.add_edges_from_no_data([
(0, 1), (1, 2)
])
rx.is_subgraph_isomorphic(ga, gb)
---
False because the edge |
Adding a layout version of the same situation as a test... Once Qiskit/rustworkx#372 is merged, I can add the related adjustment here. Thanks! |
Co-authored-by: Matthew Treinish <[email protected]>
Co-authored-by: Matthew Treinish <[email protected]>
Co-authored-by: Matthew Treinish <[email protected]>
Co-authored-by: Matthew Treinish <[email protected]>
Co-authored-by: Matthew Treinish <[email protected]>
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 LGTM now, thanks for the updates. Before merging though I have 1 question inline about the docs and some nits in the tests (nothing blocking there though).
Co-authored-by: Matthew Treinish <[email protected]>
oh gosh. Indeed. Actually, this unveiled that most of the tests were doing nothing, as they graph gate is >2q. Fixed in b7eb52c .
I guess it's a problem for later. For now, the pass only works with 2q. Anything >2q, raises. |
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.
I just realized the docstrings need to be updated here, because the rendered docs would contain no detail on how the pass worked. I left a suggestion inline on how to fix it (hopefuilly I got the spacing right in the github editor). After that's fixed I think this is ready.
This commit updates the vf2layout docstrings to include details on how the pass works and the user expectations when using it. Previously this information was set in the module docstring which doesn't get rendered in the compiled documentation. This commit just moves these details to the class docstring and expands on it slightly.
On hold, depends on Qiskit/rustworkx#368 and Qiskit/rustworkx#375Exploring alternatives with @czachow on how to improve
CSPLayout
, we start reading more about subgraph isomorphism problem, in particular VF2. In this way, we noticed that, when VF2 finds an isomorphism a subgraph of G and H, also finds the mapping m that pairs the nodes in H with nodes in G. That mapping is they layout. @mtreinish and @georgios-ts wrote ais_subgraph_isomorphic
for retworkx some time ago using VF2 and they just need to expose m. This pass uses m to construct a matching subgraph, likeCSPLayout
but much faster.Features
This pass has the following features:
digraph_vf2_mapping
andgraph_vf2_mapping
.seed=-1
.The parameterid_order
is passed to the underling*graph_vf2_mapping
call. IfNone
activates id_order only if the problem is small (a subgraph to find with less than 300 edges).CSPLayout
, but faster.Performance
In order to illustrate the performance advantage, I used
timeit
in the following example:The result for this small case is noticible:
With the example from #5694 (where a trivial layout in Manhattan makes CSP timeout in level 2 and 3), the difference is huge:
Things to add
Noise awareness
Since this is so fast, probably would be better to add noise awareness a la #5075. For that, several possible solutions can be found and then calculate the fidelity. This can be done by a fidelity scoring pass (to add later)