class_docstr: Test the utility function _nonzero_coeffs_and_words.
class_docstr_tok: ["Test","the","utility","function","_nonzero_coeffs_and_words","."]
docstr: Test that a removing single entries/Pauli words leads to the corresponding
  rows in the coefficients being skipped.
docstr_tok: ["Test","that","a","removing","single","entries\/Pauli","words","leads","to","the","corresponding","rows","in","the","coefficients","being","skipped","."]
code: def test_single_zeros(self, num_wires, remove_ids):
      """Test that a removing single entries/Pauli words leads to the corresponding
      rows in the coefficients being skipped."""
      dim = 4**num_wires - 1
      # Set a few coefficients to zero
      coeffs = tuple(
          np.zeros(dim) if i in remove_ids else e
          for i, e in enumerate(np.eye(dim))
      )
      new_coeffs, words = _nonzero_coeffs_and_words(coeffs, num_wires)
  
      mask = np.ones(dim, bool)
      mask[remove_ids] = 0
      # Filter the coefficients and Pauli words for non-zero components
      exp_coeffs = tuple(c[mask] for c in coeffs)
      exp_words = [
          w for i, w in zip(mask, pauli_basis_strings(num_wires)) if i
      ]
      assert all(
          qml.math.allclose(nc, c)
          for nc, c in zip(new_coeffs, exp_coeffs)
      )
      assert len(words) == 4**num_wires - 1 - len(remove_ids)
      assert all(w == exp for w, exp in zip(words, exp_words))
  
      # Remove entries in np.eye(...) coefficients tuple altogether, effectively doing
      # the same as setting rows of coefficients to zero.
      coeffs = tuple(
          e for i, e in enumerate(np.eye(dim)) if i not in remove_ids
      )
      new_coeffs, words = _nonzero_coeffs_and_words(coeffs, num_wires)
      exp_coeffs = tuple(c[mask] for c in coeffs)
      assert all(
          qml.math.allclose(nc, c)
          for nc, c in zip(new_coeffs, exp_coeffs)
      )
      assert len(words) == 4**num_wires - 1 - len(remove_ids)
      assert all(w == exp for w, exp in zip(words, exp_words))
  
imports: import copy
  import pytest
  import numpy
  import pennylane
  from pennylane import numpy
  from pennylane.ops.qubit.special_unitary import pauli_basis_matrices, pauli_basis_strings
  from pennylane.math import expand_matrix
  from pennylane.gradients.pulse_gradient_odegen import _generate_tapes_and_coeffs, pulse_odegen, _insert_op, _nonzero_coeffs_and_words, _one_parameter_generators, _one_parameter_paulirot_coeffs, _parshift_and_contract
label_desc: Use image node_id 3 for calling the TestNonzeroCoeffsAndWords obj's underlying member method code with example usage: obj.test_single_zeros(num_wires, remove_ids) without return types