Skip to content

Conversation

ewinston
Copy link
Contributor

@ewinston ewinston commented Jun 16, 2022

Summary

This pr adds controlflow handling to the BasicSwap router.

Details and comments

if_else: add swaps to match layouts of both blocks
for, while: add swaps to match final layout to be same as initial layout
improvements on this scheme to come in future prs.

Fixes #9430

ewinston added 3 commits June 16, 2022 16:30
minor commit

minor commit

minor commit
layout on measure

revamp current_layout tracking

minor commit
@ewinston ewinston requested a review from a team as a code owner June 16, 2022 20:38
@qiskit-bot
Copy link
Collaborator

Thank you for opening a new pull request.

Before your PR can be merged it will first need to pass continuous integration tests and be reviewed. Sometimes the review process can be slow, so please be patient.

While you're waiting, please feel free to review other open PRs. While only a subset of people are authorized to approve pull requests for merging, everyone is encouraged to review open pull requests. Doing reviews helps reduce the burden on the core team and helps make the project's code better for everyone.

One or more of the the following people are requested to review this:

@coveralls
Copy link

coveralls commented Jun 16, 2022

Pull Request Test Coverage Report for Build 2914461973

  • 135 of 145 (93.1%) changed or added relevant lines in 4 files are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage increased (+0.02%) to 84.14%

Changes Missing Coverage Covered Lines Changed/Added Lines %
qiskit/dagcircuit/dagcircuit.py 0 1 0.0%
qiskit/transpiler/passes/routing/basic_swap.py 51 52 98.08%
qiskit/transpiler/passes/routing/utils.py 83 91 91.21%
Files with Coverage Reduction New Missed Lines %
qiskit/dagcircuit/dagcircuit.py 1 89.03%
Totals Coverage Status
Change from base Build 2913991236: 0.02%
Covered Lines: 56759
Relevant Lines: 67458

💛 - Coveralls

@ewinston
Copy link
Contributor Author

ewinston commented Jun 20, 2022

I ran a benchmark using red-queen to check the effect on circuits which don't have flow control.

There were 151 circuits but 30 of those circuits had errors currently with this pr. Ignoring the errored circuits the results were as follows,

image

The orange data is from this pr. On average,
main: 14.2
this pr: 7.0
There seems to be an unexpected improvement...will look into further.

ewinston and others added 5 commits July 12, 2022 14:25
Co-authored-by: Tan Jun Liang <43441314+poig@users.noreply.github.com>
Co-authored-by: Tan Jun Liang <43441314+poig@users.noreply.github.com>
@ewinston ewinston changed the title [WIP] add controlflow to basic_swap router add controlflow to basic_swap router Jul 13, 2022
Copy link
Member

@kdk kdk 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 so far, a few questions below.

sim = Aer.get_backend("aer_simulator")
in_results = sim.run(qc, shots=4096).result().get_counts()
out_results = sim.run(cqc, shots=4096).result().get_counts()
self.assertEqual(set(in_results), set(out_results))
Copy link
Member

Choose a reason for hiding this comment

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

Do we have a utility function to test if a physical circuit is compliant with a given coupling_map? If not, this would be useful in verifying the outputs circuits here.

Copy link
Member

Choose a reason for hiding this comment

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

For a target (which is superset of the coupling map) we have https://github.com/Qiskit/qiskit-terra/blob/main/test/python/providers/test_backend_v2.py#L43-L53 which I was using to validate the full transpile() pipe line was valid

Copy link
Member

@jakelishman jakelishman left a comment

Choose a reason for hiding this comment

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

I added one comment, but I think this PR isn't currently synced with your local state, perhaps - there's some breakpoint statements left, and bits of the continue/break handling left in. I'll wait for you to ping before reviewing again (and similar on stochastic swap).

Comment on lines +137 to +139
The coupling_map is converted to the virtual qubits of the current layout."""
new_coupling = layout_transform(self.coupling_map, current_layout)
_pass = self.__class__(new_coupling, initial_layout=None)
Copy link
Member

@jakelishman jakelishman Sep 2, 2022

Choose a reason for hiding this comment

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

I'm really not a fan of co-opting CouplingMap to be over virtual qubits instead of physical qubits (mentioned on the other PR as well). Coupling maps are specifically of physical qubits - it's explicitly in the docstring of the class, and that gives a proper separation of concerns between mutable Layouts and the fixed underlying hardware.

It's difficult for me to reason about the correctness of the logic if the coupling map doesn't represent the actual physical connections, and it feels like it opens lots of opportunities for bugs when converting between the "physical" qubits of the control-flow routing and the outer-circuit routing. In this case, can we keep the coupling map fixed, and start the inner routing from the current layout? That feels much more natural to me, and it uses the classes as intended.

Comment on lines +125 to +131
if cf_layer or (subdag.depth() == 1 and subdag.op_nodes()[0].name == "continue_loop"):
order = current_layout.reorder_bits(new_dag.qubits)
new_dag.compose(subdag, qubits=order)
current_layout = cf_layout
else:
order = current_layout.reorder_bits(new_dag.qubits)
new_dag.compose(subdag, qubits=order)
Copy link
Member

Choose a reason for hiding this comment

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

This still has continue-loop handling in it right now.

@ewinston
Copy link
Contributor Author

ewinston commented Sep 9, 2022

putting this on hold until after #8418

@ewinston ewinston added the on hold Can not fix yet label Sep 9, 2022
@1ucian0
Copy link
Member

1ucian0 commented Apr 5, 2024

with #8418 merged, removing on hold

@1ucian0 1ucian0 removed the on hold Can not fix yet label Apr 5, 2024
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.

Support control flow in BasicSwap
8 participants