class_docstr: Tests circuits with sample-based measurements
docstr: Test that samples are reused when two measurements commute
docstr_tok: ["Test","that","samples","are","reused","when","two","measurements","commute"]
code: def test_shots_reuse(self, mocker):
      """Test that samples are reused when two measurements commute"""
      ops = [qml.Hadamard(0), qml.CNOT([0, 1])]
      mps = [
          qml.expval(qml.PauliX(0)),
          qml.expval(qml.PauliX(1)),
          qml.expval(qml.PauliZ(0)),
          qml.var(qml.PauliX(1)),
          qml.var(qml.PauliY(0)),
          qml.probs(wires=[0]),
          qml.probs(wires=[0, 1]),
          qml.sample(wires=[0, 1]),
          qml.expval(
              qml.Hamiltonian(
                  [1.0, 2.0, 3.0],
                  [qml.PauliX(0), qml.PauliZ(1), qml.PauliY(1)],
              )
          ),
          qml.expval(
              qml.sum(qml.PauliX(0), qml.PauliZ(1), qml.PauliY(1))
          ),
          qml.expval(qml.s_prod(2.0, qml.PauliX(0))),
          qml.expval(qml.prod(qml.PauliX(0), qml.PauliY(1))),
      ]
  
      qs = qml.tape.QuantumScript(ops, mps, shots=100)
  
      spy = mocker.spy(qml.devices.qubit.sampling, "sample_state")
      result = simulate(qs)
  
      assert isinstance(result, tuple)
      assert len(result) == len(mps)
  
      # check that samples are reused when possible
      # 3 groups for expval and var, 1 group for probs and sample, 2 groups each for
      # Hamiltonian and Sum, and 1 group each for SProd and Prod
      assert spy.call_count == 10
  
imports: import pytest
  import numpy
  import pennylane
  from pennylane.devices.qubit import simulate, get_final_state, measure_final_state
label_desc: Use image node_id 5 for calling the TestSampleMeasurements obj's underlying member method code with example usage: obj.test_shots_reuse(mocker) without return types