Skip to content

Commit

Permalink
♻️ 🔥 use opToSingleGateMatrix to retrieve matrix and remove unused CX…
Browse files Browse the repository at this point in the history
…_MAT and CZ_MAT
  • Loading branch information
Joshy-R committed Dec 7, 2024
1 parent 3257484 commit 4632650
Show file tree
Hide file tree
Showing 4 changed files with 261 additions and 279 deletions.
13 changes: 4 additions & 9 deletions src/dd/NoiseFunctionality.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,16 +180,11 @@ mEdge StochasticNoiseFunctionality::generateNoiseOperation(
stackOperation(operation, target, effect, amplitudeDampingMatrix);
break;
}
case (qc::X): {
operation = stackOperation(operation, target, effect, X_MAT);
break;
}
case (qc::Y): {
operation = stackOperation(operation, target, effect, Y_MAT);
break;
}
case (qc::X):
case (qc::Y):
case (qc::Z): {
operation = stackOperation(operation, target, effect, Z_MAT);
operation = stackOperation(operation, target, effect,
opToSingleGateMatrix(effect));
break;
}
default: {
Expand Down
3 changes: 2 additions & 1 deletion src/dd/Simulation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,8 @@ void extractProbabilityVectorRecursive(const QuantumComputation* qc,

if (RealNumber::approximatelyEquals(pone, 1.)) {
const qc::MatrixDD xGate =
dd.makeGateDD(X_MAT, static_cast<Qubit>(permutation.at(target)));
dd.makeGateDD(opToSingleGateMatrix(qc::X),
static_cast<Qubit>(permutation.at(target)));
state = dd.applyOperation(xGate, state);
continue;
}
Expand Down
7 changes: 4 additions & 3 deletions test/dd/test_edge_functionality.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "dd/Node.hpp"
#include "dd/Package.hpp"
#include "dd/RealNumber.hpp"
#include "ir/operations/OpType.hpp"

#include <cmath>
#include <cstddef>
Expand Down Expand Up @@ -373,7 +374,7 @@ TEST(DensityMatrixFunctionality, GetValueByIndexProperDensityMatrix) {
const auto nqubits = 1U;
auto dd = std::make_unique<dd::Package<>>(nqubits);
auto zero = dd->makeZeroDensityOperator(nqubits);
const auto op1 = dd->makeGateDD(dd::H_MAT, 0U);
const auto op1 = dd->makeGateDD(dd::opToSingleGateMatrix(qc::H), 0U);
const auto op2 = dd->makeGateDD(dd::rzMat(dd::PI_4), 0U);
auto state = dd->applyOperationToDensity(zero, op1);
state = dd->applyOperationToDensity(state, op2);
Expand Down Expand Up @@ -407,7 +408,7 @@ TEST(DensityMatrixFunctionality, GetSparseMatrixConsistency) {
const auto nqubits = 1U;
auto dd = std::make_unique<dd::Package<>>(nqubits);
auto zero = dd->makeZeroDensityOperator(nqubits);
const auto op1 = dd->makeGateDD(dd::H_MAT, 0U);
const auto op1 = dd->makeGateDD(dd::opToSingleGateMatrix(qc::H), 0U);
const auto op2 = dd->makeGateDD(dd::rzMat(dd::PI_4), 0U);
auto state = dd->applyOperationToDensity(zero, op1);
state = dd->applyOperationToDensity(state, op2);
Expand Down Expand Up @@ -437,7 +438,7 @@ TEST(DensityMatrixFunctionality, PrintMatrix) {
const auto nqubits = 1U;
auto dd = std::make_unique<dd::Package<>>(nqubits);
auto zero = dd->makeZeroDensityOperator(nqubits);
const auto op1 = dd->makeGateDD(dd::H_MAT, 0U);
const auto op1 = dd->makeGateDD(dd::opToSingleGateMatrix(qc::H), 0U);
const auto op2 = dd->makeGateDD(dd::rzMat(dd::PI_4), 0U);
auto state = dd->applyOperationToDensity(zero, op1);
state = dd->applyOperationToDensity(state, op2);
Expand Down
Loading

0 comments on commit 4632650

Please sign in to comment.