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

Upgrade TranspileLayout #9535

Closed
wants to merge 1 commit into from

Conversation

pedrorrivero
Copy link
Member

@pedrorrivero pedrorrivero commented Feb 4, 2023

Summary

Upgrades TranspileLayout class adding one more field (i.e. output_qubit_mapping), a property, and a few convenience methods.

Details and comments

Field:

  • output_qubit_mapping is added in order to make TranspileLayout self contained; meaning that it will not need to know about the (transpiled) circuit that it as attached to in order to understand its final_layout field. This mimics the way input_qubit_mapping allows interpretation of initial_layout.

Property:

  • num_qubits is added as a convenient way to assess the number of qubits involved in the layout. Notice that checking the size of a dictionary is an $\mathcal{O}(1)$ operation, which justifies making this a property instead of a regular method (no computation is performed, only retrieval).

Methods:

  • get_initial_permutation allows retrieval of the permutation performed by initial_layout.
  • get_final_permutation allows retrieval of the permutation performed by final_layout.
  • get_complete_permutation allows retrieval of the composed permutation from initial_layout and final_layout (in order).
  • get_complete_layout allows retrieval of the complete layout that results from composing initial_layout and final_layout.

#9486 should be updated accordingly

@pedrorrivero pedrorrivero requested review from a team and ikkoham as code owners February 4, 2023 13:05
@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:

Copy link
Member Author

@pedrorrivero pedrorrivero left a comment

Choose a reason for hiding this comment

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

Kindly share your feedback @mtreinish @jakelishman @jlapeyre.

Please double check that I updated the three TranspileLayout instances appropriately.

"""Get final permutation from final layout."""
inverted_output_mapping = {i: q for q, i in self.output_qubit_mapping.items()}
output_qubits = tuple(inverted_output_mapping[i] for i in range(self.num_qubits))
final_layout = self.final_layout or Layout(self.output_qubit_mapping)
Copy link
Member Author

@pedrorrivero pedrorrivero Feb 4, 2023

Choose a reason for hiding this comment

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

An example of why setting final_layout to None instead of the trivial layout adds complexity @jakelishman @jlapeyre.

I would personally advocate for enforcing it (i.e. final_layout: Layout instead of final_layout: Optional[Layout] = None). Note that the trivial layout is actually trivial to build from output_qubit_mapping so, alternatively, this could be parsed automatically through __post_init__ or even retrieved through a getter.

@jakelishman
Copy link
Member

I think this was obsoleted by #10835, but feel free to re-open if there's more to discuss.

@jakelishman jakelishman closed this Jan 8, 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.

3 participants