class_docstr: Test that a device different to default.qubit gives the same result
docstr: Compare the result of a random circuit to default.qubit
docstr_tok: ["Compare","the","result","of","a","random","circuit","to","default.qubit"]
code: def test_random_circuit(self, device, tol, ret):
      """Compare the result of a random circuit to default.qubit"""
      n_wires = 2
      dev = device(n_wires)
      dev_def = qml.device("default.qubit", wires=n_wires)
  
      if dev.name == dev_def.name:
          pytest.skip("Device is default.qubit.")
  
      supports_tensor = (
          "supports_tensor_observables" in dev.capabilities()
          and dev.capabilities()["supports_tensor_observables"]
      )
  
      if not supports_tensor:
          pytest.skip("Device does not support tensor observables.")
  
      if dev.shots is not None:
          pytest.skip("Device is in non-analytical mode.")
  
      n_layers = np.random.randint(1, 5)
      weights = 2 * np.pi * np.random.rand(n_layers, 1)
  
      ret_type = getattr(qml, ret)
  
      def circuit(weights):
          RandomLayers(weights, wires=range(n_wires))
          return ret_type(qml.PauliZ(wires=0) @ qml.PauliX(wires=1))
  
      qnode_def = qml.QNode(circuit, dev_def)
      qnode = qml.QNode(circuit, dev)
  
      grad_def = qml.grad(qnode_def, argnum=0)
      grad = qml.grad(qnode, argnum=0)
  
      assert np.allclose(
          qnode(weights), qnode_def(weights), atol=tol(dev.shots)
      )
      assert np.allclose(
          grad(weights), grad_def(weights), atol=tol(dev.shots)
      )
  
file_path: pennylane/pennylane/devices/tests/test_compare_default_qubit.py
imports: import pytest
  from flaky import flaky
  import pennylane
  from pennylane import numpy
  from pennylane.templates.layers import RandomLayers
label_desc: Use image node_id 4 for calling the TestComparison obj's underlying member method code with example usage: obj.test_random_circuit(device, tol, ret) and returns: ret_type