-
Notifications
You must be signed in to change notification settings - Fork 51
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
Change build_call_graph in bloqs to return dict #1392
Change build_call_graph in bloqs to return dict #1392
Conversation
- 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.
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 |
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 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
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.
Done.
# Cost is $5(n_{p} - 1) + 2$ which comes from copying each $w$ component of $p$ | ||
# into an ancilla register ($3(n_{p}-1)$), copying the $r$ and $s$ bit of into an | ||
# ancilla ($2(n_{p}-1)$), controlling on both those bit perform phase flip on an | ||
# ancilla $|+\rangle$ state. This requires $1$ Toffoli, Then erase which costs | ||
# only Cliffords. There is an additional control bit controlling the application | ||
# of $T$ thus we come to our total. | ||
# Eq 73. page | ||
return {(Toffoli(), (5 * (self.num_bits_p - 1) + 2))} | ||
# Eq 73, page 20. |
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.
nice
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.
wow! great
didn't mean to conflict you. I'll try to fix them up quick |
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.