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

✨ Support for Qiskit's final_layout #439

Closed
burgholzer opened this issue Oct 14, 2023 · 1 comment · Fixed by #592
Closed

✨ Support for Qiskit's final_layout #439

burgholzer opened this issue Oct 14, 2023 · 1 comment · Fixed by #592
Labels
Core Anything related to the Core library and IR feature New feature or request good first issue Good for newcomers python Anything related to Python code
Milestone

Comments

@burgholzer
Copy link
Member

What's the problem this feature will solve?

When reasoning about quantum circuits there are two degrees of freedom that can always lead to problems/confusion:
An arbitrary permutation of a circuit's qubits might be applied at the very beginning of the circuit (referred to as an "initial layout") or at the end of the circuit (referred to as an "output permutation").
In almost any case, a circuit containing such permutations would still be considered equivalent to a circuit without such permutations.
This is especially relevant for verifying the equivalence of quantum circuits and the results of compilation flows in particular.

For a long time, Qiskit has supported a _layout property for its QuantumCircuit objects that captured the initial layout applied during compilation. Within the MQT we use this property to infer the initialLayout for our QuantumComputation objects.
In 0.22.0 (which is now our minimum supported version), Qiskit changed the _layout property to a proper TranspileLayout class.
0.23.0 introduced an additional final_layout component that (in some confusing fashion) captures the output permutation.
This should allow to also infer the output permutation from Qiskit.
Right now, we use the measurements in a circuit for that purpose, which is rathe prone to errors (e.g., someone not adding measurements to their circuit before compilation).

Describe the solution you'd like

Starting with 0.45.0. (which should be the next minor release), the ergonomics of the TranspileLayout class have been considerably improved (see Qiskit/qiskit#10835).
That should yield a blueprint for how to interpret the final_layout and to infer the outputPermutation from Qiskit circuits.

A potential solution would first look if the final_layout attribute is present.
If so, it would check whether the new convenient syntax (>=0.45.0) is available.
If not, it replicates the logic to parse the output permutation.
If no final layout is present, the solution should check for measurements in the circuit and infer the output permutation from there (as it currently does).

@burgholzer burgholzer added good first issue Good for newcomers feature New feature or request Core Anything related to the Core library and IR python Anything related to Python code labels Oct 14, 2023
@burgholzer burgholzer added this to the MQT Core milestone Oct 14, 2023
@burgholzer burgholzer added this to MQT and MQT Core Oct 14, 2023
@burgholzer burgholzer moved this to Todo in MQT Oct 14, 2023
@burgholzer burgholzer moved this to Todo in MQT Core Oct 14, 2023
@burgholzer
Copy link
Member Author

Since this issue's creation, Qiskit 1.0 has been released and we moved to depend on it.
As a consequence, implementing this should become a lot easier, as no conditional logic based on the Qiskit version is required.

TeWas added a commit to TeWas/mqt-core that referenced this issue Apr 18, 2024
burgholzer pushed a commit to TeWas/mqt-core that referenced this issue Apr 20, 2024
burgholzer pushed a commit to TeWas/mqt-core that referenced this issue Apr 20, 2024
burgholzer added a commit that referenced this issue Apr 20, 2024
## Description

This PR adds support for Qiskit's `final_layout` attribute when
importing circuits from Qiskit. It interprets the `output_permutation`
of an MQT `QuantumComputation` object based on Qiskit's
`final_index_layout()`, which maps the original input circuit's qubit
indices to the final physical qubit indices after routing. This mapping
is the result of applying `routing_permutation()` to the
`initial_layout`. Additionally, it fixes the interpretation of the
output_permutation in `initializeIOMapping()` to align with Qiskit's
final_layout.

Fixes #439


## Checklist:

<!---
This checklist serves as a reminder of a couple of things that ensure
your pull request will be merged swiftly.
-->

- [x] The pull request only contains commits that are related to it.
- [x] I have added appropriate tests and documentation.
- [x] I have made sure that all CI jobs on GitHub pass.
- [x] The pull request introduces no new warnings and follows the
project's style guidelines.

---------

Signed-off-by: burgholzer <burgholzer@me.com>
Co-authored-by: burgholzer <burgholzer@me.com>
@github-project-automation github-project-automation bot moved this from Todo to Done in MQT Core Apr 20, 2024
@github-project-automation github-project-automation bot moved this from Todo to Done in MQT Apr 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Core Anything related to the Core library and IR feature New feature or request good first issue Good for newcomers python Anything related to Python code
Projects
Archived in project
Archived in project
Development

Successfully merging a pull request may close this issue.

1 participant