-
Notifications
You must be signed in to change notification settings - Fork 47
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
fix wire swap handling in the creation of a phase poly box [TKET-1653] #146
Conversation
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 think that this is fine. I'm not sure that the way of looping to get rid of the qubit permutation is the fastest or most efficient in terms of CNOTs, although the latter matters less for the sake of phase polynomial synthesis.
|
||
qubit_map_t perm = newcirc.implicit_qubit_permutation(); | ||
for (const std::pair<const Qubit, Qubit>& pair : perm) { | ||
if (pair.first != pair.second) { |
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.
is it ever possible for the first and second qubits to be the same?
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.
Yes, that is the case when the wire is not involved in the permutation.
Could we use Zen's token swapping algorithm for an efficient way of putting in explicit swaps from the implicit qubit permutation? This problem is just decomposing an arbitrary element of the symmetric group Sn into transpositions. I don't know enough about Sn to know whether the above method of decomposition is the best one, but I assume it isn't. EDIT: So, let's assume g in Sn permutes m elements. Each call of the loop will remove at least 1 element from g, so overall at most m-1 transpositions are required (the last call will remove 2 elements). If we assume that g is a single cycle of length m then it will always require m-1 transpositions to decompose into, and so this algorithm is optimal in this case. This generalises to products of disjoint cycles straightforwardly, so I think the algorithm is optimal in terms of SWAP count. |
After thinking again a bit longer I still think that this is finding the optimal solution. In our idea you are missing the part, that cycles could overlap, which makes it a bit more difficult. I think that the important point is, that this is only modifying the ppb and not the circuit. The data stored in the ppb is independent from the specific circuit. Maybe there is a way to improve the decomposition of the ppb by using the swap algorithm in the case decomposing the box without aas or other special algorithms. But that requires maybe a bit more work to do that... |
No, every element in the symmetric group Sn can be expressed as a product of disjoint cycles. (It can also be expressed as a product of potentially overlapping cycles, eg. a product of transpositions.) |
Yes, I forgot that. Thank you! Are you taking a look if this fixes the other bug or should I do that? |
Fixes: [TKET-1653] No wireswap handling in the creation of a phase poly box #126
I have decided to add this in the creation of the phase poly box to make sure it is not used in other cases. This is probably very inefficient in other cases, the efficient solution is found in the decomposition of the ppb.