Skip to content

Conversation

@tanujkhattar
Copy link
Collaborator

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

  • Improve qubit cost analysis
  • Improve cirq-interop and minimize qubit allocations when specifying a GreedyQubitManager.

Fixes the issue mentioned in #963 (comment), would be useful for #1097 and can be improved by addressing #1098

if TYPE_CHECKING:
from qualtran import BloqInstance

_INFINITY: int = int(1e18)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

float('inf')?

Copy link
Collaborator Author

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

Copy link
Collaborator

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

Copy link
Collaborator Author

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)
Copy link
Collaborator

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

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}}
Copy link
Collaborator

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

Copy link
Collaborator

@mpharrigan mpharrigan left a 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

@tanujkhattar tanujkhattar enabled auto-merge (squash) July 6, 2024 00:53
@tanujkhattar tanujkhattar merged commit 19928a3 into quantumlib:main Jul 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants