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(
      self, tol, qutrit_device_3_wires, basis_state, wires, target_state
  ):
      """Tests that the template produces the correct expectation values."""
  
      @qml.qnode(qutrit_device_3_wires)
      def circuit(obs):
          qml.QutritBasisStatePreparation(basis_state, wires)
  
          return [
              qml.expval(qml.THermitian(A=obs, wires=i))
              for i in range(3)
          ]
  
      # Convert to basis states
      obs = np.array([[1, 0, 0], [0, 2, 0], [0, 0, 3]])
      output_state = [x - 1 for x in circuit(obs)]
  
      assert np.allclose(output_state, target_state, atol=tol, rtol=0)
  
file_path: pennylane/tests/templates/test_state_preparations/test_qutrit_basis_state_prep.py
imports: import pytest
  import numpy
  import pennylane
label_desc: Use image node_id 2 for calling the TestDecomposition obj's underlying member method code with example usage: obj.test_state_preparation(tol, qutrit_device_3_wires, basis_state, wires, target_state) and returns: unknown