code: def test_grover_diffusion_matrix_results():
      """Test that the matrix gives the same result as when running the example in the documentation
      `here <https://pennylane.readthedocs.io/en/stable/code/api/pennylane.templates.subroutines.GroverOperator.html>`_
      """
      n_wires = 3
      wires = list(range(n_wires))
  
      def oracle():
          qml.Hadamard(wires[-1])
          qml.Toffoli(wires=wires)
          qml.Hadamard(wires[-1])
  
      dev = qml.device("default.qubit", wires=wires)
  
      @qml.qnode(dev)
      def GroverSearch(num_iterations=1):
          for wire in wires:
              qml.Hadamard(wire)
  
          for _ in range(num_iterations):
              oracle()
              qml.GroverOperator(wires=wires)
          return qml.probs(wires)
  
      # Get probabilities from example
      probs_example = GroverSearch(num_iterations=1)
  
      # Grover diffusion matrix
      G_matrix = qml.GroverOperator(wires=wires).matrix()
  
      oracle_matrix = np.identity(2**n_wires)
      oracle_matrix[-1, -1] = -1
  
      # s1 = H|0>, Hadamard on a single qubit in the ground state
      s1 = np.array([1, 1]) / np.sqrt(2)
  
      # uniform superposition state
      s = functools.reduce(np.kron, list(itertools.repeat(s1, n_wires)))
  
      amplitudes = G_matrix @ oracle_matrix @ s
      # Check that the probabilities are the same
      probs_matrix = amplitudes**2
  
      assert np.allclose(probs_example, probs_matrix)
  
file_path: pennylane/tests/templates/test_subroutines/test_grover.py
imports: import functools
  import itertools
  import pytest
  import numpy
  import pennylane
  from pennylane.ops import Hadamard, PauliZ, MultiControlledX
label_desc: Use image node_id 9 for calling a global function with example usage: test_grover_diffusion_matrix_results() and returns: qml