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

Update LexiRoute::reassign_node to use Ancilla Node #715

Merged
merged 53 commits into from
Jan 17, 2023

Conversation

sjdilkes
Copy link
Contributor

@sjdilkes sjdilkes commented Jan 6, 2023

See TKET-2761. In Routing the Qubit UnitID objects in a Circuit are relabelled to Node objects from the Architecture the Circuit is being routed to be compatible with. There are scenarios where a Qubit is labelled as one Node, but we can freely relabel it to another Node if the Node it is already assigned to is more helpful being used elsewhere. In this case we need to relabel the first Qubit to another Node on the Architecture that is not already in use.
When we do this, the logic in LexiRoute::reassign_node only checks for Node in the Architecture that aren't in use and relabels to them. However, it is possible there are no "free" Node in the Architecture as they have been used as ancillas. This PR updates LexiRoute::reassign_node to relabel to an ancilla Node if there are no "free" Node left to use.

Boolean edges don't respect linearity, but bundles do. Remove extraneous code.
Hopefully reduce branching, at least make more readable
Leaving comments as waiting to see if CI passes before removing
@sjdilkes sjdilkes requested a review from yao-cqc January 16, 2023 10:02
Copy link
Contributor

@yao-cqc yao-cqc 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. Only a few comments. Also a changelog entry would be helpful.

}

// "assignee" is Circuit UnitID being relabelled to UnitID "replacement"
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe document this in the header file? This seems to be the only method without a docstring.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, done

SCENARIO(
"Test relabelling a Circuit UnitID that is an Architecture Node but "
"reassignable to an Ancilla Node.") {
GIVEN("Line Architecture, one reassignment.") {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add some comments explaining why some UnitID have been reassigned to an ancilla? My next comment is related to this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately the condition in which this occurs is rather niche. I've added a small explanation to the test:
• If a non-labelled Qubit in a Circuit being mapped has no Quantum gates with physical constraints (i.e. mostly multi-qubit gates) then before mapping we assign it some "bad" Architecture Node (typically something on the edge of the coupling graph with low out-degree)
• Any non-labelled Qubit in a Circuit with Quantum gates with physical constraints are left unlabelled
• During mapping, if a multi-qubit gate with a non-labelled Qubit is encountered we need to allocate it to some best Architecture Node
• In some cases, this best Node may end up being a "bad" Node we've used to assign an "unimportant" (without connectivity graph related physical constraints) Qubit too. If this is the case we relabel the unlabelled Qubit to this best Node and find a new Node to assign the "unimportant" Qubit to
• Ideally we just find a spare Architecture Node that hasn't previously been assigned to and reassign the "unimportant" Qubit to it. However in some cases there can be no spare Architecture Node as they have been used as ancilla Node for SWAP/BRIDGE gates
• This is the case that was not considered before - the assertion is basically saying "there should always be a spare Architecture Node" but this is not true (this isn't in the comments)
• In this case we take an Ancilla Node and wire its output to the input of the "unimportant" Qubit Path, essentially reassigning it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks! this is much appreciated.

PassPtr r_p = gen_routing_pass(
architecture, {std::make_shared<LexiLabellingMethod>(),
std::make_shared<LexiRouteRoutingMethod>()});
REQUIRE(r_p->apply(cu));
Copy link
Contributor

Choose a reason for hiding this comment

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

I think REQUIRE(r_p->apply(cu)); (also in the other new tests) doesn't say much. Are there anything else we can check to prevent future regression?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed, as essentially it's confirming no assertion is made. I can try and make it slightly more secure by checking the bimap returned during compilation has qubits relabelled as expected.

@sjdilkes sjdilkes requested a review from yao-cqc January 17, 2023 11:42
@cqc-alec cqc-alec merged commit cccf282 into develop Jan 17, 2023
@cqc-alec cqc-alec deleted the routing-assertion branch January 17, 2023 13:45
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.

3 participants