cda-tum / mqt-core

MQT Core - The Backbone of the Munich Quantum Toolkit
https://mqt.readthedocs.io/projects/core
MIT License
62 stars 31 forks source link

Hybrid Neutral Atom Mapper Functionality #610

Closed lsschmid closed 5 months ago

lsschmid commented 6 months ago

Add Hybrid NA Mapper Functionality

This adds two things:

  1. Move operation: Abstract operation describing the movement of an atom from one coordinate to another.
  2. AodOperation: Describing the movements of the AOD to perform the above Move operation. The dump to qasm returns a format similar to qasm.

Checklist:

codecov[bot] commented 6 months ago

Codecov Report

Attention: Patch coverage is 94.11765% with 6 lines in your changes missing coverage. Please review.

Project coverage is 91.5%. Comparing base (42005a9) to head (8c2f230). Report is 106 commits behind head on main.

Files with missing lines Patch % Lines
include/mqt-core/operations/AodOperation.hpp 91.6% 3 Missing :warning:
src/operations/StandardOperation.cpp 0.0% 3 Missing :warning:
Additional details and impacted files [![Impacted file tree graph](https://app.codecov.io/gh/cda-tum/mqt-core/pull/610/graphs/tree.svg?width=650&height=150&src=pr&token=MqstsRKdqp&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cda-tum)](https://app.codecov.io/gh/cda-tum/mqt-core/pull/610?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cda-tum) ```diff @@ Coverage Diff @@ ## main #610 +/- ## ====================================== Coverage 91.5% 91.5% ====================================== Files 145 147 +2 Lines 14596 14698 +102 Branches 2343 2359 +16 ====================================== + Hits 13367 13461 +94 - Misses 1229 1237 +8 ``` | [Flag](https://app.codecov.io/gh/cda-tum/mqt-core/pull/610/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cda-tum) | Coverage Δ | | |---|---|---| | [cpp](https://app.codecov.io/gh/cda-tum/mqt-core/pull/610/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cda-tum) | `91.3% <94.1%> (+<0.1%)` | :arrow_up: | | [python](https://app.codecov.io/gh/cda-tum/mqt-core/pull/610/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cda-tum) | `99.7% <ø> (ø)` | | | [Files with missing lines](https://app.codecov.io/gh/cda-tum/mqt-core/pull/610?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cda-tum) | Coverage Δ | | |---|---|---| | [include/mqt-core/QuantumComputation.hpp](https://app.codecov.io/gh/cda-tum/mqt-core/pull/610?src=pr&el=tree&filepath=include%2Fmqt-core%2FQuantumComputation.hpp&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cda-tum#diff-aW5jbHVkZS9tcXQtY29yZS9RdWFudHVtQ29tcHV0YXRpb24uaHBw) | `92.3% <ø> (ø)` | | | [include/mqt-core/operations/OpType.hpp](https://app.codecov.io/gh/cda-tum/mqt-core/pull/610?src=pr&el=tree&filepath=include%2Fmqt-core%2Foperations%2FOpType.hpp&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cda-tum#diff-aW5jbHVkZS9tcXQtY29yZS9vcGVyYXRpb25zL09wVHlwZS5ocHA=) | `91.4% <100.0%> (+0.5%)` | :arrow_up: | | [include/mqt-core/operations/Operation.hpp](https://app.codecov.io/gh/cda-tum/mqt-core/pull/610?src=pr&el=tree&filepath=include%2Fmqt-core%2Foperations%2FOperation.hpp&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cda-tum#diff-aW5jbHVkZS9tcXQtY29yZS9vcGVyYXRpb25zL09wZXJhdGlvbi5ocHA=) | `81.6% <100.0%> (+0.4%)` | :arrow_up: | | [src/operations/AodOperation.cpp](https://app.codecov.io/gh/cda-tum/mqt-core/pull/610?src=pr&el=tree&filepath=src%2Foperations%2FAodOperation.cpp&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cda-tum#diff-c3JjL29wZXJhdGlvbnMvQW9kT3BlcmF0aW9uLmNwcA==) | `100.0% <100.0%> (ø)` | | | [include/mqt-core/operations/AodOperation.hpp](https://app.codecov.io/gh/cda-tum/mqt-core/pull/610?src=pr&el=tree&filepath=include%2Fmqt-core%2Foperations%2FAodOperation.hpp&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cda-tum#diff-aW5jbHVkZS9tcXQtY29yZS9vcGVyYXRpb25zL0FvZE9wZXJhdGlvbi5ocHA=) | `91.6% <91.6%> (ø)` | | | [src/operations/StandardOperation.cpp](https://app.codecov.io/gh/cda-tum/mqt-core/pull/610?src=pr&el=tree&filepath=src%2Foperations%2FStandardOperation.cpp&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cda-tum#diff-c3JjL29wZXJhdGlvbnMvU3RhbmRhcmRPcGVyYXRpb24uY3Bw) | `92.9% <0.0%> (-0.7%)` | :arrow_down: | ... and [1 file with indirect coverage changes](https://app.codecov.io/gh/cda-tum/mqt-core/pull/610/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cda-tum)
lsschmid commented 6 months ago

Everything except the linter passes.

I checked that all linter warnings that still remain are not from my code.

lsschmid commented 5 months ago

Finally found the time to go through this PR 😌 Overall the changes here look good 👍 I pushed two minor changes directly and added further smaller comments in the files themselves. Most of these should be pretty minor.

I have one medium-large question and one bigger question I'd like to get out of the way before proceeding here:

First, what about reading the produced QASM circuits back in? Right now, no adaptation on the QASM parser has been performed so far. So the produced QASM files cannot be read anywhere. While not a dealbreaker, it would certainly be nice to support that, wouldn't it?

Second, and probably the bigger question: @ystade recently introduced the na subcomponent in mqt-core and mqt-qmap, where he (amongst other things) also defined a ShuttlingOperation (with load, move, and store types). Now this PR implements essentially the same concept, but in a different fashion. While I would be ok with that in the short-term, this duplication is certainly no maintainable solution for the future. How hard do you think it would be to base your changes (especially those in QMAP) on @ystade's infrastructure for neutral atom computations? From the changes here, the QASM dump would be the most important thing to port to the existing NAComputation and NAOperation classes. (Expect me asking a similar question in the mqt-qmap PR)

Regarding the qasm import: Back when I wrote the code I also added the correct parsing commands. This took me quite some time as I'm not really familiar with parsing in general. Unfortuantly in the meantime the parser was updated to support qasm3 which broke my version and I could not see an easy way to transfer my code. As for now, the only usecase where the parsing would be interesting is to schedule circuits which have been mapped and saved previously. This is indeed a possible/interesting option but currently not used by us and my knowledge on parsing is not sufficient to do some "quick fix" to that.

Regarding the NA unification: Obviously, my code already existed before @ystade started with his part. We had some discussion back then on reusing the code but then decided to create two separate versions as a start as we required different things. A unification might probably be possible and would probably make sense for common export/import but currently this is a non-trivial task as we took different approaches to how we handle/represent the AOD moves.

burgholzer commented 5 months ago

Finally found the time to go through this PR 😌 Overall the changes here look good 👍 I pushed two minor changes directly and added further smaller comments in the files themselves. Most of these should be pretty minor. I have one medium-large question and one bigger question I'd like to get out of the way before proceeding here: First, what about reading the produced QASM circuits back in? Right now, no adaptation on the QASM parser has been performed so far. So the produced QASM files cannot be read anywhere. While not a dealbreaker, it would certainly be nice to support that, wouldn't it? Second, and probably the bigger question: @ystade recently introduced the na subcomponent in mqt-core and mqt-qmap, where he (amongst other things) also defined a ShuttlingOperation (with load, move, and store types). Now this PR implements essentially the same concept, but in a different fashion. While I would be ok with that in the short-term, this duplication is certainly no maintainable solution for the future. How hard do you think it would be to base your changes (especially those in QMAP) on @ystade's infrastructure for neutral atom computations? From the changes here, the QASM dump would be the most important thing to port to the existing NAComputation and NAOperation classes. (Expect me asking a similar question in the mqt-qmap PR)

Regarding the qasm import: Back when I wrote the code I also added the correct parsing commands. This took me quite some time as I'm not really familiar with parsing in general. Unfortuantly in the meantime the parser was updated to support qasm3 which broke my version and I could not see an easy way to transfer my code. As for now, the only usecase where the parsing would be interesting is to schedule circuits which have been mapped and saved previously. This is indeed a possible/interesting option but currently not used by us and my knowledge on parsing is not sufficient to do some "quick fix" to that.

Fully understand that point. The new parser is structured quite a bit differently than the old one. Adding a parser for the new operations would definitely make sense in the future. Also triggered by the comment below, I would postpone that implementation to a point where we consolidated on the particular details when it comes to NA Compilation and how to represent the corresponding computations. At that point, this can be a student project. Might be worth tracking that in an issue. It isn't valid QASM in either version of the standard. For it to be valid, you would have to add an opaque gate declaration for the operation to the top of the file, eliminate the ; from the parameter list, and you'd have to somehow handle the fact that the parameter list can have arbitrary length.

Regarding the NA unification: Obviously, my code already existed before @ystade started with his part. We had some discussion back then on reusing the code but then decided to create two separate versions as a start as we required different things. A unification might probably be possible and would probably make sense for common export/import but currently this is a non-trivial task as we took different approaches to how we handle and represent the AOD moves.

It's obvious that this is a non-trivial task. It's still important to think about this early as I would really want to avoid to develop two completely separate strands of features here. Just for clarification: To me, the two AOD representations do not look fundamentally different. You choose to explicitly encode the direction and use floating point numbers for start and end coordinates. @ystade chose to implicitly store the direction by assuming a 2D plane and using (x, y) (integer) coordinates for the start and end coordinates. Functionality-wise, these two are equivalent (at least in 2D and assuming the integer resolution is enough). Do you really think that adapting your code to that class would be that much of an effort? Most likely, I am simply overlooking things given that I have not spent enough time with the QMAP code yet. So I am really interested in your judgement here. If this is too much to ask for now (which is totally ok), then I'd at least like to have a clear plan on who has the responsibility to consolidate that in the future and a rough timeframe.

lsschmid commented 5 months ago

Fully understand that point. The new parser is structured quite a bit differently than the old one. Adding a parser for the new operations would definitely make sense in the future. Also triggered by the comment below, I would postpone that implementation to a point where we consolidated on the particular details when it comes to NA Compilation and how to represent the corresponding computations. At that point, this can be a student project. Might be worth tracking that in an issue. It isn't valid QASM in either version of the standard. For it to be valid, you would have to add an opaque gate declaration for the operation to the top of the file, eliminate the ; from the parameter list, and you'd have to somehow handle the fact that the parameter list can have arbitrary length.

Yes, exactly; this would probably be the way to go, also for the consolidated version below.

It's obvious that this is a non-trivial task. It's still important to think about this early as I would really want to avoid to develop two completely separate strands of features here. Just for clarification: To me, the two AOD representations do not look fundamentally different. You choose to explicitly encode the direction and use floating point numbers for start and end coordinates. @ystade chose to implicitly store the direction by assuming a 2D plane and using (x, y) (integer) coordinates for the start and end coordinates. Functionality-wise, these two are equivalent (at least in 2D and assuming the integer resolution is enough). Do you really think that adapting your code to that class would be that much of an effort? Most likely, I am simply overlooking things given that I have not spent enough time with the QMAP code yet. So I am really interested in your judgement here. If this is too much to ask for now (which is totally ok), then I'd at least like to have a clear plan on who has the responsibility to consolidate that in the future and a rough timeframe.

That's correct. As the basic functionality is quite clear (moving coordinates in 2D), I think both sides could be consolidated in a straightforward fashion conceptional-wise, but with small differences (e.g., I require floats instead of int) . An almost similar problem exists for the NeutralAtomArchitecture Class we used for the Mapping Tasks. For now I would keep the two projects separate and then discuss on an overarching Operation Class + Architecure Class in the following weeks, also in the context of a compiler collection.

lsschmid commented 5 months ago

I'll write the issues 👍