Skip to content

Commit 66ec9a6

Browse files
committed
slight improvement to weyl decomposition for testing purposes
1 parent b4e1422 commit 66ec9a6

1 file changed

Lines changed: 13 additions & 15 deletions

File tree

mlir/include/mlir/Dialect/MQTOpt/Transforms/Decomposition/WeylDecomposition.h

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ struct TwoQubitWeylDecomposition {
7171
};
7272

7373
// a, b, c are the parameters of the canonical gate (CAN)
74-
fp a; // rotation of RXX gate in CAN
75-
fp b; // rotation of RYY gate in CAN
76-
fp c; // rotation of RZZ gate in CAN
74+
fp a; // rotation of RXX gate in CAN (must be taken times -2.0)
75+
fp b; // rotation of RYY gate in CAN (must be taken times -2.0)
76+
fp c; // rotation of RZZ gate in CAN (must be taken times -2.0)
7777
fp globalPhase; // global phase adjustment
7878
/**
7979
* q1 - k2r - C - k1r -
@@ -101,7 +101,6 @@ struct TwoQubitWeylDecomposition {
101101
* reduce the number of parameters required by the canonical
102102
* gate and thus potentially decreasing the number of basis
103103
* gates.
104-
* @param specialization Force the use this specialization.
105104
*/
106105
static TwoQubitWeylDecomposition create(const matrix4x4& unitaryMatrix,
107106
std::optional<fp> fidelity) {
@@ -260,11 +259,6 @@ struct TwoQubitWeylDecomposition {
260259

261260
// bind weyl coordinates as parameters of canonical gate
262261
auto [a, b, c] = std::tie(cs[1], cs[0], cs[2]);
263-
// make sure decomposition is equal to input
264-
assert((helpers::kroneckerProduct(K1l, K1r) *
265-
getCanonicalMatrix(a * -2.0, b * -2.0, c * -2.0) *
266-
helpers::kroneckerProduct(K2l, K2r) * std::exp(IM * globalPhase))
267-
.isApprox(unitaryMatrix, SANITY_CHECK_PRECISION));
268262

269263
TwoQubitWeylDecomposition decomposition{
270264
.a = a,
@@ -282,6 +276,11 @@ struct TwoQubitWeylDecomposition {
282276
.calculatedFidelity = -1.0,
283277
.unitaryMatrix = unitaryMatrix,
284278
};
279+
// make sure decomposition is equal to input
280+
assert((helpers::kroneckerProduct(K1l, K1r) *
281+
decomposition.getCanonicalMatrix() *
282+
helpers::kroneckerProduct(K2l, K2r) * std::exp(IM * globalPhase))
283+
.isApprox(unitaryMatrix, SANITY_CHECK_PRECISION));
285284

286285
// determine actual specialization of canonical gate so that the 1q
287286
// matrices can potentially be simplified
@@ -315,8 +314,7 @@ struct TwoQubitWeylDecomposition {
315314

316315
// final check if decomposition is still valid after specialization
317316
assert((helpers::kroneckerProduct(decomposition.k1l, decomposition.k1r) *
318-
getCanonicalMatrix(decomposition.a * -2.0, decomposition.b * -2.0,
319-
decomposition.c * -2.0) *
317+
decomposition.getCanonicalMatrix() *
320318
helpers::kroneckerProduct(decomposition.k2l, decomposition.k2r) *
321319
std::exp(IM * decomposition.globalPhase))
322320
.isApprox(unitaryMatrix, SANITY_CHECK_PRECISION));
@@ -327,20 +325,20 @@ struct TwoQubitWeylDecomposition {
327325
/**
328326
* Calculate matrix of canonical gate based on its parameters a, b, c.
329327
*/
330-
static matrix4x4 getCanonicalMatrix(fp a, fp b, fp c) {
328+
[[nodiscard]] matrix4x4 getCanonicalMatrix() const {
331329
auto xx = getTwoQubitMatrix({
332330
.type = qc::RXX,
333-
.parameter = {a},
331+
.parameter = {-2.0 * a},
334332
.qubitId = {0, 1},
335333
});
336334
auto yy = getTwoQubitMatrix({
337335
.type = qc::RYY,
338-
.parameter = {b},
336+
.parameter = {-2.0 * b},
339337
.qubitId = {0, 1},
340338
});
341339
auto zz = getTwoQubitMatrix({
342340
.type = qc::RZZ,
343-
.parameter = {c},
341+
.parameter = {-2.0 * c},
344342
.qubitId = {0, 1},
345343
});
346344
return zz * yy * xx;

0 commit comments

Comments
 (0)