class_docstr: Unit tests for validate_and_expand_adjoint
class_docstr_tok: ["Unit","tests","for","validate_and_expand_adjoint"]
docstr: Test that a tape that is valid with operations that need to be expanded doesn't raise errors
  and is expanded
docstr_tok: ["Test","that","a","tape","that","is","valid","with","operations","that","need","to","be","expanded","does","n't","raise","errors","and","is","expanded"]
code: def test_valid_tape_with_expansion(self):
      """Test that a tape that is valid with operations that need to be expanded doesn't raise errors
      and is expanded"""
      prep_op = qml.StatePrep(
          qml.numpy.array([1.0, -1.0], requires_grad=False)
          / np.sqrt(2),
          wires=0,
      )
      qs = qml.tape.QuantumScript(
          ops=[prep_op, qml.Rot(0.1, 0.2, 0.3, wires=[0])],
          measurements=[qml.expval(qml.PauliZ(0))],
      )
  
      program = qml.device("default.qubit").preprocess(
          ExecutionConfig(gradient_method="adjoint")
      )[0]
  
      qs.trainable_params = {1, 2, 3}
      qs_valid, _ = program((qs,))
      qs_valid = qs_valid[0]
  
      expected_ops = [
          prep_op,
          qml.RZ(0.1, wires=[0]),
          qml.RY(0.2, wires=[0]),
          qml.RZ(0.3, wires=[0]),
      ]
  
      assert all(
          qml.equal(o1, o2)
          for o1, o2 in zip(qs_valid.operations, expected_ops)
      )
      assert all(
          qml.equal(o1, o2)
          for o1, o2 in zip(qs.measurements, qs_valid.measurements)
      )
      assert qs_valid.trainable_params == [0, 1, 2, 3]
      assert qs.shots == qs_valid.shots
  
imports: import pytest
  import numpy
  import pennylane
  from pennylane.devices import DefaultQubit, ExecutionConfig
  from pennylane.devices.default_qubit import stopping_condition
label_desc: Use image node_id 9 for calling the TestAdjointDiffTapeValidation obj's underlying member method code with example usage: obj.test_valid_tape_with_expansion() without return types