-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Publically expose QuantumCircuit._layout
and add helper functions for working with embedded layout
#8803
Comments
I think Another piece it would be good to discuss before we finalize this direction is whether or not to include pre/post |
I'm not convinced that I'm nervous about us suddenly applying important meaning to
Putting the mapping to hardware qubits in that dictionary seems to me to be a violation of the idea that (Technically there's typing syntax to mitigate some of that last point, if you're prepared to reserve a key in |
All that's to say that my vote is to use a public |
I would like to add a comment here to explain an observation that I made a few weeks ago. Specifically, I was working with the primitives and wanted to skip transpilation on the server side. This meant, that I had to transpile my circuit locally and set the corresponding option in my primitive job. However, this immediately led to the problem that my (now physical) circuit contained a different number of qubits than my operator resulting in errors (obviously). I could not find a builtin way of how to deal with this situation (that is to say, I did not find a transformation method which would map my qubit operator to the correct set of physical qubits) so I ended up using the private There must be some similar code running somewhere on the server side but I did not find that. All that is to say:
|
Max: can you make the operator form before the transpilation? Seems like that'd save you both simulation cost, and solve your problem. Transpilation shouldn't affect the matrix representation (including global phase, although I know some of the higher-level synthesis stuff might be missing that right now), except for re-mapping some of the qubits, and that can be fixed on the edit: I misunderstood what was going on a little bit - I was thinking needing matrix representations of the circuit and the operator, rather than the operator still being in a circuit or |
@mrossinek fwiw, this kind of thing is the intent of the But, yeah I think we all agree that the point here is that the |
I'm also in favor of using a The other reason is having a separate attribute will let us clearly document the attribute. We can write a detailed description of the what the layout (as at this point it's really initial layout, input qubit mapping, and final layout) is and examples on how to use it. Having a place we can point people to to explain all of this I think will be quite valuable because explaining layout and routing as permutations can sometimes be confusing. |
See my comment from May of last year that touches on the same issue: |
Since the Qiskit 0.9.0 release the QuantumCircuit has had a private `_layout` attribute which is used to track the permutations introduced to a circuit by the transpiler. At the time this was made private because we didn't want to commit to an interface on this at the time until a dedicated API could be introduced (see Qiskit#2853). However, since that time ~4 years ago we've never introduced an alternative public interface for `_layout` was never introduced. This has left users needing to reason about the permutation caused by transpile() in a weird place because the only mechanism to do this is private. This commit adds a public read-only attribute `.layout` to solve this, which just exposes the previously private `._layout` attribute via a documented and public interface. Unlike from 0.9.x through 0.21.x we introduced a new data class container `TranspileLayout` as part of the 0.22.0 release which _layout was updated to use at the time. Having a dedicated class used for the field gives us a certain degree of flexibility to evolve the interface over time if needed. Right now it contains 3 pieces of information the initial layout caused by the layout phase of transpile(), the input qubit mapping to figure out the qubit index on the original circuit, and the final layout caused by swaps inserted during routing. Closes Qiskit#8803
* Add public layout attribute to QuantumCircuit Since the Qiskit 0.9.0 release the QuantumCircuit has had a private `_layout` attribute which is used to track the permutations introduced to a circuit by the transpiler. At the time this was made private because we didn't want to commit to an interface on this at the time until a dedicated API could be introduced (see Qiskit#2853). However, since that time ~4 years ago we've never introduced an alternative public interface for `_layout` was never introduced. This has left users needing to reason about the permutation caused by transpile() in a weird place because the only mechanism to do this is private. This commit adds a public read-only attribute `.layout` to solve this, which just exposes the previously private `._layout` attribute via a documented and public interface. Unlike from 0.9.x through 0.21.x we introduced a new data class container `TranspileLayout` as part of the 0.22.0 release which _layout was updated to use at the time. Having a dedicated class used for the field gives us a certain degree of flexibility to evolve the interface over time if needed. Right now it contains 3 pieces of information the initial layout caused by the layout phase of transpile(), the input qubit mapping to figure out the qubit index on the original circuit, and the final layout caused by swaps inserted during routing. Closes Qiskit#8803 * Fix typo in QuantumCircuit.layout docs * Disable cyclic import check on conditional type hint import
* Add public layout attribute to QuantumCircuit Since the Qiskit 0.9.0 release the QuantumCircuit has had a private `_layout` attribute which is used to track the permutations introduced to a circuit by the transpiler. At the time this was made private because we didn't want to commit to an interface on this at the time until a dedicated API could be introduced (see Qiskit#2853). However, since that time ~4 years ago we've never introduced an alternative public interface for `_layout` was never introduced. This has left users needing to reason about the permutation caused by transpile() in a weird place because the only mechanism to do this is private. This commit adds a public read-only attribute `.layout` to solve this, which just exposes the previously private `._layout` attribute via a documented and public interface. Unlike from 0.9.x through 0.21.x we introduced a new data class container `TranspileLayout` as part of the 0.22.0 release which _layout was updated to use at the time. Having a dedicated class used for the field gives us a certain degree of flexibility to evolve the interface over time if needed. Right now it contains 3 pieces of information the initial layout caused by the layout phase of transpile(), the input qubit mapping to figure out the qubit index on the original circuit, and the final layout caused by swaps inserted during routing. Closes Qiskit#8803 * Fix typo in QuantumCircuit.layout docs * Disable cyclic import check on conditional type hint import
* Add public layout attribute to QuantumCircuit Since the Qiskit 0.9.0 release the QuantumCircuit has had a private `_layout` attribute which is used to track the permutations introduced to a circuit by the transpiler. At the time this was made private because we didn't want to commit to an interface on this at the time until a dedicated API could be introduced (see Qiskit#2853). However, since that time ~4 years ago we've never introduced an alternative public interface for `_layout` was never introduced. This has left users needing to reason about the permutation caused by transpile() in a weird place because the only mechanism to do this is private. This commit adds a public read-only attribute `.layout` to solve this, which just exposes the previously private `._layout` attribute via a documented and public interface. Unlike from 0.9.x through 0.21.x we introduced a new data class container `TranspileLayout` as part of the 0.22.0 release which _layout was updated to use at the time. Having a dedicated class used for the field gives us a certain degree of flexibility to evolve the interface over time if needed. Right now it contains 3 pieces of information the initial layout caused by the layout phase of transpile(), the input qubit mapping to figure out the qubit index on the original circuit, and the final layout caused by swaps inserted during routing. Closes Qiskit#8803 * Fix typo in QuantumCircuit.layout docs * Disable cyclic import check on conditional type hint import
What should we add?
As discussed in #8800 the way we're embedding the
Layout
from the transpiler into the output quantum circuit is a bit of a weird place right now. We have a private attribute_layout
which is used widely across the qiskit code but we provide no public or supported interface for working with this. This came to be an issue for fixing #8800 because to fix the issue we changed what was stored in the_layout
attribute, and while it is a private layout external users depend on it because it was the only way to reason about the permutation caused by initial layout in the transpiler. To address this gap in 0.23.0 we should introduce a publicQuantumCircuit.layout
attribute and/or also have methods to work with the embedded layout. Like something to return the qargs for the circuit.The text was updated successfully, but these errors were encountered: