Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/qureg_apply1qubitgate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -461,8 +461,8 @@ void QubitRegister<Type>::ApplyHadamard(unsigned const qubit)
///
/// R_XY(phi, theta) = cos(theta/2) I -i sin(theta/2) (cos(phi) X + sin(phi) Y)
///
/// = | c(t/2) -i s(t/2) (c(p) -i s(p) |
/// | -i s(t/2) (c(p) +i s(p) c(t/2) |
/// = | c(t/2) -i s(t/2) (c(p) -i s(p)) |
/// | -i s(t/2) (c(p) +i s(p)) c(t/2) |
///
/// Or, in other format:
///
Expand All @@ -475,7 +475,7 @@ void QubitRegister<Type>::ApplyRotationXY(unsigned const qubit, BaseType phi, Ba
iqs::TinyMatrix<Type, 2, 2, 32> rxy;
rxy(0, 0) = Type(std::cos(theta / 2.), 0);
rxy(0, 1) = Type(-std::sin(theta / 2.) * std::sin(phi), -std::sin(theta / 2.) * std::cos(phi) );
rxy(0, 1) = Type( std::sin(theta / 2.) * std::sin(phi), -std::sin(theta / 2.) * std::cos(phi) );
rxy(1, 0) = Type( std::sin(theta / 2.) * std::sin(phi), -std::sin(theta / 2.) * std::cos(phi) );
rxy(1, 1) = Type(std::cos(theta / 2.), 0);
Apply1QubitGate(qubit, rxy);
}
Expand Down
13 changes: 9 additions & 4 deletions unit_test/include/apply_1q_gate_test.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,9 @@ TEST_F(Apply1QGateTest, RotationXY)
psi.ApplyRotationZ(qubit, -phi);
psi.ApplyRotationX(qubit, -theta);
psi.ApplyRotationZ(qubit, phi);
ASSERT_TRUE( psi.ComputeOverlap(psi_0).real() < 1.-accepted_error_);
ASSERT_TRUE( std::abs(psi.ComputeOverlap(psi_0).real() - 1) < accepted_error_);
ASSERT_TRUE( std::abs(psi.ComputeOverlap(psi_0).imag() - 0) < accepted_error_);
ASSERT_TRUE( psi.ComputeOverlap(psi_0).real() > 1.-accepted_error_);
// Apply rotation in the XY plane and then cancel it with two rotations.
phi = 1.1;
theta = 0.13;
Expand All @@ -212,20 +214,23 @@ TEST_F(Apply1QGateTest, RotationXY)
psi.ApplyRotationZ(qubit, -phi);
psi.ApplyRotationX(qubit, -theta);
psi.ApplyRotationZ(qubit, phi);
ASSERT_TRUE( psi.ComputeOverlap(psi_0).real() < 1.-accepted_error_);
ASSERT_TRUE( std::abs(psi.ComputeOverlap(psi_0).real() - 1) < accepted_error_);
ASSERT_TRUE( std::abs(psi.ComputeOverlap(psi_0).imag() - 0) < accepted_error_);
// Special case phi=0 corresponding to a X rotation.
phi = 0.;
theta = 0.28;
qubit = 1;
psi.ApplyRotationXY(qubit, phi, theta);
psi.ApplyRotationX(qubit, -theta);
ASSERT_TRUE( psi.ComputeOverlap(psi_0).real() < 1.-accepted_error_);
ASSERT_TRUE( std::abs(psi.ComputeOverlap(psi_0).real() - 1) < accepted_error_);
ASSERT_TRUE( std::abs(psi.ComputeOverlap(psi_0).imag() - 0) < accepted_error_);
// Special case phi=pi/2 corresponding to a Y rotation.
phi = M_PI/2;
qubit = 2;
psi.ApplyRotationXY(qubit, phi, theta);
psi.ApplyRotationY(qubit, -theta);
ASSERT_TRUE( psi.ComputeOverlap(psi_0).real() < 1.-accepted_error_);
ASSERT_TRUE( std::abs(psi.ComputeOverlap(psi_0).real() - 1) < accepted_error_);
ASSERT_TRUE( std::abs(psi.ComputeOverlap(psi_0).imag() - 0) < accepted_error_);
}

//////////////////////////////////////////////////////////////////////////////
Expand Down