Skip to content

Add NLayout::compose method #14783

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

Closed
wants to merge 1 commit into from
Closed

Conversation

mtreinish
Copy link
Member

Summary

This commit adds a method to compose two NLayout objects in rust, this is something that we'll need when we do a full path compilation in Rust as we'll be working directly with NLayout and we'll potentially need to compose layouts depending on the passes that run.

Details and comments

@mtreinish mtreinish added this to the 2.2.0 milestone Jul 22, 2025
@mtreinish mtreinish requested a review from a team as a code owner July 22, 2025 18:48
This commit adds a method to compose two NLayout objects in rust, this
is something that we'll need when we do a full path compilation in Rust
as we'll be working directly with NLayout and we'll potentially need to
compose layouts depending on the passes that run.
@mtreinish mtreinish added Changelog: None Do not include in changelog Rust This PR or issue is related to Rust code in the repository mod: transpiler Issues and PRs related to Transpiler labels Jul 22, 2025
@qiskit-bot
Copy link
Collaborator

One or more of the following people are relevant to this code:

  • @Qiskit/terra-core

.iter()
.enumerate()
.for_each(|(virt_idx, phys)| {
new_v2p[virt_idx] = other_v2p[phys.index()];
Copy link
Member

Choose a reason for hiding this comment

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

It shouldn't be meaningful to index v2p using a physical qubit. Something is off here with the definition of composition and/or what the qubits represent.

Copy link
Member

@jakelishman jakelishman Jul 22, 2025

Choose a reason for hiding this comment

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

[to the] physical Q-qubits, and the other layout is a mapping from virtual Q-qubits to physical R-qubits

This part of the comment doesn't make sense. It's implying there's a hidden additional layout mapping between the physical qubits of self and the virtual qubits of other which is the indexwise identity. That largely violates what a virtual qubit is: it implies the second NLayout object is not a true layout mapping one space to another, but instead a permutation within the physical-qubit space.

Copy link
Member Author

Choose a reason for hiding this comment

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

That's fair the composition here that I need is really just for the routing permutation which I've been representing with Vec<PhysicalQubit>. I only put this in NLayout because I didn't really know where else to put this and we had the equivalent method in python's layout. But I agree it's not actually a good fit for the NLayout model I probably can just make this a standalone function for Vec<PhysicalQubit> and the only reason it's in python is because we're stuck using Layout for the permutation tracking.

Copy link
Member

Choose a reason for hiding this comment

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

I think it's fine on NLayout if that's convenient for the final layout, but let's just have it take a mapping [old] PhysicalQubit -> [new] PhysicalQubit (either as a slice or a generic over a function, or whatever) rather than another bidirectional layout object, so the mathematics is sound.

Copy link
Member Author

Choose a reason for hiding this comment

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

Writing the comment here made me realize this doesn't actually solve the problem I was intending to, since I was planning to keep routing_permutation as a Vec<PhysicalQubit> in TranspileLayout. Maybe the answer is to add TranspileLayout::compose_routing_permutation() instead since that's really what we need here. The goal of this was to have something to compose the permutations from ElidePermutations, Split2qUnitaries, and sabre for the return TranspileLayout.

@coveralls
Copy link

Pull Request Test Coverage Report for Build 16452886889

Details

  • 97 of 97 (100.0%) changed or added relevant lines in 1 file are covered.
  • 6 unchanged lines in 2 files lost coverage.
  • Overall coverage increased (+0.01%) to 87.792%

Files with Coverage Reduction New Missed Lines %
crates/circuit/src/symbol_expr.rs 2 73.9%
crates/qasm2/src/lex.rs 4 92.01%
Totals Coverage Status
Change from base Build 16420779601: 0.01%
Covered Lines: 81584
Relevant Lines: 92929

💛 - Coveralls

@mtreinish
Copy link
Member Author

I'm going to close this and just embed this into #14778

@mtreinish mtreinish closed this Jul 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelog: None Do not include in changelog mod: transpiler Issues and PRs related to Transpiler Rust This PR or issue is related to Rust code in the repository
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants