class_docstr: Gate tests.
class_docstr_tok: ["Gate","tests","."]
docstr: Test the CZ symplectic transform.
docstr_tok: ["Test","the","CZ","symplectic","transform","."]
code: 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)
  
imports: import numpy
  import numpy.random
  import pytest
  from scipy.linalg import block_diag
  from scipy.special import factorial
  import pennylane
  from pennylane import DeviceError
  from pennylane.devices.default_gaussian import fock_prob, rotation, squeezing, quadratic_phase, beamsplitter, two_mode_squeezing, controlled_addition, controlled_phase, vacuum_state, coherent_state, squeezed_state, displaced_squeezed_state, thermal_state
  from pennylane.wires import Wires
label_desc: Use image node_id 8 for calling the TestGates obj's underlying member method code with example usage: obj.test_controlled_phase(tol) without return types