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

♻️ Refactor and improve register handling #807

Merged
merged 14 commits into from
Jan 21, 2025
Merged

Conversation

burgholzer
Copy link
Member

Description

This PR originated out of working on #729. It refactors certain aspects of how registers are handled in MQT Core. In particular:

  • Registers are now no longer typedefs, but proper structs with some convenience methods that make the code more legible.
  • Classic-controlled operations now either take a full ClassicalRegister or a single bit. This closely matches the kind of operations we actually support and defines some errors out of existance.
  • The QASM dump functionality has been made more robust and can now, in principle, handle discontinuous registers.

In addition to that,

  • a couple of redundant functions have been removed
  • some general typedefs have been moved to more explicit places, and
  • some clang-tidy recommendations have been implemented.

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.

@burgholzer burgholzer added usability Anything related to usability refactor Anything related to code refactoring code quality Code quality improvements Core Anything related to the Core library and IR c++ Anything related to C++ code labels Jan 21, 2025
@burgholzer burgholzer added this to the MQT Core milestone Jan 21, 2025
@burgholzer burgholzer self-assigned this Jan 21, 2025
Copy link

codecov bot commented Jan 21, 2025

Codecov Report

Attention: Patch coverage is 91.46341% with 35 lines in your changes missing coverage. Please review.

Project coverage is 92.2%. Comparing base (bea8448) to head (ef7b2ec).
Report is 15 commits behind head on main.

Files with missing lines Patch % Lines
src/ir/QuantumComputation.cpp 94.3% 8 Missing ⚠️
include/mqt-core/dd/Operations.hpp 50.0% 6 Missing ⚠️
src/ir/operations/StandardOperation.cpp 78.5% 6 Missing ⚠️
src/dd/Simulation.cpp 54.5% 5 Missing ⚠️
src/circuit_optimizer/CircuitOptimizer.cpp 95.1% 4 Missing ⚠️
include/mqt-core/ir/Register.hpp 89.6% 3 Missing ⚠️
src/algorithms/Grover.cpp 75.0% 1 Missing ⚠️
src/ir/operations/ClassicControlledOperation.cpp 95.4% 1 Missing ⚠️
src/ir/operations/SymbolicOperation.cpp 0.0% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##            main    #807     +/-   ##
=======================================
+ Coverage   92.0%   92.2%   +0.1%     
=======================================
  Files        125     126      +1     
  Lines      13828   13826      -2     
  Branches    2153    2153             
=======================================
+ Hits       12735   12757     +22     
+ Misses      1093    1069     -24     
Flag Coverage Δ
cpp 92.0% <91.4%> (+0.1%) ⬆️
python 99.7% <ø> (ø)
Files with missing lines Coverage Δ
include/mqt-core/Definitions.hpp 76.4% <ø> (ø)
include/mqt-core/ir/QuantumComputation.hpp 100.0% <100.0%> (ø)
include/mqt-core/ir/operations/AodOperation.hpp 77.7% <ø> (ø)
...-core/ir/operations/ClassicControlledOperation.hpp 96.9% <100.0%> (+0.1%) ⬆️
...clude/mqt-core/ir/operations/CompoundOperation.hpp 100.0% <ø> (ø)
...ude/mqt-core/ir/operations/NonUnitaryOperation.hpp 100.0% <ø> (ø)
include/mqt-core/ir/operations/Operation.hpp 79.2% <100.0%> (+0.2%) ⬆️
...clude/mqt-core/ir/operations/StandardOperation.hpp 100.0% <ø> (ø)
...clude/mqt-core/ir/operations/SymbolicOperation.hpp 100.0% <ø> (ø)
src/algorithms/BernsteinVazirani.cpp 100.0% <100.0%> (ø)
... and 17 more

... and 1 file with indirect coverage changes

@burgholzer burgholzer merged commit ba3aa86 into main Jan 21, 2025
30 checks passed
@burgholzer burgholzer deleted the register-handling branch January 21, 2025 15:48
@burgholzer burgholzer mentioned this pull request Jan 21, 2025
4 tasks
burgholzer added a commit that referenced this pull request Jan 21, 2025
## Description

Fixes #729

This PR builds on the register handling improvements in #807 and fixes
the the last remaining part of the problem observed in #729.
When dumping a circuit to QASM that has been stripped of idle qubits,
the initial layout and output permutation need to be adjusted so that
the resulting circuit can be read in again without problems.
The reason this PR is so small is mainly because a lot of the legwork
was already done in #807.

## 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 <[email protected]>
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 code quality Code quality improvements Core Anything related to the Core library and IR refactor Anything related to code refactoring usability Anything related to usability
Projects
Status: Done
Status: Done
Development

Successfully merging this pull request may close these issues.

1 participant