class_docstr: Integration tests for default.gaussian. This test ensures it integrates
  properly with the PennyLane interface, in particular QNode.
class_docstr_tok: ["Integration","tests","for","default.gaussian",".","This","test","ensures","it","integrates","properly","with","the","PennyLane","interface",",","in","particular","QNode","."]
docstr: Test that variance of X^2 is correct for the vacuum
  
  The expected analytic expression of hbar^2/ 2 follows as:
  
  Var[X^2] = E[X^4] - E[X^2]
  
  We assume that we've prepared the vaccuum state.
  
  X = sqrt(hbar/2) * (a + a_{dagger}), where a and a_{dagger} are the
  ladder operators.
  
  Var[X^2] = <0|(sqrt(hbar/2) * (a + a_{dagger}))^ 4|0> -
  (<0|(sqrt(hbar/2) * (a + a_{dagger})) ^ 2|0>) ^ 2
  
  Let's label the two terms with (1) and (2).
  
  In (1), only (a*a*a_{dagger}*a_{dagger} + a*a_{dagger}*a*a_{dagger}),
  in (2), only (a*a_{dagger}) contributes (normalization excluded). The
  rest of the terms are zero.
  
  The a*a_{dagger}=Id+a_{dagger}*a equation is also used to yield
  Var[X^2] = hbar^2/2.
docstr_tok: ["Test","that","variance","of","X^2","is","correct","for","the","vacuum","The","expected","analytic","expression","of","hbar^2\/","2","follows","as",":","Var","[","X^2","]","=","E","[","X^4","]","-","E","[","X^2","]","We","assume","that","we","'ve","prepared","the","vaccuum","state",".","X","=","sqrt","(","hbar\/2",")","*","(","a","+","a_","{","dagger","}",")",",","where","a","and","a_","{","dagger","}","are","the","ladder","operators",".","Var","[","X^2","]","=","<","0|","(","sqrt","(","hbar\/2",")","*","(","a","+","a_","{","dagger","}",")",")","^","4|0",">","-","(","<","0|","(","sqrt","(","hbar\/2",")","*","(","a","+","a_","{","dagger","}",")",")","^","2|0",">",")","^","2","Let","'s","label","the","two","terms","with","(","1",")","and","(","2",")",".","In","(","1",")",",","only","(","a","*","a","*","a_","{","dagger","}","*","a_","{","dagger","}","+","a","*","a_","{","dagger","}","*","a","*","a_","{","dagger","}",")",",","in","(","2",")",",","only","(","a","*","a_","{","dagger","}",")","contributes","(","normalization","excluded",")",".","The","rest","of","the","terms","are","zero",".","The","a","*","a_","{","dagger","}","=Id+a_","{","dagger","}","*","a","equation","is","also","used","to","yield","Var","[","X^2","]","=","hbar^2\/2","."]
code: def test_vacuum_x_squared_variance(self):
      """Test that variance of X^2 is correct for the vacuum
  
      The expected analytic expression of hbar^2/ 2 follows as:
  
      Var[X^2] = E[X^4] - E[X^2]
  
      We assume that we've prepared the vaccuum state.
  
      X = sqrt(hbar/2) * (a + a_{dagger}), where a and a_{dagger} are the
      ladder operators.
  
      Var[X^2] = <0|(sqrt(hbar/2) * (a + a_{dagger}))^ 4|0> -
      (<0|(sqrt(hbar/2) * (a + a_{dagger})) ^ 2|0>) ^ 2
  
      Let's label the two terms with (1) and (2).
  
      In (1), only (a*a*a_{dagger}*a_{dagger} + a*a_{dagger}*a*a_{dagger}),
      in (2), only (a*a_{dagger}) contributes (normalization excluded). The
      rest of the terms are zero.
  
      The a*a_{dagger}=Id+a_{dagger}*a equation is also used to yield
      Var[X^2] = hbar^2/2.
      """
      dev = qml.device("default.gaussian", wires=1)
  
      @qml.qnode(dev)
      def circuit():
          return qml.var(qml.PolyXP(np.diag([0, 1, 0]), wires=0))
  
      assert circuit() == pytest.approx(dev.hbar**2 / 2)
  
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 6 for calling the TestDefaultGaussianIntegration obj's underlying member method code with example usage: obj.test_vacuum_x_squared_variance() and returns: qml