Closed chcfz closed 1 month ago
The current_swaps.drain(..)
is deliberately throwing away those swaps without adding them to the out_map
; the for_each(|swap| state.apply_swap(swap))
is undoing that set. We deliberately throw those away because those swaps didn't cause any progress, and now there's loads of them. state.force_enable_closest_node
then re-populates current_swaps
with a set of swaps that definitely makes progress, starting from the last progress point, and then those are the ones that are added to out_map
.
Do you have an example system where you can show a broken output?
The
current_swaps.drain(..)
is deliberately throwing away those swaps without adding them to theout_map
; thefor_each(|swap| state.apply_swap(swap))
is undoing that set. We deliberately throw those away because those swaps didn't cause any progress, and now there's loads of them.state.force_enable_closest_node
then re-populatescurrent_swaps
with a set of swaps that definitely makes progress, starting from the last progress point, and then those are the ones that are added toout_map
.Do you have an example system where you can show a broken output?
Oh,sry. It's my fault, I was misunderstanding why doing state.apply_swap
before do force route.
I am doing some changes in sabre routing, i fixed this bug(now i know it's not) along with another(the real bug) in my code.
Thank u for ur reply and sorry again for my mistake
No worries, thanks for the interest!
Environment
What is happening?
In Sabre routing, when the program doing force routing, it will call drain to get an iter of current_swaps and then get a force routed node, but because of the feature of drain, these swaps in current_swaps will not be inserted to out_maps, which will lead to an wrong transpiled circuit.
force routing (574 in route.rs)
update_route (110 in route.rs) which insert current swaps to out_map
How can we reproduce the issue?
As saying in comments, it never happen unless we're unlucky. an easy way to reproduce is setting the max_iterations_without_progress smaller to make the program doing force route
What should happen?
even doing force swap, current swaps will be still insert to out_map
Any suggestions?
not using drain to get an iter