def test_squeezing(self, tol): """Test the squeezing symplectic transform.""" r = 0.543 phi = 0.123 S = squeezing(r, phi) # apply to an identity covariance matrix out = S @ S.T expected = rotation(phi / 2) @ np.diag(np.exp( [-2 * r, 2 * r])) @ rotation(phi / 2).T assert out == pytest.approx(expected, abs=tol)
def test_rotation(self, tol): """Test the Fourier transform of a displaced state.""" # pylint: disable=invalid-unary-operand-type alpha = 0.23 + 0.12j S = rotation(np.pi / 2) # apply to a coherent state. F{x, p} -> {-p, x} out = S @ np.array([alpha.real, alpha.imag]) * np.sqrt(2 * hbar) expected = np.array([-alpha.imag, alpha.real]) * np.sqrt(2 * hbar) assert out == pytest.approx(expected, abs=tol)
def test_squeezed_state(self, tol): """Test the squeezed state is correct.""" r = 0.432 phi = 0.123 means, cov = squeezed_state(r, phi, hbar=hbar) # test vector of means is zero assert means == pytest.approx(np.zeros([2]), abs=tol) R = rotation(phi / 2) expected = R @ np.array([[np.exp(-2 * r), 0], [0, np.exp(2 * r)] ]) * hbar / 2 @ R.T # test covariance matrix is correct assert cov == pytest.approx(expected, abs=tol)
def test_displaced_squeezed_state(self, tol): """Test the displaced squeezed state is correct.""" alpha = 0.541 + 0.109j a = abs(alpha) phi_a = np.angle(alpha) r = 0.432 phi_r = 0.123 means, cov = displaced_squeezed_state(a, phi_a, r, phi_r, hbar=hbar) # test vector of means is correct assert means == pytest.approx(np.array([alpha.real, alpha.imag]) * np.sqrt(2 * hbar), abs=tol) R = rotation(phi_r / 2) expected = R @ np.array([[np.exp(-2 * r), 0], [0, np.exp(2 * r)] ]) * hbar / 2 @ R.T # test covariance matrix is correct assert cov == pytest.approx(expected, abs=tol)
def test_controlled_phase(self, tol): """Test the CZ symplectic transform.""" s = 0.543 S = controlled_phase(s) # test that S = R_2(pi/2) CX(s) R_2(pi/2)^\dagger R2 = block_diag(np.identity(2), rotation(np.pi / 2))[:, [0, 2, 1, 3]][[0, 2, 1, 3]] expected = R2 @ controlled_addition(s) @ R2.conj().T assert S == pytest.approx(expected, abs=tol) # test that S[x1, x2, p1, p2] -> [x1, x2, p1+sx2, p2+sx1] x1 = 0.5432 x2 = -0.453 p1 = 0.154 p2 = -0.123 out = S @ np.array([x1, x2, p1, p2]) * np.sqrt(2 * hbar) expected = np.array([x1, x2, p1 + s * x2, p2 + s * x1]) * np.sqrt( 2 * hbar) assert out == pytest.approx(expected, abs=tol)