class_docstr: Test that simulate works with broadcasted parameters
docstr: Test that simulate works for sample measurements
  when the state prep has broadcasted parameters
docstr_tok: ["Test","that","simulate","works","for","sample","measurements","when","the","state","prep","has","broadcasted","parameters"]
code: def test_broadcasted_prep_sample(self):
      """Test that simulate works for sample measurements
      when the state prep has broadcasted parameters"""
      x = np.array(1.2)
  
      ops = [qml.RY(x, wires=0), qml.CNOT(wires=[0, 1])]
      measurements = [qml.expval(qml.PauliZ(i)) for i in range(2)]
      prep = [qml.StatePrep(np.eye(4), wires=[0, 1])]
  
      qs = qml.tape.QuantumScript(
          prep + ops, measurements, shots=qml.measurements.Shots(10000)
      )
      res = simulate(qs, rng=123)
  
      assert isinstance(res, tuple)
      assert len(res) == 2
      assert np.allclose(
          res[0],
          np.array([np.cos(x), np.cos(x), -np.cos(x), -np.cos(x)]),
          atol=0.05,
      )
      assert np.allclose(
          res[1],
          np.array([np.cos(x), -np.cos(x), -np.cos(x), np.cos(x)]),
          atol=0.05,
      )
  
      state, is_state_batched = get_final_state(qs)
      res = measure_final_state(qs, state, is_state_batched, rng=123)
      expected_state = np.array(
          [
              [np.cos(x / 2), 0, 0, np.sin(x / 2)],
              [0, np.cos(x / 2), np.sin(x / 2), 0],
              [-np.sin(x / 2), 0, 0, np.cos(x / 2)],
              [0, -np.sin(x / 2), np.cos(x / 2), 0],
          ]
      ).reshape((4, 2, 2))
  
      assert np.allclose(state, expected_state)
      assert is_state_batched
      assert isinstance(res, tuple)
      assert len(res) == 2
      assert np.allclose(
          res[0],
          np.array([np.cos(x), np.cos(x), -np.cos(x), -np.cos(x)]),
          atol=0.05,
      )
      assert np.allclose(
          res[1],
          np.array([np.cos(x), -np.cos(x), -np.cos(x), np.cos(x)]),
          atol=0.05,
      )
  
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 3 for calling the TestBroadcasting obj's underlying member method code with example usage: obj.test_broadcasted_prep_sample() without return types