Skip to content
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

Merged
merged 3 commits into from
Jan 4, 2022

Conversation

cqc-melf
Copy link
Contributor

@cqc-melf cqc-melf commented Dec 7, 2021

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.

@cqc-melf cqc-melf requested a review from alexcowtan December 8, 2021 09:20
Copy link
Contributor

@alexcowtan alexcowtan left a 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) {
Copy link
Contributor

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?

Copy link
Contributor Author

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.

@alexcowtan
Copy link
Contributor

alexcowtan commented Jan 2, 2022

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.

@cqc-melf
Copy link
Contributor Author

cqc-melf commented Jan 4, 2022

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...

@cqc-melf cqc-melf merged commit 61b2d75 into develop Jan 4, 2022
@cqc-melf cqc-melf deleted the bugfix/wireswapppb branch January 4, 2022 11:48
@alexcowtan
Copy link
Contributor

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.

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.)

@cqc-melf
Copy link
Contributor Author

cqc-melf commented Jan 4, 2022

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?

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