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

Refactor handling of gate matrices and inverses #752

Open Joshy-R opened 1 week ago

Joshy-R commented 1 week ago

Description

These commits change how matrices are created from an OpType that reduces the number of switch statements necessary. The downside of this approach is that some functions can be called with arguments that do not affect the returned value. As the user never calls these functions, I see this as acceptable.

I also removed the CX_MAT and CZ_MAT, as they are only used in tests and do not occur in any other repository.

Fixes #484

Checklist:

I have not squashed the commits to make them easier to review, but I can squash them if desired.

codecov[bot] commented 1 week ago

Codecov Report

Attention: Patch coverage is 96.77419% with 3 lines in your changes missing coverage. Please review.

Project coverage is 92.0%. Comparing base (868299c) to head (3d824d7).

Files with missing lines Patch % Lines
include/mqt-core/dd/Operations.hpp 94.4% 2 Missing :warning:
include/mqt-core/ir/operations/OpType.hpp 80.0% 1 Missing :warning:
Additional details and impacted files [![Impacted file tree graph](https://app.codecov.io/gh/cda-tum/mqt-core/pull/752/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/752?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 #752 +/- ## ======================================= - Coverage 92.1% 92.0% -0.1% ======================================= Files 125 126 +1 Lines 13770 13652 -118 Branches 2157 2164 +7 ======================================= - Hits 12684 12565 -119 - Misses 1086 1087 +1 ``` | [Flag](https://app.codecov.io/gh/cda-tum/mqt-core/pull/752/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cda-tum) | Coverage Δ | | *Carryforward flag | |---|---|---|---| | [cpp](https://app.codecov.io/gh/cda-tum/mqt-core/pull/752/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cda-tum) | `91.7% <96.7%> (-0.1%)` | :arrow_down: | | | [python](https://app.codecov.io/gh/cda-tum/mqt-core/pull/752/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cda-tum) | `99.7% <ø> (ø)` | | Carriedforward from [868299c](https://app.codecov.io/gh/cda-tum/mqt-core/commit/868299c8717970d455ee32884c808593bb60e0b3?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cda-tum) | *This pull request uses carry forward flags. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cda-tum) to find out more. | [Files with missing lines](https://app.codecov.io/gh/cda-tum/mqt-core/pull/752?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/dd/GateMatrixDefinitions.hpp](https://app.codecov.io/gh/cda-tum/mqt-core/pull/752?src=pr&el=tree&filepath=include%2Fmqt-core%2Fdd%2FGateMatrixDefinitions.hpp&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cda-tum#diff-aW5jbHVkZS9tcXQtY29yZS9kZC9HYXRlTWF0cml4RGVmaW5pdGlvbnMuaHBw) | `100.0% <100.0%> (ø)` | | | [include/mqt-core/ir/operations/Operation.hpp](https://app.codecov.io/gh/cda-tum/mqt-core/pull/752?src=pr&el=tree&filepath=include%2Fmqt-core%2Fir%2Foperations%2FOperation.hpp&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cda-tum#diff-aW5jbHVkZS9tcXQtY29yZS9pci9vcGVyYXRpb25zL09wZXJhdGlvbi5ocHA=) | `79.7% <100.0%> (-0.3%)` | :arrow_down: | | [src/circuit\_optimizer/CircuitOptimizer.cpp](https://app.codecov.io/gh/cda-tum/mqt-core/pull/752?src=pr&el=tree&filepath=src%2Fcircuit_optimizer%2FCircuitOptimizer.cpp&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cda-tum#diff-c3JjL2NpcmN1aXRfb3B0aW1pemVyL0NpcmN1aXRPcHRpbWl6ZXIuY3Bw) | `90.2% <100.0%> (-0.1%)` | :arrow_down: | | [src/dd/GateMatrixDefinitions.cpp](https://app.codecov.io/gh/cda-tum/mqt-core/pull/752?src=pr&el=tree&filepath=src%2Fdd%2FGateMatrixDefinitions.cpp&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cda-tum#diff-c3JjL2RkL0dhdGVNYXRyaXhEZWZpbml0aW9ucy5jcHA=) | `100.0% <100.0%> (ø)` | | | [src/dd/NoiseFunctionality.cpp](https://app.codecov.io/gh/cda-tum/mqt-core/pull/752?src=pr&el=tree&filepath=src%2Fdd%2FNoiseFunctionality.cpp&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cda-tum#diff-c3JjL2RkL05vaXNlRnVuY3Rpb25hbGl0eS5jcHA=) | `97.0% <100.0%> (-0.1%)` | :arrow_down: | | [src/dd/Simulation.cpp](https://app.codecov.io/gh/cda-tum/mqt-core/pull/752?src=pr&el=tree&filepath=src%2Fdd%2FSimulation.cpp&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cda-tum#diff-c3JjL2RkL1NpbXVsYXRpb24uY3Bw) | `96.5% <100.0%> (+<0.1%)` | :arrow_up: | | [include/mqt-core/ir/operations/OpType.hpp](https://app.codecov.io/gh/cda-tum/mqt-core/pull/752?src=pr&el=tree&filepath=include%2Fmqt-core%2Fir%2Foperations%2FOpType.hpp&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cda-tum#diff-aW5jbHVkZS9tcXQtY29yZS9pci9vcGVyYXRpb25zL09wVHlwZS5ocHA=) | `85.1% <80.0%> (-6.4%)` | :arrow_down: | | [include/mqt-core/dd/Operations.hpp](https://app.codecov.io/gh/cda-tum/mqt-core/pull/752?src=pr&el=tree&filepath=include%2Fmqt-core%2Fdd%2FOperations.hpp&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cda-tum#diff-aW5jbHVkZS9tcXQtY29yZS9kZC9PcGVyYXRpb25zLmhwcA==) | `82.6% <94.4%> (-6.0%)` | :arrow_down: | ... and [1 file with indirect coverage changes](https://app.codecov.io/gh/cda-tum/mqt-core/pull/752/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cda-tum)