Skip to content

Conversation

@dstrain115
Copy link
Contributor

  • This changes the build_call_graph function within bloqs in qualtran to return a dictionary of cost counts rather than a set.
  • This will allow the ordering of cost counts to be deterministic

Note that this requires some slight code changes for bloqs that have multiple set items since (Toffoli(), 1) and (Toffoli(), 2) would have two different items in a set, but share an index in the dictionary.

This also may alter counts (i.e. fix a bug) where set items clobber each other. For instance, adding (Toffoli(), self.bits_a) and (Toffoli(), self.bits_b) will previously give the wrong count if bits_a == bits_b since the two items would be the same in the set.

- This changes the build_call_graph function within bloqs
in qualtran to return a dictionary of cost counts rather than
a set.
- This will allow the ordering of cost counts to be deterministic

Note that this requires some slight code changes for bloqs
that have multiple set items since (Toffoli(), 1) and (Toffoli(), 2)
would have two different items in a set, but share an index in the
dictionary.

This also may alter counts (i.e. fix a bug) where set items clobber
each other.  For instance, adding (Toffoli(), self.bits_a) and
(Toffoli(), self.bits_b) will previously give the wrong count
if bits_a == bits_b since the two items would be the same in the
set.
Comment on lines 84 to 93
cost[SignedIntegerToTwosComplement(self.num_bits_p)] += 3
cost[SignedIntegerToTwosComplement(self.num_bits_n)] += 3
# Adding nu into p / q. Nu is one bit larger than p.
cost_add_p = (Add(QInt(self.num_bits_p + 1)), 3)
cost_add_n = (Add(QInt(self.num_bits_n + 1)), 3)
cost_ctrl_add_p = (Toffoli(), 3 * (self.num_bits_p + 1))
cost_ctrl_add_n = (Toffoli(), 3 * (self.num_bits_n + 1))
cost[Add(QInt(self.num_bits_p + 1))] += 3
cost[Add(QInt(self.num_bits_n + 1))] += 3
cost[Toffoli()] += 3 * (self.num_bits_p + 1)
cost[Toffoli()] += 3 * (self.num_bits_n + 1)
# + 2 as these numbers are larger from addition of $\nu$
cost_inv_tc_p = (SignedIntegerToTwosComplement(self.num_bits_p + 2), 3)
cost_inv_tc_n = (SignedIntegerToTwosComplement(self.num_bits_n + 2), 3)
cost[SignedIntegerToTwosComplement(self.num_bits_p + 2)] += 3
cost[SignedIntegerToTwosComplement(self.num_bits_n + 2)] += 3
Copy link
Collaborator

Choose a reason for hiding this comment

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

i feel like there may be some information lost by removing those variable names? Not blocking, but maybe include in comments, eg the cost[Toffoli()] += 3 * self.num_bits_p is for ctrl_add_p which isn't otherwise obvious

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

# of $T$ thus we come to our total.
# Eq 73. page
return {(Toffoli(), (5 * (self.num_bits_p - 1) + 2))}
# Eq 73, page 20.
Copy link
Collaborator

Choose a reason for hiding this comment

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

nice

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.

wow! great

@mpharrigan
Copy link
Collaborator

didn't mean to conflict you. I'll try to fix them up quick

@dstrain115 dstrain115 merged commit 488b9a5 into quantumlib:main Sep 7, 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.

2 participants