class_docstr: Tests that the template defines the correct decomposition.
class_docstr_tok: ["Tests","that","the","template","defines","the","correct","decomposition","."]
docstr: Tests that the template produces the correct expectation values.
docstr_tok: ["Tests","that","the","template","produces","the","correct","expectation","values","."]
code: def test_state_preparation_tf_autograph(
      self, tol, basis_state, wires, target_state
  ):
      """Tests that the template produces the correct expectation values."""
      import tensorflow as tf
  
      @tf.function
      @qml.qnode(qml.device("default.qubit"), interface="tf")
      def circuit(state):
          qml.BasisStatePreparation(state, wires)
  
          # Pauli Z gates identify the basis state
          return (
              qml.expval(qml.PauliZ(0)),
              qml.expval(qml.PauliZ(1)),
              qml.expval(qml.PauliZ(2)),
          )
  
      # Convert from Pauli Z eigenvalues to basis state
      output_state = [
          0 if x == 1.0 else 1 for x in circuit(basis_state)
      ]
  
      assert np.allclose(output_state, target_state, atol=tol, rtol=0)
  
file_path: pennylane/tests/templates/test_state_preparations/test_basis_state_prep.py
imports: import pytest
  import numpy
  import pennylane
label_desc: Use image node_id 4 for calling the TestDecomposition obj's underlying member method code with example usage: obj.test_state_preparation_tf_autograph(tol, basis_state, wires, target_state) and returns: qml,  qml,  qml