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 DenseLayout when loose bits are present in input circuit #8843

Merged
merged 2 commits into from
Oct 6, 2022

Conversation

mtreinish
Copy link
Member

Summary

This commit fixes the DenseLayout transpiler pass to correctly handle when an input circuit contains loose bits. Previously the pass would incorrectly assume there was always a register in the circuit and only construct the output layout with registers. This caused the pass to return an empty layout if there were no quantum registers present in the circuit, even if there were qubits in the circuit. This commit fixes this by creating the layout per qubit and then only adding the registers as metadata to the layout after the fact.

Details and comments

This commit fixes the DenseLayout transpiler pass to correctly handle
when an input circuit contains loose bits. Previously the pass would
incorrectly assume there was always a register in the circuit and only
construct the output layout with registers. This caused the pass to
return an empty layout if there were no quantum registers present in the
circuit, even if there were qubits in the circuit. This commit fixes
this by creating the layout per qubit and then only adding the registers
as metadata to the layout after the fact.
@mtreinish mtreinish added the Changelog: Bugfix Include in the "Fixed" section of the changelog label Oct 6, 2022
@mtreinish mtreinish requested a review from a team as a code owner October 6, 2022 16:47
@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:

  • @Qiskit/terra-core

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.

Nice, thanks!

for qreg in dag.qregs.values():
for i in range(qreg.size):
layout[qreg[i]] = int(best_sub[map_iter])
map_iter += 1
layout.add_register(qreg)
Copy link
Member

Choose a reason for hiding this comment

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

I don't even know why Layout tracks registers, but it does seem to be part of the interface, so best to keep it. I'm guessing it's from before, when registers owned qubits.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, neither am I, and tbh I don't think it is 100% needed here anymore as without this all the tests passed, but I kept it in just in case there was something I wasn't considering.

@jakelishman jakelishman added this to the 0.22 milestone Oct 6, 2022
@coveralls
Copy link

Pull Request Test Coverage Report for Build 3199091475

  • 2 of 2 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.1%) to 84.724%

Totals Coverage Status
Change from base Build 3198732207: 0.1%
Covered Lines: 61698
Relevant Lines: 72822

💛 - Coveralls

@mergify mergify bot merged commit 50db8f5 into Qiskit:main Oct 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelog: Bugfix Include in the "Fixed" section of the changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants