class_docstr: Unit tests for validate_and_expand_adjoint
class_docstr_tok: ["Unit","tests","for","validate_and_expand_adjoint"]
docstr: Test that the trainable parameters of a tape are updated when it is expanded
docstr_tok: ["Test","that","the","trainable","parameters","of","a","tape","are","updated","when","it","is","expanded"]
code: def test_trainable_params_decomposed(self):
      """Test that the trainable parameters of a tape are updated when it is expanded"""
  
      ops = [
          qml.QubitUnitary([[0, 1], [1, 0]], wires=0),
          qml.CNOT([0, 1]),
          qml.Rot(0.1, 0.2, 0.3, wires=0),
      ]
      qs = qml.tape.QuantumScript(ops, [qml.expval(qml.PauliZ(0))])
  
      qs.trainable_params = [0]
      program = qml.device("default.qubit").preprocess(
          ExecutionConfig(gradient_method="adjoint")
      )[0]
      res, _ = program((qs,))
      res = res[0]
  
      assert isinstance(res, qml.tape.QuantumScript)
      assert len(res.operations) == 7
      assert qml.equal(res[0], qml.RZ(np.pi / 2, 0))
      assert qml.equal(res[1], qml.RY(np.pi, 0))
      assert qml.equal(res[2], qml.RZ(7 * np.pi / 2, 0))
      assert qml.equal(res[3], qml.CNOT([0, 1]))
      assert qml.equal(res[4], qml.RZ(0.1, 0))
      assert qml.equal(res[5], qml.RY(0.2, 0))
      assert qml.equal(res[6], qml.RZ(0.3, 0))
      assert res.trainable_params == [0, 1, 2, 3, 4, 5]
  
      qs.trainable_params = [2, 3]
      res, _ = program((qs,))
      res = res[0]
      assert isinstance(res, qml.tape.QuantumScript)
      assert len(res.operations) == 7
      assert qml.equal(res[0], qml.RZ(np.pi / 2, 0))
      assert qml.equal(res[1], qml.RY(np.pi, 0))
      assert qml.equal(res[2], qml.RZ(7 * np.pi / 2, 0))
      assert qml.equal(res[3], qml.CNOT([0, 1]))
      assert qml.equal(res[4], qml.RZ(0.1, 0))
      assert qml.equal(res[5], qml.RY(0.2, 0))
      assert qml.equal(res[6], qml.RZ(0.3, 0))
      assert res.trainable_params == [0, 1, 2, 3, 4, 5]
  
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 4 for calling the TestAdjointDiffTapeValidation obj's underlying member method code with example usage: obj.test_trainable_params_decomposed() without return types