code: def test_spinz(orbitals, coeffs_ref, ops_ref):
      r"""Tests the correctness of the :math:`\hat{S}_z` observable built by the
      function `'spin_z'`.
      """
      sz = qchem.spin.spinz(orbitals)
      sz_ref = qml.Hamiltonian(coeffs_ref, ops_ref)
      assert sz.compare(sz_ref)
  
      enable_new_opmath()
      sz_pl_op = qchem.spin.spinz(orbitals)
      disable_new_opmath()
      sz_ref_pl_op = qml.dot(coeffs_ref, ops_ref)
  
      wire_order = sz_ref.wires
      assert not isinstance(sz_pl_op, qml.Hamiltonian)
      assert np.allclose(
          qml.matrix(sz_pl_op, wire_order=wire_order),
          qml.matrix(sz_ref_pl_op, wire_order=wire_order),
      )
  
file_path: pennylane/tests/qchem/test_spin.py
imports: import pytest
  import pennylane
  from pennylane import Identity, PauliX, PauliY, PauliZ
  from pennylane import numpy
  from pennylane import qchem
  from pennylane.operation import enable_new_opmath, disable_new_opmath
label_desc: Use image node_id 4 for calling a global function with example usage: test_spinz(orbitals, coeffs_ref, ops_ref) without return types