class_docstr: Gate tests.
class_docstr_tok: ["Gate","tests","."]
docstr: Test the beamsplitter symplectic transform.
docstr_tok: ["Test","the","beamsplitter","symplectic","transform","."]
code: def test_beamsplitter(self, tol):
      """Test the beamsplitter symplectic transform."""
  
      theta = 0.543
      phi = 0.312
      S = beamsplitter(theta, phi)
  
      # apply to a coherent state. BS|a1, a2> -> |ta1-r^*a2, ra1+ta2>
      a1 = 0.23 + 0.12j
      a2 = 0.23 + 0.12j
      out = (
          S
          @ np.array([a1.real, a2.real, a1.imag, a2.imag])
          * np.sqrt(2 * hbar)
      )
  
      T = np.cos(theta)
      R = np.exp(1j * phi) * np.sin(theta)
      a1out = T * a1 - R.conj() * a2
      a2out = R * a2 + T * a1
      expected = np.array(
          [a1out.real, a2out.real, a1out.imag, a2out.imag]
      ) * 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 5 for calling the TestGates obj's underlying member method code with example usage: obj.test_beamsplitter(tol) without return types