class_docstr: Tests for the expval function
class_docstr_tok: ["Tests","for","the","expval","function"]
docstr: Test that expectation values for mid-circuit measurement values
  are correct for a composite measurement value.
docstr_tok: ["Test","that","expectation","values","for","mid-circuit","measurement","values","are","correct","for","a","composite","measurement","value","."]
code: def test_observable_is_composite_measurement_value(
      self, shots, phi, mocker, tol, tol_stochastic, device_name
  ):  # pylint: disable=too-many-arguments
      """Test that expectation values for mid-circuit measurement values
      are correct for a composite measurement value."""
      np.random.seed(42)
      dev = qml.device(device_name, wires=6, shots=shots)
  
      @qml.qnode(dev)
      def circuit(phi):
          qml.RX(phi, 0)
          m0 = qml.measure(0)
          qml.RX(0.5 * phi, 1)
          m1 = qml.measure(1)
          qml.RX(2 * phi, 2)
          m2 = qml.measure(2)
          return qml.expval(m0 * m1 + m2)
  
      new_dev = circuit.device
      spy = mocker.spy(qml.QubitDevice, "expval")
  
      res = circuit(phi, shots=shots)
  
      @qml.qnode(dev)
      def expected_circuit(phi):
          qml.RX(phi, 0)
          qml.RX(0.5 * phi, 1)
          qml.RX(2 * phi, 2)
          return (
              qml.expval(qml.Projector([1], 0)),
              qml.expval(qml.Projector([1], 1)),
              qml.expval(qml.Projector([1], 2)),
          )
  
      evals = expected_circuit(phi, shots=None)
      expected = evals[0] * evals[1] + evals[2]
  
      atol = tol if shots is None else tol_stochastic
      assert np.allclose(np.array(res), expected, atol=atol, rtol=0)
  
      if device_name != "default.mixed":
          custom_measurement_process(new_dev, spy)
  
file_path: pennylane/tests/measurements/legacy/test_expval_legacy.py
imports: import numpy
  import pytest
  import pennylane
  from pennylane.measurements import Expectation, Shots
  from pennylane.devices.qubit.measure import flatten_state
label_desc: Use image node_id 5 for calling the TestExpval obj's underlying member method code with example usage: obj.test_observable_is_composite_measurement_value(shots, phi, mocker, tol, tol_stochastic, device_name) and returns: qml, qml,  qml,  qml