class_docstr: Tests for the broadcast_expand transform
class_docstr_tok: ["Tests","for","the","broadcast_expand","transform"]
docstr: Test that expansion works for state preparations
docstr_tok: ["Test","that","expansion","works","for","state","preparations"]
code: def test_state_prep(self):
      """Test that expansion works for state preparations"""
      ops = [qml.CNOT([0, 1])]
      meas = [qml.expval(qml.PauliZ(1))]
      prep = [qml.StatePrep(np.eye(4), wires=[0, 1])]
      tape = qml.tape.QuantumScript(prep + ops, meas)
  
      tapes, fn = qml.transforms.broadcast_expand(tape)
      assert len(tapes) == 4
      assert all(t.batch_size is None for t in tapes)
  
      result = fn(qml.execute(tapes, dev, None))
      expected = np.array([1, -1, -1, 1])
  
      assert qml.math.allclose(result, expected)
  
file_path: pennylane/tests/transforms/test_broadcast_expand.py
imports: import pytest
  import numpy
  import pennylane
  from pennylane import numpy
label_desc: Use image node_id 3 for calling the TestBroadcastExpand obj's underlying member method code with example usage: obj.test_state_prep() without return types