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

🐛 properly handle timing literals in QASM parser #724

Closed burgholzer closed 1 month ago

burgholzer commented 1 month ago

Description

This PR fixes a bug in the QASM parser that would treat timing literal suffixes as individual tokens, which can lead to strange errors with gate declarations whose name matches a timing literal suffix, e.g., ms. Timing literals are now properly treated and do not lead to clashes.

In the process, it was noticed that the Python import of long QASM strings would fail due to pathlib throwing an OSError for too long paths. This is now fixed by short circuiting if the path is too long.

Fixes #723

Checklist:

codecov[bot] commented 1 month ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 92.2%. Comparing base (11a7d49) to head (896257d). Report is 1 commits behind head on main.

Additional details and impacted files [![Impacted file tree graph](https://app.codecov.io/gh/cda-tum/mqt-core/pull/724/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/724?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 #724 +/- ## ======================================= + Coverage 92.1% 92.2% +0.1% ======================================= Files 125 125 Lines 13757 13739 -18 Branches 2150 2158 +8 ======================================= + Hits 12671 12678 +7 + Misses 1086 1061 -25 ``` | [Flag](https://app.codecov.io/gh/cda-tum/mqt-core/pull/724/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/724/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cda-tum) | `92.0% <100.0%> (+0.1%)` | :arrow_up: | | [python](https://app.codecov.io/gh/cda-tum/mqt-core/pull/724/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cda-tum) | `99.7% <100.0%> (+<0.1%)` | :arrow_up: | | [Files with missing lines](https://app.codecov.io/gh/cda-tum/mqt-core/pull/724?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cda-tum) | Coverage Δ | | |---|---|---| | [...clude/mqt-core/ir/parsers/qasm3\_parser/Scanner.hpp](https://app.codecov.io/gh/cda-tum/mqt-core/pull/724?src=pr&el=tree&filepath=include%2Fmqt-core%2Fir%2Fparsers%2Fqasm3_parser%2FScanner.hpp&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cda-tum#diff-aW5jbHVkZS9tcXQtY29yZS9pci9wYXJzZXJzL3Fhc20zX3BhcnNlci9TY2FubmVyLmhwcA==) | `71.4% <ø> (ø)` | | | [include/mqt-core/ir/parsers/qasm3\_parser/Token.hpp](https://app.codecov.io/gh/cda-tum/mqt-core/pull/724?src=pr&el=tree&filepath=include%2Fmqt-core%2Fir%2Fparsers%2Fqasm3_parser%2FToken.hpp&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cda-tum#diff-aW5jbHVkZS9tcXQtY29yZS9pci9wYXJzZXJzL3Fhc20zX3BhcnNlci9Ub2tlbi5ocHA=) | `98.2% <100.0%> (-0.1%)` | :arrow_down: | | [src/ir/parsers/qasm3\_parser/Parser.cpp](https://app.codecov.io/gh/cda-tum/mqt-core/pull/724?src=pr&el=tree&filepath=src%2Fir%2Fparsers%2Fqasm3_parser%2FParser.cpp&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cda-tum#diff-c3JjL2lyL3BhcnNlcnMvcWFzbTNfcGFyc2VyL1BhcnNlci5jcHA=) | `92.6% <100.0%> (-0.1%)` | :arrow_down: | | [src/ir/parsers/qasm3\_parser/Scanner.cpp](https://app.codecov.io/gh/cda-tum/mqt-core/pull/724?src=pr&el=tree&filepath=src%2Fir%2Fparsers%2Fqasm3_parser%2FScanner.cpp&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cda-tum#diff-c3JjL2lyL3BhcnNlcnMvcWFzbTNfcGFyc2VyL1NjYW5uZXIuY3Bw) | `97.0% <100.0%> (+0.1%)` | :arrow_up: | | [src/mqt/core/\_\_init\_\_.py](https://app.codecov.io/gh/cda-tum/mqt-core/pull/724?src=pr&el=tree&filepath=src%2Fmqt%2Fcore%2F__init__.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cda-tum#diff-c3JjL21xdC9jb3JlL19faW5pdF9fLnB5) | `100.0% <100.0%> (ø)` | | ... and [16 files with indirect coverage changes](https://app.codecov.io/gh/cda-tum/mqt-core/pull/724/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cda-tum)