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

✨ Add support for OpenQASM 3.0 else #498

Merged
merged 15 commits into from
Dec 15, 2023
Merged

Conversation

martin-fink
Copy link
Collaborator

@martin-fink martin-fink commented Dec 15, 2023

Description

This PR adds support for the else branch in if statements when parsing OpenQASM 3.0.

Example:

if (c == 1) {
  x q[1];
} else {
  x q[0];
  x q[1];
}

This is implemented by adding a second ClassicalControlledOperation to the Quantum Computation with a flipped condition.
When dumping the circuit above, the following is printed:

if (c == 1) {
  x q[1];
}
if (c != 1) {
  x q[0];
  x q[1];
}

Checklist:

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

@martin-fink martin-fink changed the title ✨ Add support for OpenQASM 3.0 else ✨ Add support for OpenQASM 3.0 else Dec 15, 2023
@martin-fink martin-fink self-assigned this Dec 15, 2023
Copy link
Member

@burgholzer burgholzer left a comment

Choose a reason for hiding this comment

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

That was quick. Many thanks!
I just added some small little comments. Nothing too major.

I'll also re-run the coverage tests (they seem to be failing more frequently again recently). That's not on us though, but on the codecov service.

src/parsers/QASM3Parser.cpp Outdated Show resolved Hide resolved
src/parsers/QASM3Parser.cpp Outdated Show resolved Hide resolved
src/parsers/qasm3_parser/passes/ConstEvalPass.cpp Outdated Show resolved Hide resolved
@burgholzer burgholzer added enhancement New feature or request Core Anything related to the Core library and IR c++ Anything related to C++ code labels Dec 15, 2023
@burgholzer burgholzer added this to the OpenQASM 3.0 Support milestone Dec 15, 2023
Copy link

codecov bot commented Dec 15, 2023

Codecov Report

Merging #498 (7261fa3) into main (24f7ee1) will decrease coverage by 0.1%.
The diff coverage is 84.6%.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##            main    #498     +/-   ##
=======================================
- Coverage   90.8%   90.8%   -0.1%     
=======================================
  Files        127     128      +1     
  Lines      13846   13867     +21     
  Branches    2174    2177      +3     
=======================================
+ Hits       12579   12598     +19     
- Misses      1267    1269      +2     
Flag Coverage Δ
cpp 90.5% <84.6%> (-0.1%) ⬇️
python 99.7% <ø> (ø)
Files Coverage Δ
include/operations/ClassicControlledOperation.hpp 96.8% <ø> (ø)
include/parsers/qasm3_parser/Statement.hpp 92.7% <ø> (ø)
src/parsers/QASM3Parser.cpp 90.4% <100.0%> (+0.5%) ⬆️
include/Definitions.hpp 76.4% <0.0%> (-10.2%) ⬇️
...lude/parsers/qasm3_parser/passes/ConstEvalPass.hpp 80.9% <0.0%> (-2.0%) ⬇️
src/parsers/qasm3_parser/Statement.cpp 87.5% <87.5%> (ø)
src/operations/ClassicControlledOperation.cpp 88.5% <85.1%> (-11.5%) ⬇️

... and 2 files with indirect coverage changes

Copy link
Member

@burgholzer burgholzer left a comment

Choose a reason for hiding this comment

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

Many thanks for the PR. I just updated a few things and optimized the code a little.

The remaining lines are, per definition, uncoverable. So I am ignoring the failing patch coverage check.

@martin-fink
Copy link
Collaborator Author

Thanks!

@burgholzer burgholzer merged commit b09a5b6 into cda-tum:main Dec 15, 2023
33 of 34 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ Anything related to C++ code Core Anything related to the Core library and IR enhancement New feature or request
Projects
Status: Done
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants