-
Notifications
You must be signed in to change notification settings - Fork 48
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
Greedy topological sort of the binst graph to minimize qubit allocations / deallocations #1099
Conversation
…ons / deallocations
if TYPE_CHECKING: | ||
from qualtran import BloqInstance | ||
|
||
_INFINITY: int = int(1e18) |
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.
float('inf')
?
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.
Eventually, I want to set _INFINITY + binst.i
as the priority instead of _INFINITY
; assuming we can make binst.i
preserve insertion order following #1098
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.
In that case, a name other than "infinity" should be used if we're going to literally do "infinity + 1" as a meaningful distinction :p
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.
renamed
goal to minimize qubit allocations and deallocations by pushing allocations to the | ||
right and de-allocations to the left. | ||
""" | ||
yield from nx.lexicographical_topological_sort(binst_graph, key=_priority) |
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 function has slimmed down considerably! Thanks @anurudhp
@@ -65,20 +65,20 @@ def test_qpic_data_for_reflect_using_prepare(): | |||
reg_2 / \textrm{\scalebox{0.5}{QAny(2)}} | |||
reg_3:on G:width=25:shape=box \textrm{\scalebox{0.8}{alloc}} | |||
reg_3 / \textrm{\scalebox{0.5}{QAny(1)}} | |||
selection G:width=121:shape=box \textrm{\scalebox{0.8}{StatePreparationAliasSampling}} reg G:width=37:shape=box \textrm{\scalebox{0.8}{sigma\_mu}} reg_1 G:width=17:shape=box \textrm{\scalebox{0.8}{alt}} reg_2 G:width=21:shape=box \textrm{\scalebox{0.8}{keep}} reg_3 G:width=65:shape=box \textrm{\scalebox{0.8}{less\_than\_equal}} |
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.
should we scrap this test? I guess it sortof forces you to look at the circuit so you can paste in the new data but it's not very DAMP https://testing.googleblog.com/2019/12/testing-on-toilet-tests-too-dry-make.html
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.
removed
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.
please consider changing the documentation & name for "infinity" if we're going to be doing meaningful arithmetic on it
76af1a7
to
45971d1
Compare
This PR adds a new stable greedy topological sorting method and changes the default topological sort to use this method when iterating over nodes of a bloq instance graph.
This is useful to
Fixes the issue mentioned in #963 (comment), would be useful for #1097 and can be improved by addressing #1098