code: def test_taper_excitations(
      symbols,
      geometry,
      charge,
      generators,
      paulixops,
      paulix_sector,
      num_commuting,
  ):
      r"""Test that the tapered excitation operators using :func:`~.taper_operation`
      are consistent with the tapered Hartree-Fock state."""
  
      mol = qml.qchem.Molecule(symbols, geometry, charge)
      num_electrons, num_wires = mol.n_electrons, 2 * mol.n_orbitals
      hf_state = np.where(np.arange(num_wires) < num_electrons, 1, 0)
      hf_tapered = taper_hf(
          generators, paulixops, paulix_sector, num_electrons, num_wires
      )
  
      observables = [
          qml.qchem.diff_hamiltonian(mol)(geometry),
          qml.qchem.particle_number(num_wires),
          qml.qchem.spin2(num_electrons, num_wires),
          qml.qchem.spinz(num_wires),
      ]
      tapered_obs = [
          qml.taper(observale, generators, paulixops, paulix_sector)
          for observale in observables
      ]
  
      o = np.array([1, 0])
      l = np.array([0, 1])
      state = functools.reduce(
          np.kron, [l if s else o for s in hf_state]
      )
      state_tapered = functools.reduce(
          np.kron, [l if s else o for s in hf_tapered]
      )
  
      singles, doubles = qml.qchem.excitations(num_electrons, num_wires)
      exc_fnc = [qml.SingleExcitation, qml.DoubleExcitation]
      exc_obs, exc_tap = [[], []], [[], []]
      for idx, exc in enumerate([singles, doubles]):
          exc_obs[idx] = [
              exc_fnc[idx](np.pi, wires=wire) for wire in exc
          ]
          exc_tap[idx] = [
              taper_operation(
                  op,
                  generators,
                  paulixops,
                  paulix_sector,
                  range(num_wires),
              )
              for op in exc_obs[idx]
          ]
          exc_obs[idx] = [
              x for i, x in enumerate(exc_obs[idx]) if exc_tap[idx][i]
          ]
          exc_tap[idx] = [x for x in exc_tap[idx] if x]
          assert len(exc_tap[idx]) == num_commuting[idx]
  
      obs_all, obs_tap = (
          exc_obs[0] + exc_obs[1],
          exc_tap[0] + exc_tap[1],
      )
      for op_all, op_tap in zip(obs_all, obs_tap):
          if op_tap:
              excited_state = np.matmul(
                  qml.matrix(op_all, wire_order=range(len(hf_state))),
                  state,
              )
              ob_tap_mat = functools.reduce(
                  np.matmul,
                  [
                      qml.matrix(op, wire_order=range(len(hf_tapered)))
                      for op in op_tap
                  ],
              )
              excited_state_tapered = np.matmul(
                  ob_tap_mat, state_tapered
              )
              # check if tapered excitation gates remains spin and particle-number conserving,
              # and also evolves the tapered-state to have consistent energy values
              for obs, tap_obs in zip(observables, tapered_obs):
                  expec_val = (
                      scipy.sparse.coo_matrix(excited_state)
                      @ obs.sparse_matrix()
                      @ scipy.sparse.coo_matrix(excited_state).getH()
                  ).toarray()
                  expec_val_tapered = (
                      scipy.sparse.coo_matrix(excited_state_tapered)
                      @ tap_obs.sparse_matrix()
                      @ scipy.sparse.coo_matrix(
                          excited_state_tapered
                      ).getH()
                  ).toarray()
                  assert np.isclose(expec_val, expec_val_tapered)
  
imports: import functools
  import pytest
  import scipy
  import pennylane
  from pennylane import numpy
  from pennylane.pauli import pauli_sentence
  from pennylane.qchem.tapering import _kernel, _reduced_row_echelon, clifford, optimal_sector, taper_hf, taper_operation, _split_pauli_sentence, _taper_pauli_sentence
  from pennylane.operation import enable_new_opmath, disable_new_opmath
label_desc: Use image node_id 11 for calling a global function with example usage: test_taper_excitations(symbols, geometry, charge, generators, paulixops, paulix_sector, num_commuting) without return types