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

[TKET-1598] fix ConnectivityPredicate fails after FullPeepholeOptimise and AASRouting #194

Merged
merged 3 commits into from
Feb 3, 2022

Conversation

cqc-melf
Copy link
Contributor

@cqc-melf cqc-melf commented Feb 2, 2022

This is fixing #97

The problem has been a wrong handling of the implicit wire swaps in the aas pass

@cqc-melf cqc-melf requested a review from alexcowtan February 2, 2022 17:30
tket/src/Predicates/include/Predicates/PassGenerators.hpp Outdated Show resolved Hide resolved
Comment on lines 750 to 762
while (circ.has_implicit_wireswaps()) {
bool foundswap = false;

qubit_map_t perm = circ.implicit_qubit_permutation();
for (const std::pair<const Qubit, Qubit> &pair : perm) {
if (pair.first != pair.second) {
if (!foundswap) {
circ.replace_implicit_wire_swap(pair.first, pair.second);
foundswap = true;
}
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the foundswap variable really necessary? Can you not do something like:

Suggested change
while (circ.has_implicit_wireswaps()) {
bool foundswap = false;
qubit_map_t perm = circ.implicit_qubit_permutation();
for (const std::pair<const Qubit, Qubit> &pair : perm) {
if (pair.first != pair.second) {
if (!foundswap) {
circ.replace_implicit_wire_swap(pair.first, pair.second);
foundswap = true;
}
}
}
}
while (circ.has_implicit_wireswaps()) {
qubit_map_t perm = circ.implicit_qubit_permutation();
for (const std::pair<const Qubit, Qubit> &pair : perm) {
if (pair.first != pair.second) {
circ.replace_implicit_wire_swap(pair.first, pair.second);
}
}
}
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Without the variable only one swap will create an infinity loop. The replace_implicit_wire_swap will remove one implicit wire swap and then add it again in the next iteration of the loop where 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.

Ah, okay. Would it be slightly faster then to have a break rather than keep iterating through the loop but not replacing the swaps?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have added that.

@cqc-melf cqc-melf requested a review from alexcowtan February 3, 2022 08:56
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.

Looks good to me.

@cqc-melf cqc-melf merged commit d3ab84b into develop Feb 3, 2022
@cqc-melf cqc-melf deleted the bugfix/aas-no-wireswap-predicate branch February 3, 2022 14:49
@cqc-melf cqc-melf linked an issue Feb 3, 2022 that may be closed by this pull request
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.

ConnectivityPredicate fails after FullPeepholeOptimise and AASRouting
2 participants