Skip to content

Commit

Permalink
Fixed a bug in Z-Y decomposition
Browse files Browse the repository at this point in the history
The sub-routine must return once it found the decomp.

Signed-off-by: Thien Nguyen <nguyentm@ornl.gov>
  • Loading branch information
Thien Nguyen committed Nov 2, 2021
1 parent 3679fe7 commit 5988052
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions quantum/plugins/circuits/kak/kak.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ singleQubitGateGen(const Eigen::Matrix2cd &in_mat, size_t in_bitIdx) {
}
}
assert(found);
return std::make_tuple(a, bHalf, cHalf, dHalf);
} else if (std::abs(matrix(0, 0)) < TOLERANCE) {
auto two_a = fmod(std::arg(-matrix(0, 1) * matrix(1, 0)), 2 * M_PI);
a = (std::abs(two_a) < TOLERANCE ||
Expand All @@ -351,6 +352,7 @@ singleQubitGateGen(const Eigen::Matrix2cd &in_mat, size_t in_bitIdx) {
}
}
assert(found);
return std::make_tuple(a, bHalf, cHalf, dHalf);
} else {
auto two_a = fmod(std::arg(matrix(0, 0) * matrix(1, 1)), 2 * M_PI);
a = (std::abs(two_a) < TOLERANCE ||
Expand Down Expand Up @@ -392,11 +394,8 @@ singleQubitGateGen(const Eigen::Matrix2cd &in_mat, size_t in_bitIdx) {
}
}
assert(found);
return std::make_tuple(a, bHalf, cHalf, dHalf);
}

// Final check:
assert(checkParams(a, bHalf, cHalf, dHalf));
return std::make_tuple(a, bHalf, cHalf, dHalf);
};
// Use Z-Y decomposition of Nielsen and Chuang (Theorem 4.1).
// An arbitrary one qubit gate matrix can be writen as
Expand Down

0 comments on commit 5988052

Please sign in to comment.